≡ Menu

Ping Tutorial: 15 Effective Ping Command Examples

Linux Ping Command for Debian, Ubuntu and Fedora - ExamplesAs you already know, ping command is used to find out whether the peer host/gateway is reachable.

If you are thinking ping is such a simple command and why do I need 15 examples, you should read the rest of the article.

Ping command provides lot more options than what you might already know.

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.1
PING 0 (127.0.0.1) 56(84) bytes of data.
ping: cannot flood; minimal interval, allowed for user, is 200ms

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 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 localhost
PING 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 ms
64 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 999ms
rtt 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 should say ‘0% packet loss’

2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt 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 receiving the response or error.

$ ping -c 5 google.com
PING 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 ms
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=2 ttl=44 time=777 ms
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=3 ttl=44 time=838 ms
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=4 ttl=44 time=976 ms
64 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 4216ms
rtt 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 -V
ping 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 received.

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

# ping -f localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
.^C
--- localhost ping statistics ---
427412 packets transmitted, 427412 received, 0% packet loss, time 10941ms
rtt 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.com
PING 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 0ms
rtt 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.1 
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

--- 127.0.0.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 3998ms
rtt 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 localhost
PING 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 ms
108 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.021 ms
108 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.020 ms
^C
--- localhost ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt 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 ‘128 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 should 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 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.060 ms
64 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 1998ms
rtt 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 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.060 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.055 ms
64 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 2997ms
rtt 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.

Pressing CTRL+| (Control key followed by pipe symbol) for the shows the summary in between, and continues with it packet sending and receiving process.

$ ping -w 100 localhost
PING 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 ms
64 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 ms
64 bytes from localhost (127.0.0.1): icmp_seq=13 ttl=64 time=0.022 ms
64 bytes from localhost (127.0.0.1): icmp_seq=14 ttl=64 time=0.021 ms
64 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 ms
64 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 should 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 received

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

