A Detailed Breakdown of the Linux Ping Command
This is often referred to as latency. PING is the most popular method of troubleshooting any link. For an answer, it will respond or echo. Ping sends a packet containing the message "PING" to a server/host and receives a copy of the message from that host/server. Ping determines the "Round Trip Time" (or RTT) needed for a packet to hit a specific server or host.
One of the most commonly used methods for troubleshooting, monitoring, and diagnosing network access problems is the ping command. Ping sends one or more ICMP (Internet Control Message Protocol) Echo Request packets to a designated network destination IP and waits for a response. When the shipment arrives at its destination, it receives an ICMP echo reply.
You can use the ping command to verify if a remote destination IP is working or not. You should also search for packet loss and determine the round-trip delay when communication is established once. Ping is included in the iputils (or iputils-ping) kit, pre-installed on almost all Linux distributions. In this guide, we will explain brief information on what ping is and how it works.
What Is the Ping Command, and How Can I Use It?
The ping command has the following syntax:
ping [OPTIONS] DESTINATION
Let's ping google.com to help understand how the ping command works:
The output of the ping will be something like this:
PING google.com (18.104.22.168) 56(84) bytes of data.
64 bytes from muc11s01-in-f14.1e100.net (22.214.171.124): icmp_seq=1 ttl=53 time=40.2 ms
64 bytes from muc11s01-in-f14.1e100.net (126.96.36.199): icmp_seq=2 ttl=53 time=41.8 ms
64 bytes from muc11s01-in-f14.1e100.net (188.8.131.52): icmp_seq=3 ttl=53 time=47.4 ms
64 bytes from muc11s01-in-f14.1e100.net (184.108.40.206): icmp_seq=4 ttl=53 time=41.4 ms
--- google.com ping statistics ---
We'll go into the most popular ping command options in the sections below.
Select the number of packets you want to transfer.
Ping will continuously transfer the ICMP packets until an interrupt signal is received. Using the -c alternative followed by the number of packages to send before ping exits to specify the number of Echo Request packages to send before ping exits:
ping -c 1 DESTINATION
To ping xyz.com just once, for example, you will type:
ping -c 1 xyz.com
Now you need to choose a source interface.
The ping command's default action is to deliver ICMP packages over the default path. If your computer has several interfaces, you can use the -I option to define the source interface:
ping -I INTERFACE_NAME DESTINATION
Using em2 as a source interface, run the following command to ping xyz.com:
ping -I em2 xyz.com
Specify the Internet Protocol
Depending on your machine's DNS settings, the ping command can use either IPv4 or IPv6. If you're using IPv6, use the -6 option or ping6:
ping -6 DESTINATION
Pass the -4 alternative to compel ping to use IPv4, or use its alias ping4:
ping -4 DESTINATION
How to Timeout?
Use the -w alternative to interrupt pinging after a certain amount of time.
ping -w 5 www.xyz.com
After 5 seconds, the pinging will cease.
It is used to send packets as quickly as possible. This is used to evaluate the efficiency of a network.
ping -f www.xyz.com
Filling Data Packet
Using the -p alternative, we can fill the packet with data. -p ff, for example, -p ff would fill the packet with ones.
ping -c 5 -p ff www.xyz.com
Adjust the Time Frame
By default, ping waits 1 second before sending the next packet; however, the -i alternative can adjust this time.
ping -i 4 www.xyz.com
The ping delay has been increased to 4 seconds. Before each line in the ping output, add a timestamp. Add the -D option to the ping command if you want to record the time of day when you run it.
ping –D www.xyz.com
When a host is reachable, you'll hear an audible ping. When the –a switch is used, the device plays a sound when an answer from a host is sent.
When you're troubleshooting network problems and don't want to look at the computer before you get an answer, an audible ping will help.
ping –a www.xyz.com
Ping uses ICMP to send an ICMP echo message to the designated host, and then an ICMP returns a message if that host is open. Ping is usually calculated in milliseconds, and it comes pre-installed on any modern operating system. Ping is a network command-line interface for checking a host's IP-level reliability on a server.