Linux Commands

How to Check Internet Connectivity in Linux Terminal

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.

$ ping -c 3

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 and fetch the headers. If the headers are fetched successfully, that means the internet is working; otherwise, there is a problem.

$ curl -I

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:

$ ip a

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

$ ip r

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

$ ping -c 2

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.


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

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.