Ping
Function Description: The ping command in Linux is a common network command. It is usually used to test the connectivity with the target host. We often say, "ping a machine, check if it is on. "If you cannot open the webpage, you will say" You should ping the gateway address 192.168.1.1 first ". It sends an ICMPECHO_REQUEST packet to the network host (send ICMP ECHO_REQUEST tonetwork hosts) and displays the response, in this way, we can determine whether the target host is accessible Based on the output information (but this is not absolute ). Some servers disable ping or disable ping in kernel parameters through the firewall to prevent detection. In this way, you cannot ping the server to determine whether the host is still enabled.
The Ping Command is frequently used in network troubleshooting. You can quickly determine whether the egress path is connected and whether the NIC works properly. The ping Command calculates the statistical information of the signal return time and packet loss, and displays a brief summary after completion. The ping Command ends when the program times out or when the SIGINT signal is received. The Host parameter is either a valid Host name or an Internet address.
Command parameters:
-D: Use the SO_DEBUG function of Socket.
-F limit detection. Send a large number of network packets to a machine quickly and view the response.
-N: only numbers are output.
-Q: only the final result is displayed. [Can this be added to the script later to serve as the basis for ping result judgment?]
-R ignores common Routing tables and directly sends data packets to the remote host. Check whether the network interface of the local machine is faulty.
-R records the routing process. : Generally, you can test the link in which the network link is faulty.
-V displays the instruction execution process in detail.
-C COUNT: stops sending a specified number of packages.
-I seconds: sets the interval of seconds to send a network packet to a machine. The default value is one second.
-I Network Interface: Use the specified network interface to send data packets.
-L pre-loading: sets the data packet that is sent before the request information is sent.
-P template style: Set the template style for filling data packets.
-S Bytes: specifies the number of data bytes sent. The default value is 56, plus an 8-byte ICMP header, which is a total of 64 ICMP data bytes.
-T survival value: Set the TTL value of the survival value.
(1) ping a website for a specified number of times
[Root @ LiWenTong ~] # Ping-c 4 www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56 (84) bytesof data.
64 bytes from 115.239.210.27: icmp_seq = 1 ttl = 56 time = 17.5 ms --- you can see the time from the start to the response message.
64 bytes from 115.239.210.27: icmp_seq = 2 ttl = 56 time = 18.6 MS
64 bytes from 115.239.210.27: icmp_seq = 3 ttl = 56 time = 17.9 MS
64 bytes from 115.239.210.27: icmp_seq = 4 ttl = 56 time = 17.8 MS
--- Www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2998 ms-"When the ping is complete, there is a report about the ping, how much to send, how much to receive, and how much to lose.
Rtt min/avg/max/mdev = 17.534/17.999/18.687/0.433 ms
(2) specify the time interval and ping packet size to ping a network
[Root @ LiWenTong ~] # Ping-I 3-c 5-s 1024 www.baidu.com
PING www.a.shifen.com (115.239.210.26) 1024 (1052) bytes of data.-ping Baidu with a ping packet of 1024 in size at an interval of 3 seconds.
1032 bytes from 115.239.210.26: icmp_seq = 1 ttl = 56 time = 18.8 MS
1032 bytes from 115.239.210.26: icmp_seq = 2 ttl = 56 time = 19.6 MS
1032 bytes from 115.239.210.26: icmp_seq = 3 ttl = 56 time = 18.2 MS
1032 bytes from 115.239.210.26: icmp_seq = 4 ttl = 56 time = 17.5 MS
1032 bytes from 115.239.210.26: icmp_seq = 5 ttl = 56 time = 19.1 MS
--- Www.a.shifen.com ping statistics ---
5 packets transmitted, 5 bytes ed, 0% packet loss, time 12001 ms
Rtt min/avg/max/mdev = 17.543/18.678/19.629/0.727 ms
(3) ping different network conditions
[Root @ LiWenTong ~] # Ping 192.168.41.101
PING 192.168.41.101 (192.168.41.101) 56 (84) bytesof data. --- indicates that the target network is inaccessible, that is, no.
From 192.168.41.48 icmp_seq = 2 Destination HostUnreachable
From 192.168.41.48 icmp_seq = 3 Destination HostUnreachable
From 192.168.41.48 icmp_seq = 4 Destination HostUnreachable
From 192.168.41.48 icmp_seq = 5 Destination HostUnreachable
From 192.168.41.48 icmp_seq = 6 Destination HostUnreachable
From 192.168.41.48 icmp_seq = 7 Destination HostUnreachable
Conclusion: Sometimes we can ping an address to determine whether the link between the local device and the target device is smooth, and check whether packets are dropped and the return time. The network conditions are roughly determined accordingly.
----------------------------- Subsequent self-Summary ----------------
Reprint a command written by someone else to continuously monitor the network status. I think the most important thing is our idea, not just to understand the command itself. If our ideas are not broad enough and we cannot use commands to survive, we can only learn from each other step by step. So after learning about the functions of the command itself, we also need to think about how to combine it with other commands to accomplish something that looks more awesome. In fact, this may be just a combination of one function and another. But this is the so-called idea.
# While :; do ping-c 1 172.17.39.htm | awk '/ttl =/' | sed "s/^/'date + % Y-% m-% d \ | % t '/"; sleep 1; done
The display effect is as follows:
Reference:
[Root @ PT_LINUX boot] # while :; do ping-c 1 172.17.39.htm | awk '/ttl =/' | sed "s/^/'date + % Y-% m-% d \ | % t '/"; sleep 1; done
| 15:24:40 64 bytes from 172.17.39.133: icmp_seq = 0 ttl = 128 time = 0.240 MS
| 15:24:41 64 bytes from 172.17.39.133: icmp_seq = 0 ttl = 128 time = 0.235 MS
| 15:24:42 64 bytes from 172.17.39.133: icmp_seq = 0 ttl = 128 time = 0.220 MS
| 15:24:43 64 bytes from 172.17.39.133: icmp_seq = 0 ttl = 128 time = 0.224 MS
| 15:24:45 64 bytes from 172.17.39.133: icmp_seq = 0 ttl = 128 time = 0.211 MS
| 15:24:46 64 bytes from 172.17.39.133: icmp_seq = 0 ttl = 128 time = 0.211 MS
| 15:24:47 64 bytes from 172.17.39.133: icmp_seq = 0 ttl = 128 time = 0.222 MS
| 15:24:48 64 bytes from 172.17.39.133: icmp_seq = 0 ttl = 128 time = 0.221 MS
| 15:24:49 64 bytes from 172.17.39.133: icmp_seq = 0 ttl = 128 time = 0.222 MS
In this way, a timestamp is added to determine the time point.