Linux Learning Note---command ping

Source: Internet
Author: User
Tags sigint signal

  

The ping command of a Linux system is a common network command, which is often used to test connectivity with the target host, and we often say "ping a machine, see if it is open," or "you ping the gateway address 192.168.1.1" Before you open the page. It sends an ICMP echo_request packet to the network host (send ICMP echo_request to net hosts) and displays the response so that we can determine whether the target host is reachable based on the information it outputs (but this is not absolute). Some servers are designed to prevent pings from being detected by a firewall, or to disable ping in the kernel parameters, so it is not possible to ping to determine if the host is still open.

There is a slight difference between the ping under Linux and the ping under Windows, the Linux ping does not automatically terminate, you need to press CTRL + C to terminate, or use the parameter-C to specify the number of responses required to complete.

1. Command format:

ping [parameters] [host name or IP address]

2. Command function:

The ping command is used to determine the status of networks and external hosts, to track and isolate hardware and software issues, and to test, evaluate, and manage networks. If the host is running and connected to the network, it responds to the loopback signal. Each echo request consists of an Internet Protocol (IP) and an ICMP header, followed by a Tim structure, and sufficient bytes to fill in the packet. The default is to send the loopback signal request continuously until the interrupt signal (CTRL-C) is received.

The ping command sends a datagram every second and prints a line of output for each response received. The ping command calculates the statistics of the signal round-trip time and (information) packet loss, and displays a brief summary after completion. The ping command ends when the program times out or when a SIGINT signal is received. The host parameter is either a valid host name or an Internet address.

3. Command parameters:

-D uses the So_debug function of the socket.

-F limit detection. Send a large and fast network packet to a machine to see its response.

-n outputs only numeric values.

-Q does not display information for any transmittal packets, only the final result is displayed.

-R ignores the normal routing Table and sends the packet directly to the remote host. This is usually a matter of looking at the network interface of this computer.

-R records the routing process.

-V shows the execution of the instruction in detail.

Number of <p>-c: Stop after sending a specified number of packages.

-I seconds: set interval a few seconds to send a network packet to a machine, the default value is one second to send once.

-I network interface: sends out packets using the specified network interface.

-L Pre-load: Sets the packets that are emitted before the requested information is sent.

-P Template style: Sets the template style that fills the packet.

-S Bytes: Specifies the number of bytes of data sent, the default value is 56, plus 8 bytes of ICMP header, which is a total of 64ICMP data bytes.

-T Survival value: Sets the size of the Live value TTL.

4. Usage examples:

Example of a 1:ping case

Command:

Ping 192.168.120.205

Output:

[[email protected] ~]# Ping 192.168.120.205
PING 192.168.120.205 (192.168.120.205) bytes of data.
Bytes from 192.168.120.205:icmp_seq=1 ttl=64 time=0.720 ms
Bytes from 192.168.120.205:icmp_seq=2 ttl=64 time=0.181 ms
Bytes from 192.168.120.205:icmp_seq=3 ttl=64 time=0.191 ms
Bytes from 192.168.120.205:icmp_seq=4 ttl=64 time=0.188 ms
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 received, 0% packet loss, time 4000ms
RTT Min/avg/max/mdev = 0.181/0.293/0.720/0.214 ms
[Email protected] ~]#

Description

Instances where the 2:ping is not

Command:

Ping 192.168.120.202

Output:

[[email protected] ~]# Ping 192.168.120.202
PING 192.168.120.202 (192.168.120.202) 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 7005ms
, Pipe 4
[Email protected] ~]#

Description

Instance 3:ping Gateway

Command:

Ping-b 192.168.120.1

Output:

[Email protected] ~]# 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
[Email protected] ~]# Ping-b 192.168.120.1
PING 192.168.120.1 (192.168.120.1) bytes of data.
Bytes from 192.168.120.1:icmp_seq=1 ttl=255 time=2.02 ms
Bytes from 192.168.120.1:icmp_seq=2 ttl=255 time=1.83 ms
Bytes from 192.168.120.1:icmp_seq=3 ttl=255 time=1.68 ms
Bytes from 192.168.120.1:icmp_seq=4 ttl=255 time=1.98 ms
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 received, 0% packet loss, time 4000ms
RTT Min/avg/max/mdev = 1.682/1.880/2.020/0.129 ms

Description

Instance 4:ping specified number of times

Command:

Ping-c 10 192.168.120.206

Output:

[Email protected] ~]# ping-c 10 192.168.120.206
PING 192.168.120.206 (192.168.120.206) bytes of data.
Bytes from 192.168.120.206:icmp_seq=1 ttl=64 time=1.25 ms
Bytes from 192.168.120.206:icmp_seq=2 ttl=64 time=0.260 ms
Bytes from 192.168.120.206:icmp_seq=3 ttl=64 time=0.242 ms
Bytes from 192.168.120.206:icmp_seq=4 ttl=64 time=0.271 ms
Bytes from 192.168.120.206:icmp_seq=5 ttl=64 time=0.274 ms
Bytes from 192.168.120.206:icmp_seq=6 ttl=64 time=0.295 ms
Bytes from 192.168.120.206:icmp_seq=7 ttl=64 time=0.269 ms
Bytes from 192.168.120.206:icmp_seq=8 ttl=64 time=0.270 ms
Bytes from 192.168.120.206:icmp_seq=9 ttl=64 time=0.253 ms
Bytes from 192.168.120.206:icmp_seq=10 ttl=64 time=0.289 ms

