Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of the Linux basic command ping

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "the usage of the Linux basic command ping". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the usage of the Linux basic command ping".

Ping

The ping instruction can send an ICMP request to the destination address, and if the network is functioning properly, the target host will give a response. Ping uses the ICMP protocol to force ECHO_REQUEST messages to be sent to the target host and to obtain ICMP ECHO_RESPONSE from the host or gateway. The ECHO_REQUESTt Datagram ('pings') has an IP and ICMP header, followed by a timeval structure, followed by any number of "pad" bytes used to populate the packet.

The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

Ping [options] destination

2. List of options

Option

Description

-a

Audible ping

A

The adaptive flat packet interval adapts to the round trip time, so no more than one (or more, if preloaded) unanswered probes exist in the network. For non-superusers, the minimum interval is 200 milliseconds. On networks with low RTT, this mode is essentially equivalent to flood mode.

-b

Allow ping broadcast addresses

-B

Ping is not allowed to change the source address of the probe. When ping starts, the address is bound to the selected address.

-c count

Specify the number of times for ping

-d

Set the SO_DEBUG option on the socket you are using. In fact, the linux kernel does not use this socket option.

-F flowlabel

Assign and set a 20-bit flow label on the echo request packet. (only Ping 6). If the value is zero, the kernel assigns a random flow label.

-f

Limit detection, send the next request without waiting for a reply, and only super admins can use it

-I interval

Specify the time interval to send

-Iinterfaceaddress

Sets the source address to the specified interface address. Parameters can be numeric IP addresses or device names. This option is required when selecting an ipv 6 link-local address.

-l preload

If preloaded preload,ping is specified, many packets are sent that are not waiting for a reply. Only superusers can select preloads of more than 3

-L

Suppresses the echo of multicast packets. This flag applies only if the ping destination is a multicast address.

-n

Display digitally

-p pattern

You can specify up to 16 "PAD" bytes to populate the packet you send. This is useful for diagnosing data-related problems in the network.

-Q tos

The quality of the bits associated with the service is set in the ICMP Datagram. TOS can be a decimal number or a hexadecimal number. Traditionally (RFC 1349), they were interpreted as 0 for retention (currently redefined as congestion control), 1-4 for type of service, and 5-7 for priority. The possible settings for the service type are: lowest cost: 0x02, reliability: 0x04, throughput: 0x08, low latency: 0x10. You cannot set multiple TOS bits at the same time. Possible settings for special priorities range from priority (0x20) to net control (0xe0).

-Q

Do not display the execution process

-r

Ignore the normal routing table

-R

Record rout

-spacketsize

Specify the size of the packet

-S sndbuf

Sets the socket send buffer sndbuf. If not specified, select it to buffer no more than one packet

-t ttl

Specify the lifetime of the packet TTL

-Ttimestampoption

