Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux ping command

Linux ping command

Linux Command Reference Linux Command Reference

The Linux ping command is used to test the network connection to another host.

The ping command measures network response time and packet loss by sending data packets to the target host and waiting for replies.

Running the ping command uses the ICMP (Internet Control Message Protocol) protocol to send a request for a reply; if the remote host's network functions properly, it will reply, thus indicating that the host is operating normally.

Syntax

ping [选项] [目标主机/IP地址]

Parameter Description:

Example

1. Check connectivity with the host:

# ping www.runoob.com //ping主机

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



//Must be terminated manually Ctrl+C

2. Limit the number of packets sent:

# ping -c 2 www.runoob.com

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



//Exit automatically after receiving two packets

3. Using multiple options:-i 3 sets the send interval to 3 seconds -s sets the packet size -t sets the TTL value to 255

# ping -i 3 -s 1024 -t 255 g.cn //ping主机

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

**4. Set the packet interval:** send packets at intervals of 0.2 seconds; this option is suitable for testing short-term network stability.



ping -i 0.2 www.runoob.com

**5. Specify the packet size:** set the packet size to 128 bytes, suitable for checking stability when transferring larger amounts of data.



ping -s 128 www.runoob.com

**6. Set the network timeout:** limit the test time to 10 seconds, suitable for testing connectivity when the network environment is uncertain.



ping -w 10 www.example.com

Common output analysis

The output of the ping command typically includes the following information:

PING www.example.com (93.184.216.34): 56 data bytes

64 bytes from 93.184.216.34: icmp_seq=0 ttl=56 time=10.1 ms

64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=10.3 ms



--- www.example.com ping statistics ---

2 packets transmitted, 2 packets received, 0% packet loss

round-trip min/avg/max/stddev = 10.1/10.2/10.3/0.1 ms

Advanced applications

**1. Quickly check network connection:** send one packet with a 1-second timeout to quickly check whether the network is connected.



ping -c 1 -W 1 www.example.com

** 2. Test network stability with large packets:** send 1024-byte packets a total of 10 times to test network capacity.



ping -s 1024 -c 10 www.example.com

**3. IPv6 network test:** force the IPv6 protocol to test connectivity, suitable for IPv6 environments.



ping -6 www.example.com

Notes

Using the ping command, you can quickly check network connection status and troubleshoot network faults; it is an essential tool for every network administrator.

Linux Command Reference Linux Command Reference