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.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/1.png60bf2fe893c0b.jpg" data-lazy- height="238" src="data:image/svg xml,” width=”729″>

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.

$ curl -I https://linuxhint.com/

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/2.png60bf2fe8a1e2e.jpg" data-lazy- height="509" src="data:image/svg xml,” width=”759″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/3.png60bf2fe8b453c.jpg" data-lazy- height="314" src="data:image/svg xml,” width=”726″>

To get the default gateway IP address, use the “ip r” command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/4.png60bf2fe8c7185.jpg" data-lazy- height="84" src="data:image/svg xml,” width=”727″>

And try to ping to the default gateway using the PING command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/5.png60bf2fe8cf228.jpg" data-lazy- height="167" src="data:image/svg xml,” width=”575″>

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).