ping
ping
The ping command is a fundamental network utility used to test the reachability of a host on an IP network and to measure the round-trip time for messages sent from the originating host to a destination computer. It is an essential tool for network troubleshooting and diagnostics.
How ping Works
ping Worksping uses the Internet Control Message Protocol (ICMP) Echo Request and Echo Reply messages. When you issue a ping command, the following steps occur:
ICMP Echo Request: The source computer sends an ICMP Echo Request message to the target host.
ICMP Echo Reply: If the target host is reachable, it responds with an ICMP Echo Reply message.
Round-Trip Time: The
pingcommand measures the time between sending the Echo Request and receiving the Echo Reply, providing the round-trip time (RTT).
Basic Syntax
The basic syntax of the ping command is:
ping [options] destinationdestination: The IP address or hostname of the target host.
Common Options
Basic Ping Command:
ping google.comThis command sends ICMP Echo Requests to
google.comindefinitely until stopped withCtrl+C.Specify Number of Echo Requests:
ping -c 4 google.comThis sends exactly 4 ICMP Echo Requests to
google.com.Specify Interval Between Pings:
ping -i 0.5 google.comThis sends ICMP Echo Requests every 0.5 seconds instead of the default 1-second interval.
Specify Packet Size:
ping -s 100 google.comThis sends ICMP Echo Requests with 100 bytes of data.
Flood Ping (Warning: High Network Load):
sudo ping -f google.comThis sends packets as fast as possible and requires root privileges. It is useful for stress testing but can create high network load.
Ping a Specific Network Interface:
ping -I eth0 google.comThis sends ICMP Echo Requests using the specified network interface (
eth0).Timeout for Ping Command:
ping -w 5 google.comThis sets a timeout of 5 seconds for the
pingcommand.
Example Usage
Basic Connectivity Test:
ping 8.8.8.8This tests connectivity to Google's public DNS server.
Ping a Local Host:
ping localhostThis tests the local network interface.
Test with Detailed Output:
ping -v google.comThis provides verbose output, including detailed diagnostic information.
Analyzing Output
The typical output of a ping command looks like this:
PING google.com (172.217.11.142): 56 data bytes
64 bytes from 172.217.11.142: icmp_seq=0 ttl=54 time=10.4 ms
64 bytes from 172.217.11.142: icmp_seq=1 ttl=54 time=10.1 ms
64 bytes from 172.217.11.142: icmp_seq=2 ttl=54 time=10.2 ms
64 bytes from 172.217.11.142: icmp_seq=3 ttl=54 time=10.3 ms
--- google.com ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 10.1/10.3/10.4/0.1 msicmp_seq: Sequence number of the ICMP Echo Request.
ttl: Time to Live, indicating the remaining number of hops.
time: Round-trip time in milliseconds.
statistics: Summary of packets transmitted, received, packet loss, and round-trip time statistics (minimum, average, maximum, and standard deviation).
Conclusion
The ping command is an invaluable tool for network troubleshooting, allowing you to verify the reachability of hosts, measure network latency, and diagnose connectivity issues. By mastering the use of ping with various options, you can effectively diagnose and resolve a wide range of network problems. For more advanced usage, consult the ping man page:
man pinghelp
ping: invalid option -- '-'
Usage
ping [options] <destination>
Options:
<destination> dns name or ip address
-a use audible ping
-A use adaptive ping
-B sticky source address
-c <count> stop after <count> replies
-D print timestamps
-d use SO_DEBUG socket option
-f flood ping
-h print help and exit
-I <interface> either interface name or address
-i <interval> seconds between sending each packet
-L suppress loopback of multicast packets
-l <preload> send <preload> number of packages while waiting replies
-m <mark> tag the packets going out
-M <pmtud opt> define mtu discovery, can be one of <do|dont|want>
-n no dns name resolution
-O report outstanding replies
-p <pattern> contents of padding byte
-q quiet output
-Q <tclass> use quality of service <tclass> bits
-s <size> use <size> as number of data bytes to be sent
-S <size> use <size> as SO_SNDBUF socket option value
-t <ttl> define time to live
-U print user-to-user latency
-v verbose output
-V print version and exit
-w <deadline> reply wait <deadline> in seconds
-W <timeout> time to wait for response
IPv4 options:
-4 use IPv4
-b allow pinging broadcast
-R record route
-T <timestamp> define timestamp, can be one of <tsonly|tsandaddr|tsprespec>
IPv6 options:
-6 use IPv6
-F <flowlabel> define flow label, default is random
-N <nodeinfo opt> use icmp6 node info query, try <help> as argument
For more details see ping(8).Last updated