Tuesday, September 11, 2007

Linux Ping command explained

We have always been using ping command ever since the network begun. Ping has been in the service for gazillions of echo requests and replies locally and/or from the web. Almost everybody doing link connectivity test between two points is familiar with ping command. Ping command is available in many worlds of operating system and IP address domain. You can easily find them installed by default OS installation. Not only sysads, even newbies and non-techies who's currently beginning to enter the world of connectivity troubleshooting never crawl google index to search for more ping explanation.

Ping command as compared to a new kid's world is like a new bike, just hit the pedal with your feet and your bike will move forward then. Ping results is more likely provides the same concept of the bike. The ping command result, host reachable or not reachable is what matter most.

As ping command is so easy and widely used, even grandma can manage to ping grandpa from the other room, this entry is here to explain and document more of ping arguments and usage details, which might be helpful to others hopefully.

PING definition
Wikipedia says:

ping is a computer network tool used to test whether a particular host is reachable across an IP network. It works by sending ICMP “echo request” packets to the target host and listening for ICMP “echo response” replies. ping estimates the round-trip time, generally in milliseconds, and records any packet loss, and prints a statistical summary when finished.

The word ping is also frequently used as a verb or noun, where it can refer directly to the round-trip time, the act of running a ping program or measuring the round-trip time.


The simplest way to use ping from any operating system is to supply it with an IP address without further consideration to DNS issue and current IP address of working host, like so:

# ping

This is the usual way to ping an IPv4 based host. The above assumes that is the host we wish to get ICMP ECHO RESPONSE reply from.

To send a specified or limited number of ECHO REQUEST packets, simply use -c argument like so

# ping -c2

-c followed by 2 is the number of ICMP ECHO REQUEST we wish to send forth against the target host . The above command sends out 2 ICMP ECHO REQUEST to target host.

To ping a broadcast address using ping on a subnetted IP network or network class, simply

# ping -b

The above command assumes a broadcast IP address of for /27 subnet class.

To send ping with interval mode between each ping, this can be done like so

# ping -i 3

which sends out a single echo request every 3 seconds against the target host. This is also handy as some target host are too sensitive and have too high ping thresholds against echo request that immediately triggers ping flood attack, which might cause blockage to your current host.

A ping source address can also be specified with ping. This is where ping echo request would be released from ifever your current host has several virtual IP address or multiple network card interface.

# ping -I eth0:0
# ping -I eth1

To use ping flood would be

# ping -f localhost

which display . for every ping echo request sent and prints a backspace for every ICMP reply received

To send out ping packets while displaying host route path found along the round trip travel of ping packets would be like so

# ping -R

This could be visually handy with those hidden routers, firewalls, or gateways that has transparent port forwarding enabled and being supported.

To customize and change the default IP time to live or TTL values with ping would be like

# ping -t 1

Ping sends out ping echo request packet size of 64 ICMP bytes including data headers. To send out a customized ping packet size

# ping -s 24

changes ping echo request packet size from 56 down to 24, excluding the ICMP data header.

To specify in seconds a forced termination of ping commands would be

# ping -w 5

which forcefully but gracefully terminates the issue ping command after 5 seconds.

To ping an IPv6 IP address would be as follows

# ping6 -I eth0 fe80::203:47ff:fe31:5569
# ping6 -c 3 -I eth1 fe80::203:47ff:fe31:556a

Ping arguments can be combined when needed so.

A sample ping command would be

# ping
64 bytes from icmp_seq=1 ttl=255 time=4.19 ms
64 bytes from icmp_seq=2 ttl=255 time=1.05 ms
64 bytes from icmp_seq=3 ttl=255 time=1.02 ms
--- ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 1.025/2.092/4.197/1.488 ms
Notes: that icmp_seq displays the number of ping echo request being sent which appears in consecutive number patterns for normal ping echo replies.

From above results, 3 ICMP echo request packets have been transmitted, and 3 ICMP echo replies have been received with default 255 TTL. A round trip icmp echo reply average of 2.092 ms for the whole ping round trip transmitted and received, that is 0% packet loss in total stats.

Multiple host pinging using ping is not possible via command line unless you create a script to feed in IP address from it. However, there are alternatives to ping multiple host, one of them is using the linux command fping.

For a more verbosed mode would be the usual verbose mode parameter -v and for more a quite mode would be -q, the usual parameter with most handy linux tools.

By default, ping is installed as world executable and and readable binary.


Remember that issuing ping command can not guarantee anybody a reachable host connectivity between two or more hosts. Any failed ICMP reply does not mean a dead target host as well. Ping does not consider target host's setup, firewalls, and routers in between the travel path. Ping ignorantly assumes that the target host and the path is open for ICMP echo replies from requesting ICMP echo request host.

So happy pinging!


Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy