Ping command details and examples of common Linux commands (view the network connection failure)

Source: Internet
Author: User
Tags sigint signal
The ping command in Linux is a commonly used 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 ICMP ECHO_REQUEST packet to the network host (send ICMP ECHO_REQUEST to network 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 in linux is slightly different from that in windows. in linux, the ping will not be automatically terminated. press ctrl + c to terminate the ping or specify the number of requests.

1. command format:

Ping [parameter] [host name or IP address]

2. command functions:

The ping command is used to determine the status of the network and external hosts, track and isolate hardware and software problems, and test, evaluate, and manage the network. If the host is running and connected to the Internet, it responds to the return signal. Each send-back request contains an Internet Protocol (IP) and an ICMP header followed by an tim structure, and enough bytes to fill in the information package. By default, a send-back request is sent continuously until the interrupt signal is received (Ctrl-C ).

The ping command sends a datagram every second and prints a line of output for each received response. 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.

3. 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.

-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.

-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.

4. example:

Instance 1: ping status

Command: ping 192.168.120.205

Output:

Copy codeThe code is as follows:
[Root @ localhost ~] # Ping 192.168.120.205
PING 192.168.120.205 (192.168.120.205) 56 (84) bytes of data.
64 bytes from 192.168.120.205: icmp_seq = 1 ttl = 64 time = 0.720 MS
64 bytes from 192.168.120.205: icmp_seq = 2 ttl = 64 time = 0.181 MS
64 bytes from 192.168.120.205: icmp_seq = 3 ttl = 64 time = 0.191 MS
64 bytes from 192.168.120.205: icmp_seq = 4 ttl = 64 time = 0.188 MS
64 bytes from 192.168.120.205: icmp_seq = 5 ttl = 64 time = 0.189 MS

--- 192.168.120.205 ping statistics ---
5 packets transmitted, 5 bytes ed, 0% packet loss, time 4000 ms
Rtt min/avg/max/mdev = 0.181/0.293/0.720/0.214 MS
[Root @ localhost ~] #

Instance 2: ping failure

Command: ping 192.168.120.202

Output:


Copy codeThe code is as follows:
[Root @ localhost ~] # Ping 192.168.120.202
PING 192.168.120.202 (192.168.120.202) 56 (84) bytes of data.
From 192.168.120.204 icmp_seq = 1 Destination Host Unreachable
From 192.168.120.204 icmp_seq = 2 Destination Host Unreachable
From 192.168.120.204 icmp_seq = 3 Destination Host Unreachable
From 192.168.120.204 icmp_seq = 4 Destination Host Unreachable
From 192.168.120.204 icmp_seq = 5 Destination Host Unreachable
From 192.168.120.204 icmp_seq = 6 Destination Host Unreachable

--- 192.168.120.202 ping statistics ---
8 packets transmitted, 0 received, + 6 errors, 100% packet loss, time 7005 ms
, Pipe 4
[Root @ localhost ~] #

Instance 3: ping the Gateway

Command: ping-B 192.168.120.1

Output:

Copy codeThe code is as follows:
[Root @ localhost ~] # Route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0*255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
Default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
[Root @ localhost ~] # Ping-B 192.168.120.1
PING 192.168.120.1 (192.168.120.1) 56 (84) bytes of data.
64 bytes from 192.168.120.1: icmp_seq = 1 ttl = 255 time = 2.02 MS
64 bytes from 192.168.120.1: icmp_seq = 2 ttl = 255 time = 1.83 MS
64 bytes from 192.168.120.1: icmp_seq = 3 ttl = 255 time = 1.68 MS
64 bytes from 192.168.120.1: icmp_seq = 4 ttl = 255 time = 1.98 MS
64 bytes from 192.168.120.1: icmp_seq = 5 ttl = 255 time = 1.88 MS

--- 192.168.120.1 ping statistics ---
5 packets transmitted, 5 bytes ed, 0% packet loss, time 4000 ms
Rtt min/avg/max/mdev = 1.682/1.880/2.020/0.129 MS

Instance 4: ping a specified number of times

Command: ping-c 10 192.168.120.206

Output:


Copy codeThe code is as follows:
[Root @ localhost ~] # Ping-c 10 192.168.120.206
PING 192.168.120.206 (192.168.120.206) 56 (84) bytes of data.
64 bytes from 192.168.120.206: icmp_seq = 1 ttl = 64 time = 1.25 MS
64 bytes from 192.168.120.206: icmp_seq = 2 ttl = 64 time = 0.260 MS
64 bytes from 192.168.120.206: icmp_seq = 3 ttl = 64 time = 0.242 MS
64 bytes from 192.168.120.206: icmp_seq = 4 ttl = 64 time = 0.271 MS
64 bytes from 192.168.120.206: icmp_seq = 5 ttl = 64 time = 0.274 MS
64 bytes from 192.168.120.206: icmp_seq = 6 ttl = 64 time = 0.295 MS
64 bytes from 192.168.120.206: icmp_seq = 7 ttl = 64 time = 0.269 MS
64 bytes from 192.168.120.206: icmp_seq = 8 ttl = 64 time = 0.270 MS
64 bytes from 192.168.120.206: icmp_seq = 9 ttl = 64 time = 0.253 MS
64 bytes from 192.168.120.206: icmp_seq = 10 ttl = 64 time = 0.289 MS

--- 192.168.120.206 ping statistics ---
10 packets transmitted, 10 bytes ed, 0% packet loss, time 9000 ms
Rtt min/avg/max/mdev = 0.242/0.367/1.251/0.295 MS
[Root @ localhost ~] #

Instance 5: ping with time interval and frequency limit

Command: ping-c 10-I 0.5 192.168.120.206

Output:

 
Copy codeThe code is as follows:
[Root @ localhost ~] # Ping-c 10-I 0.5 192.168.120.206
PING 192.168.120.206 (192.168.120.206) 56 (84) bytes of data.
64 bytes from 192.168.120.206: icmp_seq = 1 ttl = 64 time = 1.24 MS
64 bytes from 192.168.120.206: icmp_seq = 2 ttl = 64 time = 0.235 MS
64 bytes from 192.168.120.206: icmp_seq = 3 ttl = 64 time = 0.244 MS
64 bytes from 192.168.120.206: icmp_seq = 4 ttl = 64 time = 0.300 MS
64 bytes from 192.168.120.206: icmp_seq = 5 ttl = 64 time = 0.255 MS
64 bytes from 192.168.120.206: icmp_seq = 6 ttl = 64 time = 0.264 MS
64 bytes from 192.168.120.206: icmp_seq = 7 ttl = 64 time = 0.263 MS
64 bytes from 192.168.120.206: icmp_seq = 8 ttl = 64 time = 0.331 MS
64 bytes from 192.168.120.206: icmp_seq = 9 ttl = 64 time = 0.247 MS
64 bytes from 192.168.120.206: icmp_seq = 10 ttl = 64 time = 0.244 MS

--- 192.168.120.206 ping statistics ---
10 packets transmitted, 10 bytes ed, 0% packet loss, time 4499 ms
Rtt min/avg/max/mdev = 0.235/0.362/1.241/0.294 MS
[Root @ localhost ~] # Ping-c 10-I 0.01 192.168.120.206
PING 192.168.120.206 (192.168.120.206) 56 (84) bytes of data.
64 bytes from 192.168.120.206: icmp_seq = 1 ttl = 64 time = 0.244 MS
64 bytes from 192.168.120.206: icmp_seq = 2 ttl = 64 time = 0.195 MS
64 bytes from 192.168.120.206: icmp_seq = 3 ttl = 64 time = 0.219 MS
64 bytes from 192.168.120.206: icmp_seq = 4 ttl = 64 time = 0.204 MS
64 bytes from 192.168.120.206: icmp_seq = 5 ttl = 64 time = 3.56 MS
64 bytes from 192.168.120.206: icmp_seq = 6 ttl = 64 time = 1.93 MS
64 bytes from 192.168.120.206: icmp_seq = 7 ttl = 64 time = 0.193 MS
64 bytes from 192.168.120.206: icmp_seq = 8 ttl = 64 time = 0.193 MS
64 bytes from 192.168.120.206: icmp_seq = 9 ttl = 64 time = 0.202 MS
64 bytes from 192.168.120.206: icmp_seq = 10 ttl = 64 time = 0.211 MS

--- 192.168.120.206 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 90 ms
Rtt min/avg/max/mdev = 0.193/0.716/3.564/1.080 MS
[Root @ localhost ~] #

Instance 6: ping the website on the public network through the domain name

Command: ping-c 5 www.58.com

Output:


Copy codeThe code is as follows:
Peida-VirtualBox ~ # Ping-c 5 www.58.com
PING www.58.com (211.151.111.30) 56 (84) bytes of data.
64 bytes from 211.151.111.30: icmp_req = 1 ttl = 49 time = 14.7 MS
64 bytes from 211.151.111.30: icmp_req = 2 ttl = 49 time = 16.4 MS
64 bytes from 211.151.111.30: icmp_req = 3 ttl = 49 time = 15.2 MS
64 bytes from 211.151.111.30: icmp_req = 4 ttl = 49 time = 14.6 MS
64 bytes from 211.151.111.30: icmp_req = 5 ttl = 49 time = 19.9 MS

--- Www.58.com ping statistics ---
5 packets transmitted, 5 bytes ed, 0% packet loss, time 20101 ms
Rtt min/avg/max/mdev = 14.618/16.192/19.917/1.965 MS
Peida-VirtualBox ~ #

Instance 7: use multiple parameters

Command: ping-I 3-s 1024-t 255 192.168.120.206

Output:

Copy codeThe code is as follows:
[Root @ localhost ~] # Ping-I 3-s 1024-t 255 192.168.120.206
PING 192.168.120.206 (192.168.120.206) 1024 (1052) bytes of data.
1032 bytes from 192.168.120.206: icmp_seq = 1 ttl = 64 time = 1.99 MS
1032 bytes from 192.168.120.206: icmp_seq = 2 ttl = 64 time = 0.694 MS
1032 bytes from 192.168.120.206: icmp_seq = 3 ttl = 64 time = 0.300 MS
1032 bytes from 192.168.120.206: icmp_seq = 4 ttl = 64 time = 0.481 MS
1032 bytes from 192.168.120.206: icmp_seq = 5 ttl = 64 time = 0.415 MS
1032 bytes from 192.168.120.206: icmp_seq = 6 ttl = 64 time = 0.600 MS
1032 bytes from 192.168.120.206: icmp_seq = 7 ttl = 64 time = 0.411 MS
1032 bytes from 192.168.120.206: icmp_seq = 8 ttl = 64 time = 0.281 MS
1032 bytes from 192.168.120.206: icmp_seq = 9 ttl = 64 time = 0.318 MS
1032 bytes from 192.168.120.206: icmp_seq = 10 ttl = 64 time = 0.362 MS
1032 bytes from 192.168.120.206: icmp_seq = 11 ttl = 64 time = 0.408 MS
1032 bytes from 192.168.120.206: icmp_seq = 12 ttl = 64 time = 0.445 MS
1032 bytes from 192.168.120.206: icmp_seq = 13 ttl = 64 time = 0.397 MS
1032 bytes from 192.168.120.206: icmp_seq = 14 ttl = 64 time = 0.406 MS
1032 bytes from 192.168.120.206: icmp_seq = 15 ttl = 64 time = 0.458 MS

--- 192.168.120.206 ping statistics ---
15 packets transmitted, 15 bytes ed, 0% packet loss, time 41999 ms
Rtt min/avg/max/mdev = 0.281/0.531/1.993/0.404 MS
[Root @ localhost ~] #


Note:-I 3 sets the sending package size to 1024-t and the TTL value to 255 for 3 seconds-s.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.