YouTip LogoYouTip

Linux Comm Ping

[![Image 1: Linux Command Manual](#) Linux Command Manual](#) The Linux `ping` command is used to test network connectivity to another host. The `ping` command works by sending packets to a target host and waiting for a response, allowing it to measure network response time and packet loss. Executing the `ping` command uses the ICMP (Internet Control Message Protocol) transport protocol to send out echo request messages. If the remote host's network functionality is working properly, it will respond to these messages, thereby confirming that the host is operating normally. ### Syntax ping [target host/IP address] **Parameter Description**: * `-c`: Specifies the number of packets to send, for example, `-c 4` means sending 4 packets. * `-i`: Specifies the interval time (in seconds) between sending packets, for example, `-i 0.5` means sending once every 0.5 seconds. * `-w`: Sets a timeout limit for sending packets; it automatically stops after this time, for example, `-w 5` means waiting for 5 seconds. * `-s`: Specifies the size of each packet (in bytes), default is 56 bytes. * `-t`: Sets the Time To Live (TTL) for packets, specifying the number of routing hops. * `-q`: Quiet mode, only displays the start and end statistics, not detailed information for each packet. * `-f`: Flood mode, sends packets rapidly, used for testing network capacity; use with caution. * `-l`: Specifies the number of packets to send at once, typically used for load testing. * `-v`: Displays verbose output information, used for debugging. * `-4`: Forces the use of the IPv4 protocol. * `-6`: Forces the use of the IPv6 protocol. ### Examples **1. Test connectivity to a host:** # ping example.com //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 //Needs manual termination with Ctrl+C **2. Limit the number of packets sent:** # ping -c 2 example.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 //Automatically exits after receiving two packets **3. Using multiple parameters:** -i 3 sets the send cycle 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 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 **4. Set packet interval time:** Send packets at an interval of 0.2 seconds. This parameter is suitable for testing network stability over a short period. ping -i 0.2 example.com **5. Specify packet size:** Set the packet size to 128 bytes, suitable for checking stability during larger data transfers. ping -s 128 example.com **6. Set network timeout:** Limit the test time to 10 seconds, suitable for testing connectivity in uncertain network environments. ping -w 10 www.example.com ### Common Output Analysis The output of the `ping` command typically contains the following information: * **Packets sent and received**: Shows how many packets were sent during the test, how many were received, and the packet loss rate. * **Round-trip time statistics**: Displays the minimum, maximum, average, and standard deviation of the round-trip times (in milliseconds). 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. Quick network connectivity test:** Send one packet with a timeout of 1 second to quickly check if the network is connected. ping -c 1 -W 1 www.example.com **2. Test network stability with large packets:** Send 1024-byte packets 10 times to test network capacity. ping -s 1024 -c 10 www.example.com **3. IPv6 network test:** Force the use of the IPv6 protocol to test connectivity, suitable for IPv6 environments. ping -6 www.example.com ### Notes * `ping` uses the ICMP protocol. Some firewalls may block ICMP packets, which can cause the `ping` command to malfunction. * Flood mode (`-f` parameter) sends packets very quickly. It is recommended to use it in a secure network environment, as it might otherwise be considered an attack. Using the `ping` command allows for quick detection of network connection status and troubleshooting of network faults, making it an essential tool for every network administrator. [![Image 2: Linux Command Manual](#) Linux Command Manual](#)
← Linux Comm PppstatsLinux Comm Netstat β†’