It is essential to verify that your Ubuntu server has a stable internet connection to access online resources, install packages, and communicate with other systems.
In this guide, we’ll demonstrate how to check if your Ubuntu server is connected to the internet using a few simple commands.
Step 1: Ping a Well-Known Domain
The ping command sends small packets of data to a specified domain or IP address and measures the response time. It’s a simple and effective way to check if your server has an active internet connection. To check the connection using ping, run the following command:
ping -c 4 google.com
This command sends 4 ICMP packets to google.com. If your server is connected to the internet, you’ll see output similar to the following:
PING google.com (184.108.40.206) 56(84) bytes of data. 64 bytes from lt-in-f139.1e100.net (220.127.116.11): icmp_seq=1 ttl=110 time=24.1 ms 64 bytes from lt-in-f139.1e100.net (18.104.22.168): icmp_seq=2 ttl=110 time=24.0 ms 64 bytes from lt-in-f139.1e100.net (22.214.171.124): icmp_seq=3 ttl=110 time=24.0 ms 64 bytes from lt-in-f139.1e100.net (126.96.36.199): icmp_seq=4 ttl=110 time=24.1 ms --- google.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3003ms rtt min/avg/max/mdev = 24.041/24.090/24.126/0.114 ms
If you don’t receive any packets or see 100% packet loss, your server might not be connected to the internet.
Step 2: Test DNS Resolution
Another way to check your server’s internet connection is by testing its DNS resolution. The nslookup command queries the Domain Name System (DNS) to obtain the IP address associated with a domain name. To check DNS resolution, run the following command:
If your server is connected to the internet and has a working DNS configuration, you’ll see output similar to the following:
Server: 198.18.18.18 Address: 198.18.18.18#53 Non-authoritative answer: Name: google.com Address: 188.8.131.52 Name: google.com Address: 184.108.40.206 Name: google.com Address: 220.127.116.11 Name: google.com Address: 18.104.22.168 Name: google.com Address: 22.214.171.124 Name: google.com Address: 126.96.36.199 Name: google.com Address: 2a00:1450:4010:c0f::71 Name: google.com Address: 2a00:1450:4010:c0f::8a Name: google.com Address: 2a00:1450:4010:c0f::66 Name: google.com Address: 2a00:1450:4010:c0f::64
If the command fails or returns an error message, it indicates an issue with your server’s internet connection or DNS configuration.
Step 3: Check Network Interface and Gateway
To verify that your server’s network interface is up and running, use the ip command:
This command displays information about the network interfaces on your system. Check for an assigned IP address in the output.
To check the default gateway configuration, run the following command:
Ensure that the default gateway is correctly configured, as it is responsible for routing traffic between your server and the internet.
You now know how to check if your Ubuntu server is connected to the internet using the ping, nslookup, and ip commands. These methods help you diagnose connectivity issues and ensure that your server can access online resources as needed.
If you still encounter connectivity issues after following the above steps, consider checking the following:
- Firewall settings: Make sure your server’s firewall isn’t blocking outgoing or incoming traffic. You can check the current firewall configuration using the sudo ufw status command if you’re using UFW (Uncomplicated Firewall). Adjust the firewall settings if necessary.
- Network configuration files: Verify the network configuration files located in the /etc/netplan directory (for Ubuntu 18.04 and newer). Check for any errors or misconfigurations in these files, and correct them if needed. After making changes, apply the new configuration using the sudo netplan apply command.
- Proxy settings: If your server is behind a proxy, ensure that the proxy settings are correctly configured. You can check the environment variables for proxy settings with the env | grep -i proxy command. Update the proxy settings in the /etc/environment file or the appropriate configuration files if needed.
- Hardware issues: Check for any hardware-related issues, such as faulty Ethernet cables or network interface cards. Replace or fix the hardware components if necessary.
By performing these additional troubleshooting steps, you can further diagnose and resolve connectivity issues with your Ubuntu server.
Feel free to leave any questions, comments, or suggestions for improvement in the comments section below. Your feedback is invaluable to us, and it helps us create better and more informative content for our users.