Ping is one of the most used tool for network diagnostics. When internet is not working, can not access file shares etc we will firstly ping command. Ping is one of the most known tool in the IT area. Ping actually uses ICMP packets to get information about network status. In this tutorial we will look practical use cases of Ping tool.
Syntax of ping command for Linux is like below.
$ ping [options] [hop1...] destination
$ ping -h
ICMP is a network protocol mainly used by ping command. ICMP have different type of messages to exchange network, host, router, switch information. Ping command uses
ICMP Request which is numbered 8 and
ICMP Reply which is numbered 0.
We will just ping with default settings for ping command. By default ping will work infinitely. We can stop ping command with processes cancel keyboard shortcut
$ ping poftut.com
After stopping ping command there will be some statistics about ping command. There will be following information
Packet transmittedshows the count of total packet sent
Receivedshow total count of packets received
Packet lossshow the percentage of lost or not responded packages
Timeshows how long the ping command worked.
Rtt minshow minimum round trip time which is how long take a ICMP request and response
Rtt avgshows average round trip time
Rtt maxshows maximum round trip time
By default ping command uses 1 second intervals. Interval is the time between two ping or ICMP request. This amount can be changed with
$ ping -i 2 poftut.com
In previous example we have increased the interval. We can also set lower interval for ping requests. But there is a minor difference. To set interval lower than 0.2 we need root privileges. In this example we will set interval as 0.5 second.
$ ping -i 0.5 poftut.com
Check Local Interface Status
Ping have some diagnostic feature. We can check the status of the local network interface with destination address
Set Packet Count
As we stated before ping command will work endlessly if there is no interrupt for ping. Providing this interrupt can be difficult job if we use ping as a batch script. We may need to run ping some little time and use the output. In this situations we can set the packet count. Ping will only send specified count. In this example we will send only 3 ping or ICMP requests to the destination.
$ ping -c 3 poftut.com
There are some alert mechanism in the ping command. Ping command can provided some voice alert if some change occur. This change can be the destination host is down or up. But keep in mind that this may not work in some terminals.
$ ping -a poftut.com
Find IP Address
The IP address will be printed in the first line of ping output if we specify the destination with its host name.
$ ping poftut.com
In this example host name is
poftut.com and related IP address is
Change Ping Packet Size
Ping command uses ICMP packets and puts some meaningless data in the ICMP packet. This data size is 56 byte by default. This data size can be changed with
-s parameter. In this example we will set the data size for ICMP packet 200.
$ ping -s 200 poftut.com
Set Time To Live or TTL
IP packets have Time To Live count. This TTL will set how much hop the packet can transmitted. By using
-t option TTL value can be set. In this example we will set TTL as 22 which is by default 52.
$ ping -t 22 poftut.com
While sending ICMP request packets we wait for some amount of time for the ICMP response. This waiting time can be change with
-w option. After the timeout value the ping command will exit. In this example we will set timeout value as 2 seconds.
$ ping -w 2 poftut.com
Set Route or Path For Ping
The ICMP packets send by ping command will be routed according to the default routes in the network. Sometimes this default routes will not enough for the test case. In this situations the route information can be provided to the ping command by adding them before the destination. In this example we will set
192.168.122.1 route byte hand. We want to ping destination
$ ping 192.168.122.239 192.168.122.1 poftut.com
But keep in mind that the network devices should be supported host provided routing. This can be a security implication and disabled in the network devices.
Online Ping Tool
There are some online ping tools which provided the scale ability to select source host.
Flood ICMP Packets
Flood is a term used to specify uncontrolled high level network traffic. Ping command can flood ICMP requests to the destination with
-f option. This will generate mass ICMP requests without setting any interval or count. In order to flood we need root privileges.
$ ping -f poftut.com
As we can see from example there is no verbose information about the ICMP requests. There will be only a summary about the ping command.
Ping command version information can be printed with
-v parameter like below.
$ ping -V
As we can see that ping utility is provided by iputils package which version is s20150815