Table of Contents
- Install Ping on Linux
- Basic Syntax of the Ping Command
- Check Connectivity Using the Ping Command
- Specify the Number of Ping Packets
- Set Time Intervals Between Ping Packets
- Change the Ping Packet Size
- Set the Time Limit for the Ping Command
- Add a Timestamp Before Each Line in the Ping Output
- Flood a Network with Ping Command
- Print only Summary Statistics in Ping Command.
- Conclusion
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. The Ping command allows the user to check the network connection quality between two devices.
This post will show you how to install and use the Ping command on Linux.
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
The ping packet size is set to 56 (84) bytes by default. 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 a Timestamp Before Each Line in the Ping Output
You can use the -D option with the Ping command to print a timestamp before each line in the 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’s 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:
--- 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 network problems such as high latency or dropped packages and test your internet connection. Get started now on VPS hosting from Atlantic.Net!