Ping command usage in linux

Source: Internet
Author: User
The Ping command sends an Internet Control Message Protocol (ICMP) echo request message to verify the IP-level connection with another TCP/IP computer. it is an important command, today, I will explain how to use the ping command in linux.

• The ping command is generally used to detect network connectivity and network latency. the larger the value is, the slower the PING (PacketInternetGrope) 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:

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

[-Wtimeout] 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 ICMPECHO_REPLY information package to dump to the standard output hexadecimal format.

[-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 Floodping command can be used only by the root user. -F flag is incompatible with-iWait 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.

[-Iwait] specifies the time (in seconds) to Wait for each packet to be sent by the Wait variable ). 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, "-pff" 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/IPaddr: 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, an error is returned and no sending is performed.

[-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-c5172.17.0.254 (requests 5 times)

(2) rapid display of discarded information:

# Ping-f172.17.0.254

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

# Ping-i2172.17.0.254 (interval 2 s)

4. ping test

• 1. ping the local IP address

• # Ping172.17.0.11/127.0.0.1

• (Test: # ping ifdowneth0 and try again)

• 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

• # Ping172.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

• # Pingwww.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 the Ping127.0.0.1, 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.

Link: http://blog.csdn.net/star_xiong/article/details/17320473

If you like this article, please share it with your friends. thank you!

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.