Linux under ping command to use the introduction

Source: Internet
Author: User
Tags lowercase

The principle and working mechanism of the ping command

ping commands are commonly used to detect network communication and impassability, also called time delay, the greater the value, the slower the ping (packetinternetgrope), the Internet Packet Explorer, used to test the amount of network connectivity program.

Ping sends an ICMP echo request message to the destination and reports whether it receives the desired ICMP echo response. It is used to check whether the network is smooth or network connection Speed command.

• Principle: Network machines have a unique IP address, we send a packet to the destination IP address, the other side will return a packet of the same size, according to the returned packets we can determine the existence of the target host, you can initially determine the target host's operating system.

Second, the work process of ping

• 1. Within the same network segment

Ping

• Host a---------------------> Host B

ICMP Request Package

• In native (host a) lookup ARP cache table lookup Host B IP with its corresponding Mac,

• No mapping of Host B's IP to its Mac is found, send an ARP request broadcast,

• Host B receives an ARP request package and replies to an ARP reply packet (which contains the native Mac).

• Host a<----------------------Host B

ICMP Answer Package

• 2, not the same network segment

• When you run ping host C (not on the same network segment) on host A, starting with the above, to how to get the MAC address, the IP protocol through the calculation found that C machine and itself is not in the same network segment, will be directly routed processing, that is, the route of the Mac, as to how to get the route of the Mac, Like the above, first in the ARP cache table to find, can not find the broadcast package. When the data frame is routed, the host C is contacted, and if it is not found, a timeout message is returned to host a.

Third, the use of ping command

The general format for the ping command is:

ping[-dfnqrrv][-c Send number][-i interval seconds][-i (capital I) network interface][-l (lowercase l) Front load][-p template style][-s packet size][-t survival value [host name or IP address]

Parameter description:

"-ccount" Specifies the number of loopback signal requests to be sent (or received), as indicated by the count variable.

The "-wtimeout" option only works with the-C option. It causes the ping to wait for the answer (after sending the last packet) with the longest timeout. Default timeout is 4000ms (4s)

"-D" uses the So_debug feature of the socket.

The "-d" option causes the icmpecho_reply packet to be dumped to the standard output in hexadecimal.

"-F" specifies the flood-ping option. -F Flag "dump" or output packets, choose a faster one when they return or 100 times per second. Each time a echo_request is sent, a period is printed and a backspace is printed for each echo_reply signal received. This provides a quick display of how much information packets are discarded. Only the root user can use this option.

Note: This will be very difficult on the web and must be used with care. The floodping command can only be used by the root user. The-f flag is incompatible with the-IWAIT flag.

'-n ' outputs only numeric values.

-R ignores the routing table and sends packets directly to the remote host. It is usually a matter of viewing the network interface on this computer.

"-R" records the routing process. The-R flag includes the Record_route option in the Echo_request packet and displays the routing buffer on the return packet.

The "-V" detail shows the execution of the instruction.

"-iwait" Waits for the time (in seconds) to be specified by the wait variable between each packet sending. The default value is to wait 1 seconds between packets sent per packet. This option is not compatible with the-f flag.

The "-IA.B.C.D" specifies that the interface marked by A.B.C.D will be used to broadcast outside IPV4 multicast. The-I flag is uppercase I.

"-lpreload" sends the preload variable to a specified number of packets as soon as possible before entering normal behavior mode (1 per second). The-l flag is lowercase l.

"-L" disables local loopback for multicast ping commands.

"-ppattern" specifies that the packets you send are populated with up to 16 "padding" bytes. This helps diagnose the problem of data dependency on the network. For example, "-pff" fills the packet with 1.

"-Q" does not display any information about the delivery packet, only the final result is displayed.

"-spacketsize" Specifies the number of bytes of data to send, with a preset value of 56, plus a 8-byte ICMP header, which is a total of 64ICMP data bytes.

"-SHOSTNAME/IPADDR" uses the IP address as the source address in the emitted ping packet. On hosts with more than one IP address, the-s flag can be used to force the source address to be any address other than the IP address of the interface to which the package is sent. If the IP address is not one of the following machine interface addresses, an error is returned and no forwarding is made.

"-ttll" Sets the size of the Live value TTL.

"-ointerface" points out that interface will be used to broadcast outside IPV6 multicast. Interfaces are specified in the form of "En0", "tr0", and so on.

Use examples:

(1) Specifies the number of loopback signal requests to be sent (or received):

#ping-c5172.17.0.254 (Request 5 times)

(2) Quick display of information packet discarded information:

#ping-f172.17.0.254

(3) Waiting for the time specified by the wait variable (in seconds) between each packet sending:

#ping-i2172.17.0.254 (interval 2s)

Four, ping test

• 1, ping native IP

• #ping172.17.0.11/127.0.0.1

• (test: #ifdowneth0之后再ping试试)

• If the ping does not pass, it indicates that there is a problem with the NIC installation or configuration. Disconnect the network cable and execute this command again, and if it appears normal, the IP address used by the computer may duplicate the IP address of another machine being used. If it is still not normal, it indicates that there is a problem with the installation or configuration of the local NIC, and you need to continue checking the related network configuration.

Ubuntu configuration file Location:

[ip]:/etc/network/interfaces

[dns]:/etc/resolv.conf

• 2, Ping gateway IP

• #ping172.17.0.254

• Normal Ping, indicating that the gateway router in the LAN is running normally. Conversely, it indicates a problem with the gateway.

• 3, ping remote IP

• #pingwww. baidu.com

• This command detects whether the computer can access the Internet properly.

How to use the ping command to test network connectivity?

• Connectivity problems are caused by a number of reasons, such as local configuration errors, remote host protocol failure, and of course, equipment and other failures. First let's talk about the steps to use the ping command.

• There are six steps to using ping to check connectivity:

·1. Use Ifconfig to observe whether the local network settings are correct;

2.ping127.0.0.1,127.0.0.1 loopback Address ping loopback address is to check the local TCP/IP protocol is not set up well;

3.ping The native IP address, this is to check whether the IP address of this machine is set incorrectly;

4.ping This network gateway or the IP address of this network, this is in order to check whether the hardware device has the problem, also can check this machine and local network connection is normal; (this step can be ignored in a non-LAN)

5.ping The local DNS address, in order to check that DNS is able to resolve IP correctly.

6.ping Remote IP address, this is mainly to check the local network or local and external connection is normal.

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.