Set special ip timestamp options. Can be tsonly (only timestamps), tsandaddr (timestamps and addresses) or tsprespec host1 [host2 [host3 [host4] (timestamp prespecified hops)

-M hint

Select a path MTU discovery policy, which can be do (fragmentation prohibited, even local), want (pmtu is found locally when the packet size is large), don't (no DF flag is set)

-U

Print full user-to-user delay

-wdeadline

Specify a timeout (in seconds) before ping exits, regardless of how many packets are sent or received.

-Wtimeout

The time, in seconds, to wait for a response. This option only affects the timeout of any response, otherwise ping will wait for two RTT

-v

Show detailed execution process

-V

Show version

3. ICMP message

The IP header with no option is 20 bytes. The ICMP echo_Request packet contains another 8-byte ICMP header, followed by any amount of data. When a packet size is given, this indicates the size of this extra block (the default is 56). Therefore, the amount of data received in an IP packet of type ICMP ECHO_REPLY is always 8 bytes more than the requested data space (ICMP header).

If the data space is at least the size of the structure timeval, Timeval ping uses the starting byte of that space to contain the timestamp it uses when calculating round-trip time. If the data space is short, no round trip time is provided.

4. Duplicate and corrupted packets

Ping will report duplicate and corrupted packets. Duplicate packets should not occur and seem to be caused by inappropriate link-level retransmissions. Repetition can occur in many cases, and little (if any) is a good sign, although low levels of repetition may not always cause panic. Corrupted packets are clearly a serious cause of alerts and often indicate a hardware failure in the path of ping packets (in the network or host).

5. Try different data modes

The (internal) network layer should not treat packets differently according to the data contained in the data section. Unfortunately, data-dependent problems have been known to sneak into the network and have not been discovered for a long time. In many cases, the specific pattern that can cause problems is something that does not have enough "transformations", such as all 1s or all zeros, or a pattern on the edge, such as almost all zeros. Simply specifying a data pattern of all zeros on the command line (for example) is not necessarily sufficient, because the pattern of interest is at the data link level, and the relationship between what you type and what the controller sends can be complex.

This means that if you have a data dependency problem, you may need to do a lot of testing to find it. If you are lucky, you may try to find a file that either cannot be sent over your network or takes longer to transfer than other files of similar length. You can then check to see if the file has a duplicate pattern, which you can test with the-p option of ping.

6 、 TTL

The TTL value of an IP packet represents the maximum number of IP routers that a packet can pass through before being discarded. In current practice, you can expect each router in Internet to reduce the TTL field by one. The TCP/IP specification states that the TTL field of TCP packets should be set to 60, but many systems use smaller values (4.3BSD uses 30 ~ 4.2 and 15). The maximum possible value for this field is 255, and most Unix systems set the TTL field of ICMP ECHO_REQUEST packets to 255. This is why you will find that you can "ping" some hosts, but you cannot reach them through telnet (1) or ftp (1).

In normal operation, the ping prints the ttl value from the packets it receives. When the remote system receives an ping packet, it can use the ttl field in the response to perform one of the following three tasks.

1) Don't change it; this is what the Berkeley Unix system did before 4.3BSDTahoe was released. In this case, the TTL value in the received packet will be 255 minus the number of routers in the round-trip path.

2) set it to 255; this is what the current BerkeleyUnix system does. In this case, the TTL value in the received packet will be 255 minus the number of routers in the path from the remote system to the ping host.

3) set it to a different value. Some machines use the same values for ICMP packets as they use for TCP packets, such as 30 or 60. Others may use completely wild values.

7. Examples

1) ping broadcast address

[root@localhost ~] # ping 192.168.1.255

Do you want to ping broadcast? Then-b

[root@localhost ~] # ping-b 192.168.1.255 / / ping broadcast address only using the-b option

WARNING: pinging broadcast address

PING 192.168.1.255 (192.168.1.255) 56 (84) bytes of data.

64 bytes from 192.168.1.8: icmp_seq=1 ttl=64 time=0.219 ms

64 bytes from 192.168.1.8: icmp_seq=2 ttl=64 time=0.282 ms

64 bytes from 192.168.1.8: icmp_seq=3 ttl=64 time=0.215 ms

64 bytes from 192.168.1.8: icmp_seq=4 ttl=64 time=0.268 ms

^ C

-192.168.1.255 ping statistics

4 packets transmitted, 4 received, 0% packet loss, time 3684ms

Rtt min/avg/max/mdev = 0.215 ms, 0.246, 0.282, 0.029

2) Test whether the destination address is unblocked

[root@localhost ~] # ping-c 4 192.168.1.8 / / specify the number of times packets are sent

PING 192.168.1.8 (192.168.1.8) 56 (84) bytes of data.

64 bytes from 192.168.1.8: icmp_seq=1 ttl=64 time=0.427 ms

64 bytes from 192.168.1.8: icmp_seq=2 ttl=64 time=0.196 ms

64 bytes from 192.168.1.8: icmp_seq=3 ttl=64 time=0.220 ms

64 bytes from 192.168.1.8: icmp_seq=4 ttl=64 time=0.329 ms

-192.168.1.8 ping statistics-

4 packets transmitted, 4 received, 0% packet loss, time 3002ms

Rtt min/avg/max/mdev = 0.196 ms 0.293 ms

Thank you for your reading, the above is the content of "the usage of the Linux basic command ping". After the study of this article, I believe you have a deeper understanding of the usage of the Linux basic command ping, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report