While working on Linux Servers where we do not have any GUI of Linux and have access to the terminal from where we have to manage the whole server, it becomes difficult to diagnose internet connectivity problems. Therefore, this post contains several methods and provides a detailed guide on how to check the internet connectivity in Linux Terminal.
Method 1: PING Command
The best and foremost way is to check the internet availability through the PING command.
The PING command is used for sending and receiving packages from and to some external/remote server.
As an example, we will try to send three internet packages to the Google server and check the internet connectivity if we will be able to receive the internet packets from the Google server.
In the output, you can also witness that the three packages are transmitted and received. Again, this is because pinging to the Google server went successful.
Method 2: CURL Command
Another way to check the internet connection is through the CURL command.
The CURL command is used to download, upload, or transfer the data over the network from or to the server. It supports various protocols, and we can use it to check the internet connectivity by connecting to linuxhint.com and fetch the headers. If the headers are fetched successfully, that means the internet is working; otherwise, there is a problem.
If you get the status 200 OK and the website’s headers, the internet connection is working perfectly fine.
These are the methods to check internet connectivity.
Diagnose the Problem
If the internet is not connected using any of the above methods, you can use the IP command to check whether there is a problem in the gateway settings or network interface.
To get the IP address of your system assigned by the network adapter, use the command provided below:
To get the default gateway IP address, use the “ip r” command:
And try to ping to the default gateway using the PING command:
If pinging goes unsuccessful, it means there is a problem with the gateway settings, and you need to reconfigure them. Otherwise, the gateway settings are fine, but the internet is not working from the internet service provider end.
Conclusion
This post contains a profound guide on how to check the internet connectivity in Linux terminal and how to diagnose the problem. PING command is precisely used for pinging purposes, as its name is saying, while CURL command is used to transferring the data over the network. Using the “ip” command, we can diagnose the problem. Either there is a problem in the default gateway, DNS server resolution, Network adaptor, or ISP (internet service provider).