7 Ping Very Useful Examples

7 Ping Very Useful Examples

PING

Ping command is used to find out whether the peer host/gateway is reachable.

1. Increase or Decrease the Time Interval Between Packets

You can increase or decrease this using option -i as shown below.
Decrease Ping Time Interval – wait 0.2 seconds before sending the next packet

# ping -i 0.2 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.035 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.049 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.049 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.039 ms
^C
--- 127.0.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 599ms
rtt min/avg/max/mdev = 0.035/0.043/0.049/0.006 ms

2. Send N packets and stop

#ping -c 5 google.com
PING google.com (216.58.217.206) 56(84) bytes of data.
64 bytes from 216.58.217.206: icmp_seq=1 ttl=56 time=1.02 ms
64 bytes from 216.58.217.206: icmp_seq=2 ttl=56 time=0.921 ms
64 bytes from 216.58.217.206: icmp_seq=3 ttl=56 time=0.837 ms
64 bytes from 216.58.217.206: icmp_seq=4 ttl=56 time=0.845 ms
64 bytes from 216.58.217.206: icmp_seq=5 ttl=56 time=0.858 ms

 

3. Flood the network

It prints a ‘.’ when a packet is sent, and a backspace is printed when a packet is received.

# ping -f localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
^C
--- localhost ping statistics ---
413166 packets transmitted, 413166 received, 0% packet loss, time 10579ms
rtt min/avg/max/mdev = 0.003/0.004/0.493/0.002 ms, pipe 2, ipg/ewma 0.025/0.006 ms

 

4. Audible ping

Give beep when the peer is reachable. When the remote machine become reachable you’ll hear the beep automatically.

# ping -a IP

 

5. Find out the IP address

# ping -c 1 google.com
PING google.com (216.58.217.206) 56(84) bytes of data.
64 bytes from 216.58.217.206: icmp_seq=1 ttl=56 time=1.16 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.167/1.167/1.167/0.000 ms

 

6. Change Ping Packet Size

Change the packet size of ping command using -s option.

# ping -s 1000 localhost
PING localhost (127.0.0.1) 1000(1028) bytes of data.
1008 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.054 ms
1008 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.044 ms
^C
--- localhost ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.044/0.049/0.054/0.005 ms

When we set the packet size to 1000, it displays ‘1028 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 1000, 28 bytes for header will be added to it and 128 bytes will be sent.

 

7. Timeout

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.

# ping -w 3 localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.041 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.039 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.041 ms

--- localhost ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2997ms
rtt min/avg/max/mdev = 0.036/0.039/0.041/0.004 ms

 

arstech

Leave a Reply