---192.168.120.206 ping statistics---
Packets transmitted, received, 0% packet loss, time 9000ms
RTT Min/avg/max/mdev = 0.242/0.367/1.251/0.295 ms
[Email protected] ~]#

Description

Example 5: Ping with time interval and number of times limit

Command:

Ping-c 10-i 0.5 192.168.120.206

Output:

[Email protected] ~]# ping-c 10-i 0.5 192.168.120.206
PING 192.168.120.206 (192.168.120.206) bytes of data.
Bytes from 192.168.120.206:icmp_seq=1 ttl=64 time=1.24 ms
Bytes from 192.168.120.206:icmp_seq=2 ttl=64 time=0.235 ms
Bytes from 192.168.120.206:icmp_seq=3 ttl=64 time=0.244 ms
Bytes from 192.168.120.206:icmp_seq=4 ttl=64 time=0.300 ms
Bytes from 192.168.120.206:icmp_seq=5 ttl=64 time=0.255 ms
Bytes from 192.168.120.206:icmp_seq=6 ttl=64 time=0.264 ms
Bytes from 192.168.120.206:icmp_seq=7 ttl=64 time=0.263 ms
Bytes from 192.168.120.206:icmp_seq=8 ttl=64 time=0.331 ms
Bytes from 192.168.120.206:icmp_seq=9 ttl=64 time=0.247 ms
Bytes from 192.168.120.206:icmp_seq=10 ttl=64 time=0.244 ms

---192.168.120.206 ping statistics---
Packets transmitted, received, 0% packet loss, time 4499ms
RTT Min/avg/max/mdev = 0.235/0.362/1.241/0.294 ms
[Email protected] ~]# ping-c 10-i 0.01 192.168.120.206
PING 192.168.120.206 (192.168.120.206) bytes of data.
Bytes from 192.168.120.206:icmp_seq=1 ttl=64 time=0.244 ms
Bytes from 192.168.120.206:icmp_seq=2 ttl=64 time=0.195 ms
Bytes from 192.168.120.206:icmp_seq=3 ttl=64 time=0.219 ms
Bytes from 192.168.120.206:icmp_seq=4 ttl=64 time=0.204 ms
Bytes from 192.168.120.206:icmp_seq=5 ttl=64 time=3.56 ms
Bytes from 192.168.120.206:icmp_seq=6 ttl=64 time=1.93 ms
Bytes from 192.168.120.206:icmp_seq=7 ttl=64 time=0.193 ms
Bytes from 192.168.120.206:icmp_seq=8 ttl=64 time=0.193 ms
Bytes from 192.168.120.206:icmp_seq=9 ttl=64 time=0.202 ms
Bytes from 192.168.120.206:icmp_seq=10 ttl=64 time=0.211 ms

---192.168.120.206 ping statistics---
Packets transmitted, received, 0% packet loss, time 90ms
RTT Min/avg/max/mdev = 0.193/0.716/3.564/1.080 ms
[Email protected] ~]#

Description

Example 6: Ping the site on the public website via the domain name

Command:

Ping-c 5 www.58.com

Output:

Peida-virtualbox ~ # ping-c 5 www.58.com
PING www.58.com (211.151.111.30) bytes of data.
Bytes from 211.151.111.30:icmp_req=1 ttl=49 time=14.7 ms
Bytes from 211.151.111.30:icmp_req=2 ttl=49 time=16.4 ms
Bytes from 211.151.111.30:icmp_req=3 ttl=49 time=15.2 ms
Bytes from 211.151.111.30:icmp_req=4 ttl=49 time=14.6 ms
Bytes from 211.151.111.30:icmp_req=5 ttl=49 time=19.9 ms

---www.58.com ping statistics---
5 Packets transmitted, 5 received, 0% packet loss, time 20101ms
RTT Min/avg/max/mdev = 14.618/16.192/19.917/1.965 ms
Peida-virtualbox ~ #

Description

Example 7: Multi-parameter use

Command:

Ping-i 3-s 1024-t 255 192.168.120.206

Output:

[Email protected] ~]# ping-i 3-s 1024-t 255 192.168.120.206
PING 192.168.120.206 (192.168.120.206) 1024x768 (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---
Packets transmitted, received, 0% packet loss, time 41999ms
RTT Min/avg/max/mdev = 0.281/0.531/1.993/0.404 ms
[Email protected] ~]#

Description

-I 3 Send period is 3 seconds-s set send packet size to 1024-t set TTL value to 255

I use the ping command:

Ping is mainly used to check the connectivity between the two machines.

Ping IP

Ping Domain name

Ping-c 10-i 3 IP: ICMP packets are sent every three seconds, 10 times.

Ping-r ip:ping The routing information of a certain IP,

Linux Learning Note---command ping

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.