Linux ping command use introduction

  
                  

First, the principle and working mechanism of the ping command

• The ping command is generally used to detect network access and nowhere, also called delay, the greater the value, the slower the speed PING (PacketInternetGrope), the Internet Package explorer, a program for testing network connections.

•ping sends an ICMP echo request message to the destination and reports whether the desired ICMP echo response was received. It is a command to check if the network is fluent or the speed of the network connection.

• Principle: The machines on the network have uniquely determined IP addresses. We send a packet to the destination IP address, and the other party will return a packet of the same size. According to the returned packet, we can Determine the existence of the target host, you can initially determine the operating system of the target host.

Second, ping workflow

• 1, in the same network segment

• ping

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

•ICMP Request Package

•Find ARP Cache on Local (Host A) The table looks up the IP of host B and its corresponding MAC,

• does not find the mapping relationship between the IP of host B and its MAC, then sends an arp request broadcast,

• host B receives After arp requests the packet, it replies with an arp response packet (which contains the local MAC),

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

• ICMP response packet

•2, not on the same network segment

•Run on host A<quo;ping host C (not on the same network After the segment), the same as above, when the MAC address is obtained, the IP protocol calculates that the C machine is not in the same network segment as itself, and will directly hand over the route, that is, the MAC of the route is taken over. As for how to get the MAC of the route, as in the above, first find it in the ARP cache table, and can't find the broadcast packet. After the route gets the data frame, it contacts the host C. If it is not found, it returns a timeout message to the host A.

Third, the use of ping command

• The general format of the ping command is:

• ping[-dfnqrRv][-c send times][-i interval Seconds][-I (uppercase i) web interface][-l (lowercase L) preload][-p template style][-s packet size][-t survivor value][hostname or IP address ]

Parameter Description:

[-ccount] Specifies the number of echo signal requests to be sent (or received), as indicated by the Count variable.

[-wtimeout] This option works only with the -c option. It causes the ping command to wait for a response with the longest timeout (after sending the last packet). The default timeout is 4000ms (4s)

[-d] Use the SO_DEBUG function of Socket.

[-D] This option causes a hexadecimal dump of the ICMPECHO_REPLY packet to the standard output.

[-f] Specify the flood-ping option. -f flag "dump" or output packets, when they come back or 100 times per second, choose the faster one. Each time ECHO_REQUEST is sent, a period is printed, and each time an ECHO_REPLY signal is received, a backspace is printed. This provides a quick display of how many packets are discarded. This option is only available to root users.

Note: This will be very difficult on the network and must be used with care. The Floodping command is only available to the root user. The -f flag is not compatible with the -iWait flag.

[-n] Only output values.

-r] Ignore the routing table and send the packet directly to the remote host. Usually it is a problem to check the network interface of this machine.

[-R] Record the routing process. The -R flag includes the RECORD_ROUTE option in the ECHO_REQUEST packet and shows the route buffer on the return packet.

[-v] Detailed display of the execution of the instruction.

[-iwait] Waits for the time (in seconds) specified by the Wait variable between each packet transmission. The default is to wait 1 second between each packet transmission. This option is not compatible with the -f flag.

[-Ia.b.c.d] Specifies that the interface indicated by a.b.c.d will be used for outgoing IPv4 multicast. The -I flag is an uppercase i.

[-lPreload] Sends the specified number of packets of the Preload variable as soon as possible before entering the normal behavior mode (1 per second). The -l flag is lowercase L.

[-L] Disable local loopback for the multicast ping command.

[-pPattern] specifies to fill up the packets you send with up to 16 "fill" bytes. This is useful for diagnosing data-dependent problems on the network. For example, “-pff” all fill the packet with 1.

[-q] does not display any information about the transmitted packet, only the last result.

[-spacketsize] specifies the number of bytes of data to be sent. The default value is 56, plus an 8-byte ICMP header, which is a total of 64 ICMP data bytes.

[-Shostname/IPaddr] Use the IP address as the source address in the outgoing ping packet. On a host with more than one IP address, the -S flag can be used to force the source address to be anything other than the IP address of the interface on which the package was sent. If the IP address is not one of the following machine interface addresses, an error is returned and no transmission is made.

[-ttll] Set the size of the surviving value TTL.

[-ointerface] indicates that the interface will be used for outgoing IPv6 multicast. The interface is specified in the form of “en0”,“tr0”.

Example of use:

(1) Specify the number of echo signal requests to be sent (or received):

#ping-c5172.17.0.254 (Request 5 times)

(2) Quick display of information discarded by the packet:

#ping-f172.17.0.254

(3) In each packet The time (seconds) to wait between transmissions to be specified by the Wait variable:

#ping-i2172.17.0.254 (interval 2s)

IV, ping test

&bull ; 1, ping the local IP

• #ping172.17.0.11/127.0.0.1

• (test: #ifdowneth0 and then ping try)

• If the ping fails, it indicates that there is a problem with the NIC installation or configuration. Disconnect the network cable and execute this command again. If the display is normal, the IP address used by this machine may be duplicated with the IP address of another machine being used. If it is still abnormal, it indicates that there is a problem with the installation or configuration of the local network card. You need to continue to check the related network configuration.

• Ubuntu configuration file location:

•[IP]:/etc/network/interfaces

•[DNS]:/etc/resolv.conf

•2, ping gateway IP

•#ping172.17.0.254

• can be pinged normally, indicating that the gateway router in the LAN is running normally . Otherwise, there is a problem with the gateway.

•3, ping remote IP

•#pingwww.baidu.com

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

V. How to use the Ping command to test network connectivity?

• Connectivity problems are caused by many reasons, such as local configuration errors, remote host protocol failures, etc., of course, including A malfunction caused by equipment, etc. First let's talk about the steps to use the Ping command.

• There are six steps to checking connectivity using Ping:

•1. Use ifconfig to observe if the local network settings are correct;

•2.Ping127.0.0 .1, 127.0.0.1 loopback address Ping loopback address is to check whether the local TCP/IP protocol is set;

•3.Ping the local IP address, this is to check the IP address of the machine. Whether the setting is incorrect;

•4.Ping the local network gateway or the IP address of the local network, this is to check whether the hardware device has a problem, you can also check whether the connection between the local network and the local network is normal; This step can be ignored in non-LAN.

•5.Ping the local DNS address, this is to check if the DNS can correctly resolve the IP.

•6.Ping remote IP address, this is mainly to check whether the connection between the local network or the local and external is normal.

Copyright © Windows knowledge All Rights Reserved