Atlantic.Net Blog

How to Install and Use the Ping Command in Linux

Hitesh Jethva
by Atlantic.Net (468 posts) under Tutorials, VPS Hosting
0 Comments

Ping stands for Packet Internet Groper and is a Linux command-line tool used to check connectivity between two computer systems. It allows us to check the time duration for sending and receiving responses from a network. Ping uses Internet Control Message Protocol (ICMP) protocol to send messages to the remote computer system. In simple terms, the Ping command allows the user to check the quality of the network connection between two devices.

In this post, we will show you how to install and use the Ping command on Linux.

Prerequisites

  • A server running Linux on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing any Linux operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Install Ping on Linux

By default, the Ping command is present in most Linux-based distributions. If not installed, you can install it on Debian and Ubuntu-based operating systems using the following command:

apt-get install iputils-ping -y

For RHEL, CentOS and Fedora, install the Ping command using the following command:

dnf install iputils -y

Once the Ping command is installed, you can verify the installation using the following command:

ping -V

You will get the following output:

ping utility, iputils-s20161105

Also Read

How to Install and Use Telnet on Debian 11

Basic Syntax of the Ping Command

The basic syntax of the ping command is shown below:

ping [option] [hostname] or [IP address]

To get a list of all options used with the Ping command, run the following command:

ping -help

You should see the following output:

Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
            [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
            [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
            [-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
             [-l preload] [-m mark] [-M pmtudisc_option]
             [-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
             [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
             [-W timeout] destination

Check Connectivity Using the Ping Command

You can use the Ping command followed by IP address or Hostname to check the connectivity of the remote device.

ping IP address / Hostname

For example, to check the connectivity of facebook.com, run the following command:

ping facebook.com

You should see the following output:

PING facebook.com(edge-star-mini6-shv-02-pnq1.facebook.com (2a03:2880:f16e:181:face:b00c:0:25de)) 56 data bytes
64 bytes from edge-star-mini6-shv-02-pnq1.facebook.com (2a03:2880:f16e:181:face:b00c:0:25de): icmp_seq=1 ttl=53 time=70.1 ms
64 bytes from edge-star-mini6-shv-02-pnq1.facebook.com (2a03:2880:f16e:181:face:b00c:0:25de): icmp_seq=2 ttl=53 time=66.6 ms
64 bytes from edge-star-mini6-shv-02-pnq1.facebook.com (2a03:2880:f16e:181:face:b00c:0:25de): icmp_seq=3 ttl=53 time=449 ms
64 bytes from edge-star-mini6-shv-02-pnq1.facebook.com (2a03:2880:f16e:181:face:b00c:0:25de): icmp_seq=4 ttl=53 time=368 ms
--- facebook.com ping statistics ---
5 packets transmitted, 4 received, 20% packet loss, time 4002ms
rtt min/avg/max/mdev = 106.813/250.740/424.457/116.691 ms

You can press the CTRL + C button to stop sending packets to the target host.

  • from – Specify the destination host and its IP address.
  • icmp_seq=1 – Specify the sequence number of each ICMP packet.
  • ttl=53 – The time to live value from 1 to 255.
  • min – Minimum time to receive a response.
  • avg – Average time to get responses.
  • max – Maximum time to get a response.

Also Read

How to Find Files with fd Command in Linux

Specify the Number of Ping Packets

You can use the -c option with the Ping command to stop the Ping command automatically after sending a certain number of packets.

ping -c 5 google.com

This will stop the Ping command after sending the 5 packets.

PING google.com(bom07s30-in-x0e.1e100.net (2404:6800:4009:820::200e)) 56 data bytes
64 bytes from bom07s30-in-x0e.1e100.net (2404:6800:4009:820::200e): icmp_seq=1 ttl=55 time=82.0 ms
64 bytes from bom07s30-in-x0e.1e100.net (2404:6800:4009:820::200e): icmp_seq=2 ttl=55 time=224 ms
64 bytes from bom07s30-in-x0e.1e100.net (2404:6800:4009:820::200e): icmp_seq=3 ttl=55 time=451 ms
64 bytes from bom07s30-in-x0e.1e100.net (2404:6800:4009:820::200e): icmp_seq=4 ttl=55 time=372 ms
64 bytes from bom07s30-in-x0e.1e100.net (2404:6800:4009:820::200e): icmp_seq=5 ttl=55 time=292 ms

--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 82.018/284.782/451.970/126.884 ms

Set Time Intervals Between Ping Packets

By default, the time interval between each packet is set to one second. You can use the -i option to change the default time interval.

ping -i 2 google.com

Change the Ping Packet Size

By default, the ping packet size is set to 56 (84) bytes. You can change it using the -s option.

For example, to set the Ping packet size to 500 bytes, run the following command:

ping -s 500 google.com

You should see the packet size in the following output:

PING google.com(bom12s20-in-x0e.1e100.net (2404:6800:4009:830::200e)) 500 data bytes
76 bytes from bom12s20-in-x0e.1e100.net (2404:6800:4009:830::200e): icmp_seq=1 ttl=55 (truncated)
76 bytes from bom12s20-in-x0e.1e100.net (2404:6800:4009:830::200e): icmp_seq=2 ttl=55 (truncated)
76 bytes from bom12s20-in-x0e.1e100.net (2404:6800:4009:830::200e): icmp_seq=3 ttl=55 (truncated)

Set the Time Limit for the Ping Command

You can use the -w option to stop receiving a ping output after a specific amount of time.

For example, to stop the Ping command output after 20 seconds, run the following command:

ping -w 20 google.com

Add Timestamp Before Each Line in Ping Output

You can use the -D option with the Ping command to print a timestamp before each line in Ping output:

ping -D google.com

You should see the following output:

PING google.com(bom12s20-in-x0e.1e100.net (2404:6800:4009:830::200e)) 56 data bytes
[1646212673.335469] 64 bytes from bom12s20-in-x0e.1e100.net (2404:6800:4009:830::200e): icmp_seq=1 ttl=55 time=305 ms
[1646212674.256155] 64 bytes from bom12s20-in-x0e.1e100.net (2404:6800:4009:830::200e): icmp_seq=2 ttl=55 time=225 ms
[1646212675.485228] 64 bytes from bom12s20-in-x0e.1e100.net (2404:6800:4009:830::200e): icmp_seq=3 ttl=55 time=453 ms

Flood a Network with Ping Command

You can use the Ping command with the -f option to send 100 or more packets per second to the remote host. It is very useful if you want to test your website performance.

ping -f google.com

Print only Summary Statistics in Ping Command

You can use the Ping command with the -q option to suppress the output to print only summary statistics.

ping -q google.com

You should see the following output:

PING google.com(bom07s30-in-x0e.1e100.net (2404:6800:4009:820::200e)) 56 data bytes
^C
--- google.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5007ms
rtt min/avg/max/mdev = 84.909/175.073/317.982/77.991 ms

Conclusion

In this post, we explained how to install and use the Ping command in Linux. You can now use the Ping command to troubleshoot the network problems such as high latency or dropped packages and test your internet connection. Get started now on VPS hosting from Atlantic.Net!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Best Cloud Consultancy or MSP in 2022
BAA Red Flags: What Should Your HIPAA-Compliant Hosting Company Be Willing to Accommodate?
HIPAA Compliance for Remote Workers: How to Maintain HIPAA Compliance with a Remote Team
How to Make the Best Use of the Cloud in the Internet of Things (IoT)
How to Make the Best Use of Artificial Intelligence in Cloud Computing

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2008 Lookout Dr,

Garland, Texas 75044

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources