Use the Ping command in CentOS

Source: Internet
Author: User

I. ping Command principle and working mechanism

• The ping command is generally used to detect network connectivity and network latency. The larger the value is, the slower the PING (PacketInternet Grope) and the Internet package Explorer are used to test the number of network connections.


• Ping sends an ICMP echo request message to the destination and reports whether the desired ICMP echo response is received. It is a command used to check whether the network is smooth or the network connection speed.


• Principle: All machines on the network have a unique IP address. When we send a packet to the target IP address, the other party will return a packet of the same size, based on the returned data packets, we can determine the existence of the target host and determine the operating system of the target host.


2. ping Workflow

• 1. Within the same network segment

• Ping

• Host A ---------------------> host B

• ICMP request packet

• Find the ARP cache table on the host (host A) to find the IP address of host B and its MAC address,

• If the ing between host B's IP address and MAC address is not found, an arp request broadcast is sent,

• Host B replies to an arp response packet (including the local MAC) After receiving the arp request packet ),

• Host A <---------------------- host B

• ICMP response packet


• 2. Not in the same network segment

• Run "ping host C (not in the same CIDR Block)" on host A to get the MAC address, through computing, the IP protocol finds that the C host is not in the same network segment as itself, and the IP address is directly transferred to the route, that is, the MAC address of the route is obtained. As for how to obtain the MAC address of the route, first, find the ARP cache table and broadcast the packet if it cannot be found. After the route obtains the data frame, it will contact host C. If it cannot be found, it will return A timeout message to host.

Iii. ping command usage


• The ping command is generally in the following format:


• Ping [-dfnqrRv] [-c message frequency] [-I interval seconds] [-I (uppercase I) network interface] [-l (lowercase L) pre-load] [-p template style] [-s packet size] [-t survival value] [host name or IP address]


Parameter description:



[-C count] specifies the number of sending signal requests to be sent (or received), which is indicated by the Count variable.




[-W timeout] this option only works with the-c option. It enables the ping command to wait for a response with the longest timeout (after the last packet is sent ). Default timeout 4000 ms (4S)




[-D] Use SO_DEBUG function of Socket.




[-D] This option causes the ICMP ECHO_REPLY information package to be dumped to the standard hexadecimal output.




[-F] specifies the flood-ping option. -F indicates "dumping" or outputting information packages. When they return or 100 times per second, select a faster one. Each time an ECHO_REQUEST is sent, a full stop is printed, and each time an ECHO_REPLY signal is received, a backspace is printed. This provides a quick display of discarded information. Only root users can use this option.




Note: This will be very difficult on the network and must be used with caution. The Flood ping command can be used only by the root user. The-f flag is incompatible with the-I Wait flag.




-N: only the numeric value is output.




-R: Ignore the route table and directly send data packets to the remote host. Check whether the network interface of the local machine is faulty.




[-R] records the routing process. The-R flag includes the RECORD_ROUTE option in the ECHO_REQUEST information package and displays the route buffer on the returned information package.




[-V] displays the execution process of commands in detail.




-I wait: the waiting time (in seconds) specified by the Wait variable between sending of each information package ). The default value is to wait 1 second for each packet to be sent. This option is not compatible with the-f flag.




[-Ia. B. c. d] the interface specified by a. B .c.d will be used for IPv4 multicast. -The I sign is an uppercase I.




-LPreload: sends the specified number of information packages of the Preload variable as soon as possible before entering the normal behavior mode (1 per second. -L indicates L in lower case.




[-L] disable local delivery for multicast ping command.




[-PPattern] indicates that up to 16 "fill" bytes are used to fill the information package you sent. This is conducive to the diagnosis of Network-dependent data issues. For example, "-p ff" fills the information package with 1.




[-Q] Only displays the final result without displaying any information about the transfer packets.




[-Spacketsize] 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.




-Shostname/IP addr: Use the IP address as the source address in the sent ping packet. On a host with more than one IP address, you can use the-S flag to force the source address to any address other than the IP address of the interface sent by the software package on it. If the IP address is not one of the following machine interface addresses, the system returns an error and does not send any messages.




[-Ttll] sets the TTL value of the survival value.




[-Ointerface] indicates that the interface will be used for IPv6 multi-point broadcast. The interface is specified in the form of "en0" and "tr0.




Example:




(1) Number of send signal requests to be sent (or received:




# Ping-c 5 172.17.0.254 (5 requests)




(2) Rapid display of discarded information:




# Ping-f 172.17.0.254




(3) Wait for the time specified by the Wait variable (in seconds) between sending of each information package ):




# Ping-I 2 172.17.0.254 (interval: 2 s)




4. ping Test




• 1. ping the local IP Address




• # Ping 172.17.0.11/127.0.0.1




• (Test: # ping after ifdown eth0)




• If the ping fails, the NIC installation or configuration is incorrect. Disconnect the network cable and run this command again. If the command is displayed normally, the IP address used by the local machine may be the same as the IP address of another machine in use. If it is still abnormal, it indicates that the local Nic is installed or the configuration is incorrect. You must continue to check the related network configurations.




• Configuration File Location in Ubuntu:




• [IP]:/etc/network/interfaces




• [DNS]:/etc/resolv. conf




• 2. ping the gateway IP Address




• # Ping 172.17.0.254


• Normal ping indicates that the Gateway Router in the LAN is running normally. Otherwise, the gateway is faulty.


• 3. ping the remote IP Address


• # Ping www.baidu.com


• This command can detect whether the local machine can normally access the Internet.


5. How can I use the Ping command to test network connectivity?


• Connectivity problems are caused by many reasons, such as local configuration errors, remote host protocol failures, and equipment faults. First, let's talk about how to use the Ping command.



• There are six steps to use Ping to check Connectivity:


• 1. Use ifconfig to check whether the local network settings are correct;


• 2. Ping 127.0.0.1 and 127.0.0.1 to check whether the local TCP/IP protocol is set;


• 3. Ping the IP address of the Local Machine to check whether the IP address of the local machine is set incorrectly;


• 4. ping the gateway or IP address of this network to check whether the hardware device is faulty or whether the connection between the local machine and the local network is normal. (This step can be ignored in non-LAN networks)


• 5. Ping the local DNS address to check whether the DNS can correctly resolve the IP address.



• 6. Ping the remote IP address, which mainly checks whether the connection between this network or the local machine and the external machine 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.