How to Check if CentOS Server is Connected to the Internet

In order to ensure that your CentOS server is functioning properly and that services and applications are able to communicate with the Internet, it’s important to confirm that your server is connected to the Internet.

In this tutorial, we will outline a few methods to check if your CentOS server is connected to the internet.

Method 1: Ping a Website

The simplest way to check if your server is connected to the internet is to ping a website. Pinging a website sends a small packet of data to the website and waits for a response. If the website responds, it means your server is connected to the internet. To ping a website, run the following command:

ping -c 6 www.google.com

If you receive a response, it means your server is connected to the internet. If you do not receive a response, it may indicate a connectivity issue.

PING www.google.com (64.233.164.103) 56(84) bytes of data.
64 bytes from lf-in-f103.1e100.net (64.233.164.103): icmp_seq=1 ttl=110 time=21.2 ms
64 bytes from lf-in-f103.1e100.net (64.233.164.103): icmp_seq=2 ttl=110 time=21.2 ms
64 bytes from lf-in-f103.1e100.net (64.233.164.103): icmp_seq=3 ttl=110 time=21.1 ms
64 bytes from lf-in-f103.1e100.net (64.233.164.103): icmp_seq=4 ttl=110 time=21.1 ms
64 bytes from lf-in-f103.1e100.net (64.233.164.103): icmp_seq=5 ttl=110 time=21.1 ms
64 bytes from lf-in-f103.1e100.net (64.233.164.103): icmp_seq=6 ttl=110 time=21.2 ms

--- www.google.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5007ms
rtt min/avg/max/mdev = 21.185/21.203/21.229/0.169 ms

Method 2: Use wget or curl

Another way to check if your server is connected to the internet is to use the wget or curl command to download a webpage. If the webpage downloads successfully, it means your server is connected to the internet. To use wget, run the following command:

wget www.google.com
--2023-04-24 15:56:07--  http://www.google.com/
Resolving www.google.com (www.google.com)... 64.233.164.103, 64.233.164.147, 64.233.164.105, ...
Connecting to www.google.com (www.google.com)|64.233.164.103|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’

index.html              [ <=>                ]  16.64K  --.-KB/s    in 0.02s   

2023-04-24 15:56:07 (714 KB/s) - ‘index.html’ saved [17035]

To use curl, run the following command:

curl www.google.com

If the webpage downloads successfully, it means your server is connected to the internet.

Method 3: Use the ping Command with an IP Address

If you do not have access to a website URL, you can also use the ping command with an IP address to check if your server is connected to the internet. To ping a website IP address, run the following command:

ping -c 4 8.8.8.8

If you receive a response, it means your server is connected to the internet.

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=110 time=23.6 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=110 time=23.6 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=110 time=23.5 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=110 time=23.5 ms

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 23.586/23.600/23.619/0.188 ms

Conclusion:

In this guide, we have outlined a few methods to check if your CentOS server is connected to the internet. By following these steps, you can ensure that your server is functioning properly and able to communicate with the internet. If you encounter any issues during the connectivity test, feel free to comment or suggest improvements.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *