Tcpip (7) Ping

Source: Internet
Author: User
Tags sigint signal time 0

Ping through ICMP echo request and response

Some good examples of Ping: From http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-command-examples/

Ping Example 1. Increase or decrease the time interval between packets

By default Ping waits for 1 second before sending the next packet. You can increase or decrease this using option-I as shown below.

Increase ping time interval

Example: Wait for 5 seconds before sending the next packet.

 
$ Ping-I 5 IP
Decrease ping time interval

Example: Wait 0.1 seconds before sending the next packet.

 
# Ping-I 0.1 IP

Note:Only Super User can specify interval less than 0.2 seconds. If not, you'll get the following error message.

$ Ping-I 0.1 127.0.0.1ping 0 (127.0.0.1) 56 (84) bytes of data. Ping: cannot flood; minimal interval, allowed for user, is 200 ms
Ping Example 2. Check whether the local network interface is up and running

Before checking whether the peer machine is reachable, first check whether the local network is up and running using any one of the following 3 methods.

Ping localhost using zero (0)

This is probably the easiest and simplest way to ping a local host

 
$ Ping 0 Ping 0 (127.0.0.1) 56 (84) bytes of data.64 bytes from 127.0.0.1: icmp_seq = 1 TTL = 64 time = 0.024 Ms ^ C
Ping localhost using name
$ Ping localhostping localhost (127.0.0.1) 56 (84) bytes of data.64 bytes from localhost (127.0.0.1): icmp_seq = 1 TTL = 64 time = 0.051 ms64 bytes from localhost (127.0.0.1 ): icmp_seq = 2 TTL = 64 time = 0.055 Ms ^ C --- localhost Ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 999 msrtt min/AVG/max/mdev = 0.051/0.053/0.055/0.002 MS
Ping localhost using IP
 
$ Ping 127.0.0.1

To quit the ping command, send SIGINT signal by pressing CTRL + C. if you have not specified any option to make the ping to exit automatically, then you will be terminating using Ctrl + C (SIGINT) which will show the statistics and then terminate the ping process. when everything is working properly, it shoshould say '0% packet loss'

 
2 packets transmitted, 2 mounted Ed,0% packet loss,Time 999 msrtt min/AVG/max/mdev = 0.051/0.053/0.055/0.002 MS
Ping example 3. Send n Packets and stop

Send n Packets specified with-C option and then stop. This way the ping command can exit automatically instead of pressing CTRL + C to exit.

In the following example, Ping Command sends 5 packets, and waits for response from the destination host. Ping will exit after loading the response or error.

$ Ping-C 5 Google. comping Google.com (74.125.45.100) 56 (84) bytes of data.64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq = 1 TTL = 44 time = 731 ms64 bytes from yx-in-f100.google.com (74.125.45.100 ): icmp_seq = 2 TTL = 44 time = 777 ms64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq = 3 TTL = 44 time = 838 ms64 bytes from yx-in-f100.google.com (74.125.45.100 ): icmp_seq = 4 TTL = 44 time = 976 ms64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq = 5 TTL = 44 time = 1071 Ms --- Google.com Ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4216 msrtt min/AVG/max/mdev = 731.039/879.129/1071.050/126.625 MS
Ping Example 4. Show version and exit

Display the current version of Ping program using-V option.

 
$ Ping-vping utility, iputils-sss20071127
Ping Example 5. Flood the network

Super Users can send hundred or more packets per second using-F option. It prints a '. 'When a packet is sent, and a backspace is printed when a packet is wrongly ed.

As shown below, Ping-F has sent more than 400,000 packets in few seconds.

 
# Ping-F localhostping localhost (127.0.0.1) 56 (84) bytes of data .. ^ C --- localhost Ping statistics ---427412 packets transmitted, 427412 received, 0% packet loss, time 10941 msrtt min/AVG/max/mdev = 0.003/0.004/1.004/0.002 MS, IPG/EWMA 0.025/0.004 MS
Ping Example 6. Audible Ping: Give beep when the peer is reachable

This option is useful for SysAdmin during troubleshooting. there is no need for you to look at the ping output after each and every change. you can continue working with your changes, and when the remote machine become reachable you'll hear the beep automatically.

 
$ Ping-A IP

Note:It can give beep only from terminal number 1 through 7 and gnome-terminal (it will not work in console ).

Ping Example 7. Find out the IP address

You can identify the IP-address using the host name as shown below.

 
$ Ping-C 1 Google. comping Google.com (74.125.67.100) 56 (84) bytes of data.64 bytes from gw-in-f100.google.com (74.125.67.100): icmp_seq = 1 TTL = 43 time = 287 Ms --- Google.com Ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0 msrtt min/AVG/max/mdev = 287.903/287.903/287.903/0.000 MS
Ping Example 8. Print only ping command summary statistics

Use Option-Q to view only the ping statistics summary as shown below.

$ Ping-C 5-Q 127.0.0.1ping 127.0.0.1 (127.0.0.1) 56 (84) bytes of data. --- 127.0.0.1 Ping statistics --- 5 packets transmitted, 5 pinned ed, 0% packet loss, time 3998 msrtt min/AVG/max/mdev = 0.047/0.053/0.061/0.009 MS
Ping Example 9. Change ping packet size

You can change the packet size of ping command using-s option.

