Linux ping Command
The Linux ping command is used to check the connectivity to a host.
Executing the ping command uses the ICMP transmission protocol to send a request for a response. If the remote host's network is functioning properly, it will respond to this message, indicating that the host is operational.
Syntax
ping [-dfnqrRv][-c<completion count>][-i<interval seconds>][-I<network interface>][-l<preload>][-p<pattern>][-s<packet size>][-t<TTL value>][host name or IP address]
Parameter Description:
-d Use the SO_DEBUG function of the Socket.
-c <completion count> Set the number of echo requests to send.
-f Flood ping.
-i<interval seconds> Specify the wait interval between sending each packet.
-I<network interface> Use the specified network interface to send the packet.
-l<preload> Send specified number of packets not waiting for response.
-n Numeric output only.
-p<pattern> Pad the packet with a given pattern.
-q Quiet output. Only the summary and final results are displayed.
-r Bypass the normal routing tables and send directly to a host.
-R Record route.
-s<packet size> Specify the number of data bytes to be sent.
-t<TTL value> Set the IP Time to Live.
-v Verbose output.
-w <deadline> Stop after <deadline> seconds.
-W <timeout> Time to wait for a response, in seconds.
Examples
Checking connectivity to a host
# ping www.tutorialpro.org //ping host
PING aries.m.alikunlun.com (114.80.174.110) 56(84) bytes of data.
64 bytes from 114.80.174.110: icmp_seq=1 ttl=64 time=0.025 ms
64 bytes from 114.80.174.110: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 114.80.174.110: icmp_seq=3 ttl=64 time=0.034 ms
64 bytes from 114.80.174.110: icmp_seq=4 ttl=64 time=0.034 ms
64 bytes from 114.80.174.110: icmp_seq=5 ttl=64 time=0.028 ms
64 bytes from 114.80.174.110: icmp_seq=6 ttl=64 time=0.028 ms
64 bytes from 114.80.174.110: icmp_seq=7 ttl=64 time=0.034 ms
64 bytes from 114.80.174.110: icmp_seq=8 ttl=64 time=0.034 ms
64 bytes from 114.80.174.110: icmp_seq=9 ttl=64 time=0.036 ms
64 bytes from 114.80.174.110: icmp_seq=10 ttl=64 time=0.041 ms
--- aries.m.alikunlun.com ping statistics ---
10 packets transmitted, 30 received, 0% packet loss, time 29246ms
rtt min/avg/max/mdev = 0.021/0.035/0.078/0.011 ms
//Requires manual termination with Ctrl+C
Specifying the number of packets to receive
# ping -c 2 www.tutorialpro.org
PING aries.m.alikunlun.com (114.80.174.120) 56(84) bytes of data.
64 bytes from 114.80.174.120: icmp_seq=1 ttl=54 time=6.18 ms
64 bytes from 114.80.174.120: icmp_seq=2 ttl=54 time=15.4 ms
--- aries.m.alikunlun.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1016ms
rtt min/avg/max/mdev = 6.185/10.824/15.464/4.640 ms
//Exits automatically after receiving two packets
Using multiple parameters
# ping -c 5 -i 0.5 www.tutorialpro.org
ping -i 3 -s 1024 -t 255 g.cn //ping host
PING g.cn (203.208.37.104) 1024(1052) bytes of data. 1032 bytes from bg-in-f104.1e100.net (203.208.37.104): icmp_seq=0 ttl=243 time=62.5 ms 1032 bytes from bg-in-f104.1e100.net (203.208.37.104): icmp_seq=1 ttl=243 time=63.9 ms 1032 bytes from bg-in-f104.1e100.net (203.208.37.104): icmp_seq=2 ttl=243 time=61.9 ms
--- g.cn ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 6001ms rtt min/avg/max/mdev = 61.959/62.843/63.984/0.894 ms, pipe 2 [root@linux ~]#
//-i 3 send interval of 3 seconds -s set packet size -t set TTL value to 255 ```