Search

An Overview of ping

ping is a diagnostic tool used for verifying connectivity between
two hosts on a network. It sends Internet Control Message Protocol
(ICMP) echo request packets to a remote IP address and watches for ICMP
responses. The author of the initial version of the ping program that
we use today was Mike Muss. Many other people have tweaked, rewritten
and variously abused ping since then.

The name ping itself is somewhat colorful. Some people claim that
it is an acronym standing for Packet INternet Groper, but this is not
the case. ping was named after the sound a sonar tracking system makes.
There even is a story claiming that a system administrator wrote a
script that repeatedly pinged a host on the network and made an audible
"pinging" alert for each success. The system administrator then was able
to go through his network methodically checking BNC connectors until he
found the dodgy connector that had been plaguing his network. When the
noises stopped, he'd found the culprit.

ping used to be a good indicator of a machine's general ability to receive
and send IP packets. If you could ping a host, you also could make an
FTP or HTTP connection. With the wider advent of packet filtering for
security, though, this is becoming less true. Many firewalls explicitly
disallow ICMP packets on the twin grounds that people don't need to know
what your internal network looks like and any protocol can be used to
launch an attack, even ICMP.

Deciding whether to let ICMP through your firewall is a tough call to
make. There certainly are good uses for ICMP, but there also are attacks
based on ICMP. For example, the "ping of Death" uses oversized ping
packets to overload the IP stack of the target--often with spectacular
results. If you choose to allow ICMP into your network, make sure you've
thought about the repercussions.

Additional flavors of the ping command exist that have been written
for other purposes. Among the most common is fping, which
was written to ping a range of addresses. It commonly is used in
network scanners and monitors, such as saint and mon. Another variation
is the Net::Ping module, which provides a Perl implementation of ping
functionality that can be used easily from within a script without
calling an external program. You might use the script something like
this:

This output can be split into three sections. The first section, the single
line starting with the word PING, shows an overview of the command.
The second section, the lines beginning with 64
bytes shows a running tally of the responses received. The third
section, everything after the line --- mango ping statistics
---, shows a summary of the results. In this case, the
results are good: none of the packets was dropped and they all were passed
fairly quickly.

This example also illustrates another important point: you should not rely on
a single packet to diagnose your network. A series of five or ten
packets is much better, as you can count up to 40% data loss as congestion
on a network. Even a single dropped packet can be attributed to a busy
host on the other end.

Several useful options can be used with the ping command. These are
summarized in the following table:

Table 1. ping Command Options

Option

Description

-c count

Stop sending and receiving packets after
count packets.

-d

Set the SO_DEBUG on the socket used.

-f

Send the packets as fast as possible. (flood)

-i wait

Set an interval of wait
seconds between packets.

-I (device)

Set the output interface.

-l preload

Send preload packets as fast as possible, then drop
back to normal mode.

-n

Don't look up hostnames, just give IP addresses.
(numeric)

-p pattern

Specify up to 16 bytes of "pad data" to be sent with the
packet.

-q

Output only summary lines. (quiet)

-r

Don't use routing tables to send the packet, just drop it out the local
interface.

-R

Set the Record Route option.

-s packetsize

Set the number of data bytes sent to
packetsize.

-T tsonly

Send a ping with the timestamp option.

-T tsandaddr

Collect timestamps and addresses

-T tsprespec [host1 [host2 [host3 [host4]]]]

Collect timestamps and addresses from prespecified hops.

These options can be combined to make ping even more helpful. One thing
you cannot see is that the ping command used in the previous
section is likely to take several seconds to run and report back. Using
the -f option, though, can reduce the time spent waiting for the command.
Combining this with the -c 10 and the -q options can give you quicker results
and easier output to read:

Note: The record route option specified by the -R option is not
honored by all routers and hosts. Further, it contains limited
space to hold router addresses. Therefore, traceroute may be a better tool for
identifying the path packets take through a network.

Overall, the ping command is a useful tool for your troubleshooting kit
and should not be overlooked.

Copyright (c) 2000, Pat Eyler and New Riders Publishing. Originally published in Linux
Gazette issue 56. It is presented under the
Open Publication
License, with no additional terms applied.

Pat Eyler is a Linux/UNIX/networking geek who enjoys
playing on the command line. When he's not puttering with or writing
about computers and networks, he likes to play with his kids, cook
and read.