Example: Change the default packet size from 56 to 100.

 
$ Ping-S 100 localhostping localhost (127.0.0.1) 100 (128) bytes of data.108 bytes from localhost (127.0.0.1): icmp_seq = 1 TTL = 64 time = 0.022 ms108 bytes from localhost (127.0.0.1): icmp_seq = 2 TTL = 64 time = 0.021 ms108 bytes from localhost (127.0.0.1): icmp_seq = 3 TTL = 64 time = 0.020 Ms ^ C --- localhost Ping statistics --- 3 packets transmitted, 3 bytes ed, 0% packet loss, time 1998 msrtt min/AVG/max/mdev = 0.020/0.021/0.022/0.000 MS
Ping packet size

In the above example, when we set the packet size to 100, it displays '100 bytes 'in the output. this is because of the ping packet header size, which is 28 bytes. so, if you specify the packet size as 100, 28 bytes for header will be added to it and 128 bytes will be sent.

Ping Bytes Sent = ping packet size + Ping header packet size (28 bytes)

Ping Example 10. Timeout-W

Ping-W option specifies the deadline to terminate the ping output. This specifies the total number of seconds the ping command shocould send packets to the remote host.

The following example will ping for 5 seconds. I. e ping command will exit after 5 seconds irrespective of how many packets are sent or received.

 
$ Ping-W 5 localhost

Note:When you specify both-W, and-C, whichever comes first will terminate the ping command.

Ping example 11. Online Ping

Ping from different locations and check the reachability (availability or time for reaching) of your server from different locations.

If you want to do an online Ping, try just ping.

Ping example 12. Option-W or-C exits Ping
$ Ping-C 4 0-W 2 Ping 0 (127.0.0.1) 56 (84) bytes of data.64 bytes from 127.0.0.1: icmp_seq = 1 TTL = 64 time = 0.064 ms64 bytes from 127.0.0.1: icmp_seq = 2 TTL = 64 time = 0.060 ms64 bytes from 127.0.0.1: icmp_seq = 3 TTL = 64 time = 0.058 Ms --- 0 Ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1998 msrtt min/AVG/max/mdev = 0.058/0.060/0.064/0.009 MS $ Ping-C 4 0-W 10 Ping 0 (127.0.0.1) 56 (84) bytes of data.64 bytes from 127.0.0.1: icmp_seq = 1 TTL = 64 time = 0.063 ms64 bytes from 127.0.0.1: icmp_seq = 2 TTL = 64 time = 0.060 ms64 bytes from 127.0.0.1: icmp_seq = 3 TTL = 64 time = 0.055 ms64 bytes from 127.0.0.1: icmp_seq = 4 TTL = 64 time = 0.061 Ms --- 0 Ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 2997 msrtt min/AVG/max/mdev = 0.055/0.059/0.063/0.009 MS
Ping example 13. Shorter statistics with sigquit

While Ping is printing the individual packet status, when you want to view the shorter statistics you can use this technique.

PressingCTRL + |(Control Key followed by pipe symbol) for the shows the summary in between, and continues with it packet sending and processing process.

 $ Ping-W 100 localhostping localhost (127.0.0.1) 56 (84) bytes of data.64 bytes from localhost (127.0.0.1 ): icmp_seq = 10 TTL = 64 time = 0.021 ms64 bytes from localhost (127.0.0.1): icmp_seq = 11 TTL = 64 time = 0.022 Ms  11/11 packets, 0% loss, MIN/AVG/EWMA/max = 0.020/0.022/0.022/0.024 Ms  64 bytes from localhost (127.0.0.1 ): icmp_seq = 12 TTL = 64 time = 0.021 ms64 bytes from localhost (127.0.0.1): icmp_seq = 13 TTL = 64 time = 0.022 ms64 bytes from localhost (127.0.0.1 ): icmp_seq = 14 TTL = 64 time = 0.021 ms64 bytes from localhost (127.0.0.1): icmp_seq = 15 TTL = 64 time = 0.021 Ms  19/19 packets, 0% loss, MIN/AVG/EWMA/max = 0.020/0.022/0.022/0.024 Ms  64 bytes from localhost (127.0.0.1 ): icmp_seq = 31 TTL = 64 time = 0.022 ms64 bytes from localhost (127.0.0.1): icmp_seq = 32 TTL = 64 time = 0.022 Ms  32/32 packets, 0% loss, MIN/AVG/EWMA/max = 0.020/0.022/0.022/0.027 Ms  64 bytes from localhost (127.0.0.1): icmp_seq = 33 TTL = 64 time = 0.023 Ms .. 
Ping example 14. Specify path for ping to send the packet

You can also specify through which path the ping shocould send the packet to destination.

 
$ Ping hop1 hop2 hop3 .. hopn destination
 
$ Ping 192.168.3.33 192.168.7.1 192.168.4.45

Note:If one of the hop in the path is not reachable then you will have failure in pinging.

Ping example 15. Record and print route of how echo_request sent and echo_reply replicated ed

It records, and prints the network route through which the packet is sent and stored ed. This is useful for network engineers who wish to know how the packet is sent and stored ed.

 $ Ping-r 192.168.1.63ping 192.168.1.63 (192.168.1.63) 56 (84) bytes of data.64 bytes from 192.168.1.63: icmp_seq = 1 TTL = 61 time = 2.05 msrr: 192.168.9.118 192.168.3.25 192.168.10.35 192.168.1.26 192.168.1.63 192.168.1.63 192.168.10.4 192.168.3.10 192.168.4.2564 bytes from 192.168.1.63: icmp_seq = 2 TTL = 61 time = 2.00 MS (same route) 

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.