$ ping -R 192.168.1.63
PING 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 ms
RR:   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.25
64 bytes from 192.168.1.63: icmp_seq=2 ttl=61 time=2.00 ms      (same route)
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Salih November 30, 2009, 7:21 pm

    Hi Ramesh,

    Good Article. Thanks 🙂

    Best Regards
    Salih KM

  • Anonymous December 1, 2009, 10:26 am

    very good tutorial

  • diptanu paul December 2, 2009, 11:54 pm

    Excellent article Ramesh.Thanks for the increasing the kowledgebase.

  • S.RAGHU December 3, 2009, 3:13 am

    Great article.Never knew ping could be used to determine the ip or route and also get the short stat. Thanx

  • Sravan Babu December 5, 2009, 12:53 am

    Hi Ramesh…Awesome tut on ping
    🙂
    but I m unable
    to use the audible option
    When I use ” ping -a google.com”
    I m not able to hear any beep
    🙁
    🙁

  • NetSpider December 6, 2009, 1:12 pm

    i’ve got strange result on FreeBSD 🙂

    ~> netstat -r -n
    Routing tables
    Internet:
    Destination Gateway Flags Refs Use Netif Expire
    default a.b.c.1 UGS 0 66309126 em0

    Okay, my GW is a.b.c.1. But when i’m going to ping 0, i’ve got this:

    ~> ping 0.0.0.0
    PING 0.0.0.0 (0.0.0.0): 56 data bytes
    64 bytes from a.b.c.2: icmp_seq=0 ttl=64 time=0.261 ms
    64 bytes from a.b.c.2: icmp_seq=1 ttl=64 time=0.109 ms
    ^C

    i don’t know why.. =(
    0 should be my default GW (!not 127.0.0.1!)

  • Ramesh Natarajan December 10, 2009, 5:55 pm

    @Salih, Diptanu,

    Thanks for the comment. I’m very glad you found this article helpful.

    @Raghu,

    Yes. Lot of people underestimate the power of ping.

    @Sravan,

    If you are trying to do a ‘ping -a’ on a remote server, you’ll hear the beep only on the host where the ping command is getting executed.

    For example, from your laptop, if you’ve ssh-ed to dev-db and executing ‘ping -a google.com’ on dev-db, you’ll hear the beep only on the dev-db box.

    @Netspider,

    That is strange. I’m not sure why that is happening. When you do, ping 0, it is supposed to ping only the local host and not even the gateway. Are there any strange entries in your /etc/hosts file?

  • Reza December 21, 2009, 12:17 am

    Thanks for your very nice tutorial. Could you please also help me with these two questions:

    1- Ping claims to give an estimation about RTT(Round Trip Time) for SPECIFIC PACKET SIZE. But as it shows the packet that is coming back is 20Bytes less. So we have a RTT for which packet size (86 which goes or 66 which is coming back) ?

    2-What does “mdev” means in mid/avg/max/mdev

    TQ

  • Anonymous March 23, 2011, 5:12 am

    superb article

  • saikrishna July 18, 2011, 4:09 am

    super article

  • TK Nallappan August 6, 2011, 4:36 pm

    Hi All,

    Here is the command to protect yourself from a form of attack known as a ‘ping flood’

    # sysctl -w net.ipv4.icmp_echoreply_rate=10

  • Greg Janssen October 27, 2011, 12:38 pm

    This must not be about Windows XP! Parts of it do not work with XP. Can the Increase Decrease Time Internal of Ping packets be shown for XP? Thanks.

  • angel July 8, 2012, 10:32 pm

    One of the small hive of usable articles!

  • Gaurav B August 6, 2012, 10:51 am

    One word !!! Ultimate !!!

    Thanks for posting.

  • sumit September 5, 2012, 2:04 pm

    i’m using ubuntu 11.10, and new linux user…….
    ping -R isn’t working……it isn’t showing me the return path

  • Sean January 31, 2013, 7:33 pm

    can you tell me what the difference between Ping -R and normal ping
    i notice i can always ping but Ping -R doesnt behave the same

    we had some issues with mac not being able print or use afp ( we recently upgraded to mountain lion)

    we narrowed it down to the bridge that connects another bridge connection which links to a gateway to the windows 2008 server side. As soon as we disconnected the bridge connection and use Ping -R to a printer works straight away and afp works too.. soon as we connected it back it stops working and ping -R time out

  • kumar February 11, 2013, 4:22 am

    how to reduce ping

  • Heinz March 29, 2013, 9:34 am

    Hi
    Nice tutorial. I get a correct address when I ping 0 but get something different when I ping localhost? Strange

  • Anuraj August 28, 2013, 6:10 am

    Good Article

  • Anonymous October 25, 2013, 12:58 pm

    Awesome tutorial dude. learned alot.

  • Bob November 10, 2013, 12:29 am

    this article is wrong in many respects
    %ping -V
    ping: illegal option — V

    host(1) or drill(1) should be used to determine IP – not ping.

    there is no -w option. you mean to use -t for timeout

    CTRL+| is wrong. You mean CTRL-t

    ping does not support source routing

  • NetSpider November 11, 2013, 8:29 pm

    Bob, I assume you’re using Mac OS X or FreeBSD?
    I’ve got the same error on FreeBSD:
    ~ ~> ping -V
    ping: illegal option — V
    Ramesh should specify that some examples may vary on non-Linux OSes or even on some Linux versions.
    A better way to determine IP is dig:
    ~ ~> dig +short google.com
    173.194.70.101
    173.194.70.139

    In order to try “drill” I had to install /usr/ports/dns/ldns, but in my taste the “dig” is better.

  • prashant December 3, 2013, 6:51 am

    sir… its really good..

    im a beginner to linux… please give a idea to develope my career..

  • Ujwal December 16, 2013, 8:52 am

    Hi,

    Great article!

    Can you tell me how to loop pinging a particular IP after regular intervals of time.

    Ex:
    Say suppose I have an IP: a.b.c.d
    I want to ping this IP every 300sec. What is to be done?

  • NetSpider December 16, 2013, 2:22 pm

    Ujwal, you can use -i key:
    -i wait Wait wait seconds between sending *each packet*.
    Or you can use bash-script:
    while :; do ping -c yy a.b.c.d; sleep xx; done
    This script will send yy icmp-packets every xx seconds.

  • Vitalie March 24, 2014, 2:12 am

    Also you could include -r option.

    -r – direct ping without taking in account routing table.

    Problem: need to check if we have wire electrical connection.
    lnx#> ping -r

  • gandhimathi April 20, 2014, 6:14 pm

    Hi Ramesh,
    This is very useful article. I have a question.
    The time displayed in the ping statistics is taken from where? Is the time taken to run the the ping command?
    for example, 5 packets transmitted, 5 received, 0% packet loss, time 3998ms
    Then no.of packets sent * avg RTT is the time taken to send and receive is the time taken for the pings right. Why both the times are not equal?

  • Bobin chacko April 24, 2014, 11:27 am

    hi I tried to use the command ping -c 5 google.com it gives me a message that access denied option -c requires administrative privileges… while I am logged in as administrator with an elevated command prompt please help

  • Ritesh April 25, 2014, 1:11 am

    If I ping using hostname it does not ping.
    Ex
    $ ping abc //abc as host name
    It gives message
    ping: unknown host abc

  • Kevin December 10, 2014, 3:53 pm

    HI Sir, thank you for sharing.

    What is a perpetual ping?

  • rodnaldo January 12, 2015, 5:15 am

    Hi there!
    I’m Rodnaldo. I’d like to ask you about an output that I’m having..

    When I ping 10.0.51.24 I’m geting:
    40 bytes from 10.0.51.24: icmp_req=503 ttl=127 (truncated)
    40 bytes from 10.0.51.24: icmp_req=504 ttl=127 (truncated)
    40 bytes from 10.0.51.24: icmp_req=505 ttl=127 (truncated)
    40 bytes from 10.0.51.24: icmp_req=506 ttl=127 (truncated)
    40 bytes from 10.0.51.24: icmp_req=507 ttl=127 (truncated)
    40 bytes from 10.0.51.24: icmp_req=508 ttl=127 (truncated)
    40 bytes from 10.0.51.24: icmp_req=509 ttl=127 (truncated)
    40 bytes from 10.0.51.24: icmp_req=510 ttl=127 (truncated)
    40 bytes from 10.0.51.24: icmp_req=511 ttl=127 (truncated)
    40 bytes from 10.0.51.24: icmp_req=512 ttl=127 (truncated)
    ^C
    — 10.0.51.24 ping statistics —
    512 packets transmitted, 512 received, 0% packet loss, time 511001ms
    rtt min/avg/max/mdev = 0.189/3.012/167.145/16.791 ms

    Do you know what’s happenning? What does truncated mean?

    Since already thank you so much

  • SK98 February 7, 2015, 3:04 am

    Hello, just had a bit of a problem when I tried to use the ping -s command. I tried to change the value to 100, but it gave me an error saying “Bad value for option -s, valid range is from 1 to 4.” Anyone know why this is happening? Thanks

  • VINAY G March 11, 2015, 11:58 pm

    hi,
    how to find everysecond of ping of a subnet ip address..
    example :
    10.4.34.4

    10.4.34.254.In between all IP’s ping of every second …..

    how to do ? need batch file or some other soluction….

    thanks

  • Suleman April 22, 2015, 3:54 am

    Very Good

  • Krishna July 24, 2015, 12:55 pm

    Very nice and usefull , tips and tricks. explained in a very good mannered and almost cover all useful tips for ping

  • Sys January 10, 2016, 8:46 am

    The -W parameter is also very useful (it’s not the same as the -w parameter) to achieve that ping stops waiting after x seconds:

    -W timeout
    Time to wait for a response, in seconds. The option affects only timeout in absence of any responses, otherwise ping waits for two RTTs.

  • Roshan January 20, 2016, 12:01 am

    [root@1-2 ~]# ping 10.3.3.24 -c 1 -t 80
    PING 10.3.3.24 (10.3.3.24) 56(84) bytes of data.
    64 bytes from 10.3.3.24: icmp_seq=1 ttl=63 time=1.33 ms

    In this statemement i am setting a ttl value as 80 and i have one hop for the destination, so i was expecting ttl=79 in my result but it is showing it as 63 which is default TTL. Can anyone explain me what is happening here?

    ping 10.3.3.24 -c 1 -t 80

    C means count
    t means TTL

  • Hara Prasasd Sahoo May 31, 2016, 5:27 am

    You wrote -s to change the packet size ,but it is not working it tells
    “Bad value for option -s,valid values range from 1 to 4”

    But I think you had mistaken -s for -l.

    ping -l 100 URL_VARIABLE
    is working perfectly and sending packets of size 100 bytes.

  • Eeshan July 2, 2016, 10:41 pm

    Hello Ramesh ,
    Thanks for the wonderful tutorial . It was really helpful .

  • John Deere March 21, 2017, 7:48 pm

    Decent article from a ‘what’ ping can do perspective but, you need to expand to include ‘why’ some of the options can be useful in various situations. For example, what are the benefits of using larger buffer sizes …

  • chetan March 14, 2019, 4:03 am

    I have a very slow internet connection. I observed a very strange thing with this.
    Nice article.
    I have doubt, I was trying to ping 8.8.8.8 and observed the following.
    If I open one command prompt window and starts to ping 8.8.8.8, it will not work.
    If I open two command prompt windows and ping 8.8.8.8 from both of them, then it will work smoothly.
    Can you please tell me what could be the reason and solution. Thanks in advance.