Ping Tutorial: 15 Effective Ping Command Examples
As you already know, ping command is used to find out whether the peer host/gateway is reachable.
If you are thinking ping is such a simple command and why do I need 15 examples, you should read the rest of the article.
Ping command provides lot more options than what you might already know.
Ping Example 1. Increase or Decrease the Time Interval Between Packets
By default ping waits for 1 second before sending the next packet.
You can increase or decrease this using option -i as shown below.
Increase Ping Time Interval
Example: Wait for 5 seconds before sending the next packet.
$ ping -i 5 IP
Decrease Ping Time Interval
Example: Wait 0.1 seconds before sending the next packet.
# ping -i 0.1 IP<br>
Note: Only super user can specify interval less than 0.2 seconds. If not, you’ll get the following error message.
$ ping -i 0.1 127.0.0.1<br>PING 0 (127.0.0.1) 56(84) bytes of data.<br>ping: cannot flood; minimal interval, allowed for user, is 200ms<br>
Ping Example 2. Check whether the local network interface is up and running
Before checking whether the peer machine is reachable, first check
whether the local network network is up and running using any one of
the following 3 methods.
Ping localhost using zero (0)
This is probably the easiest and simplest way to ping a local host
$ ping 0<br>PING 0 (127.0.0.1) 56(84) bytes of data.<br>64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.024 ms<br>^C<br>
Ping localhost using name
$ ping localhost<br>PING localhost (127.0.0.1) 56(84) bytes of data.<br>64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.051 ms<br>64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.055 ms<br>^C<br>--- localhost ping statistics ---<br>2 packets transmitted, 2 received, 0% packet loss, time 999ms<br>rtt min/avg/max/mdev = 0.051/0.053/0.055/0.002 ms<br>
Ping localhost using ip
$ ping 127.0.0.1
To quit the ping command, send SIGINT signal by pressing CTRL+C. If
you have not specified any option to make the ping to exit
automatically, then you will be terminating using CTRL+C ( SIGINT )
which will show the statistics and then terminate the ping process.
When everything is working properly, it should say ‘0% packet loss’
2 packets transmitted, 2 received, <strong>0% packet loss,</strong> time 999ms<br>rtt min/avg/max/mdev = 0.051/0.053/0.055/0.002 ms<br>
Ping Example 3. Send N packets and stop
Send N packets specified with -c option and then stop. This way the
ping command can exit automatically instead of pressing CTRL+C to exit.
In the following example, ping command sends 5 packets, and waits
for response from the destination host. Ping will exit after receiving
the response or error.
$ ping -c 5 google.com<br>PING google.com (74.125.45.100) 56(84) bytes of data.<br>64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=1 ttl=44 time=731 ms<br>64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=2 ttl=44 time=777 ms<br>64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=3 ttl=44 time=838 ms<br>64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=4 ttl=44 time=976 ms<br>64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=5 ttl=44 time=1071 ms<br><br>--- google.com ping statistics ---<br>5 packets transmitted, 5 received, 0% packet loss, time 4216ms<br>rtt min/avg/max/mdev = 731.039/879.129/1071.050/126.625 ms<br>
Ping Example 4. Show Version and Exit
Display the current version of ping program using -V option.
$ ping -V<br>ping utility, iputils-sss20071127<br>
Ping Example 5. Flood the network
Super users can send hundred or more packets per second using -f
option. It prints a ‘.’ when a packet is sent, and a backspace is
printed when a packet is received.
As shown below, ping -f has sent more than 400,000 packets in few seconds.
# ping -f localhost<br>PING localhost (127.0.0.1) 56(84) bytes of data.<br>.^C<br>--- localhost ping statistics ---<br><strong>427412 packets transmitted</strong>, 427412 received, 0% packet loss, time 10941ms<br>rtt min/avg/max/mdev = 0.003/0.004/1.004/0.002 ms, ipg/ewma 0.025/0.004 ms<br>
Ping Example 6. Audible ping: Give beep when the peer is reachable
This option is useful for sysadmin during troubleshooting. There is
no need for you to look at the ping output after each and every change.
You can continue working with your changes, and when the remote machine
become reachable you’ll hear the beep automatically.
$ ping -a IP<br>
Note: It can give beep only from terminal number 1 through 7 and gnome-terminal ( It will not work in console ).
Ping Example 7. Find out the IP address
You can identify the ip-address using the host name as shown below.
$ ping -c 1 google.com<br>PING google.com (<font color="red"><strong>74.125.67.100</strong></font>) 56(84) bytes of data.<br>64 bytes from gw-in-f100.google.com (74.125.67.100): icmp_seq=1 ttl=43 time=287 ms<br><br>--- google.com ping statistics ---<br>1 packets transmitted, 1 received, 0% packet loss, time 0ms<br>rtt min/avg/max/mdev = 287.903/287.903/287.903/0.000 ms<br>
Ping Example 8. Print Only Ping Command Summary Statistics
Use option -q to view only the ping statistics summary as shown below.
$ ping -c 5 -q 127.0.0.1<br>PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.<br><br>--- 127.0.0.1 ping statistics ---<br>5 packets transmitted, 5 received, 0% packet loss, time 3998ms<br>rtt min/avg/max/mdev = 0.047/0.053/0.061/0.009 ms<br>
Ping Example 9. Change Ping Packet Size
You can change the packet size of ping command using -s option.
Example: Change the default packet size from 56 to 100.
$ ping -s 100 localhost<br>PING localhost (127.0.0.1) 100(128) bytes of data.<br>108 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.022 ms<br>108 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.021 ms<br>108 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.020 ms<br>^C<br>--- localhost ping statistics ---<br>3 packets transmitted, 3 received, 0% packet loss, time 1998ms<br>rtt min/avg/max/mdev = 0.020/0.021/0.022/0.000 ms<br>
Ping Packet Size
In the above example, when we set the packet size to 100, it
displays ‘128 bytes’ in the output. This is because of the Ping packet
header size, which is 28 bytes. So, if you specify the packet size as
100, 28 bytes for header will be added to it and 128 bytes will be sent.
Ping Bytes Sent = Ping Packet Size + Ping Header Packet Size (28 bytes)
Ping Example 10. Timeout -w
Ping -w option specifies the deadline to terminate the ping output.
This specifies the total number of seconds the ping command should send
packets to the remote host.
The following example will ping for 5 seconds. i.e ping command will
exit after 5 seconds irrespective of how many packets are sent or
received.
$ ping -w 5 localhost<br>
Note: When you specify both -w, and -c, whichever comes first will terminate the ping command.
Ping Example 11. Online ping
Ping from different locations and check the reachability
(availability or time for reaching) of your server from different
locations.
If you want to do an online ping, try just ping.
Ping Example 12. Option -w or -c Exits Ping
$ ping -c 4 0 <font color="red">-w 2</font><br>PING 0 (127.0.0.1) 56(84) bytes of data.<br>64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.064 ms<br>64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.060 ms<br>64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.058 ms<br><br>--- 0 ping statistics ---<br>3 packets transmitted, 3 received, 0% packet loss, <font color="red">time 1998ms</font><br>rtt min/avg/max/mdev = 0.058/0.060/0.064/0.009 ms<br>$ ping <font color="red">-c 4</font> 0 -w 10<br>PING 0 (127.0.0.1) 56(84) bytes of data.<br>64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.063 ms<br>64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.060 ms<br>64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.055 ms<br>64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.061 ms<br><br>--- 0 ping statistics ---<br><font color="red">4 packets transmitted, 4 received</font>, 0% packet loss, time 2997ms<br>rtt min/avg/max/mdev = 0.055/0.059/0.063/0.009 ms<br>
Ping Example 13. Shorter statistics with SIGQUIT
While ping is printing the individual packet status, when you want to view the shorter statistics you can use this technique.
Pressing CTRL+| (Control key followed by pipe
symbol) for the shows the summary in between, and continues with it
packet sending and receiving process.
$ ping -w 100 localhost<br>PING localhost (127.0.0.1) 56(84) bytes of data.<br>64 bytes from localhost (127.0.0.1): icmp_seq=10 ttl=64 time=0.021 ms<br>64 bytes from localhost (127.0.0.1): icmp_seq=11 ttl=64 time=0.022 ms<br><strong>11/11 packets, 0% loss, min/avg/ewma/max = 0.020/0.022/0.022/0.024 ms<br></strong>64 bytes from localhost (127.0.0.1): icmp_seq=12 ttl=64 time=0.021 ms<br>64 bytes from localhost (127.0.0.1): icmp_seq=13 ttl=64 time=0.022 ms<br>64 bytes from localhost (127.0.0.1): icmp_seq=14 ttl=64 time=0.021 ms<br>64 bytes from localhost (127.0.0.1): icmp_seq=15 ttl=64 time=0.021 ms<br><strong>19/19 packets, 0% loss, min/avg/ewma/max = 0.020/0.022/0.022/0.024 ms<br></strong>64 bytes from localhost (127.0.0.1): icmp_seq=31 ttl=64 time=0.022 ms<br>64 bytes from localhost (127.0.0.1): icmp_seq=32 ttl=64 time=0.022 ms<br><strong>32/32 packets, 0% loss, min/avg/ewma/max = 0.020/0.022/0.022/0.027 ms<br></strong>64 bytes from localhost (127.0.0.1): icmp_seq=33 ttl=64 time=0.023 ms<br>..<br>
Ping Example 14. Specify path for ping to send the packet
You can also specify through which path the ping should send the packet to destination.
$ ping hop1 hop2 hop3 .. hopN destination<br>
$ ping 192.168.3.33 192.168.7.1 192.168.4.45<br>
Note: If one of the hop in the path is not reachable then you will have failure in pinging.
Ping Example 15. Record and print route of how ECHO_REQUEST sent and ECHO_REPLY received
It records, and prints the network route through which the packet is
sent and received. This is useful for network engineers who wish to
know how the packet is sent and received.
$ ping -R 192.168.1.63<br>PING 192.168.1.63 (192.168.1.63) 56(84) bytes of data.<br>64 bytes from 192.168.1.63: icmp_seq=1 ttl=61 time=2.05 ms<br>RR: 192.168.9.118<br> 192.168.3.25<br> 192.168.10.35<br> 192.168.1.26<br> 192.168.1.63<br> 192.168.1.63<br> 192.168.10.4<br> 192.168.3.10<br> 192.168.4.25<br>64 bytes from 192.168.1.63: icmp_seq=2 ttl=61 time=2.00 ms (same route)<br>
0 comments:
Post a Comment