Anda di halaman 1dari 13

Ping Tutorial: 15 Effective Ping Command Examples

1 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

Database Modeling Tool


www.datanamic.com
Draw ER Diagrams with DeZign. Create, design & import databases.

Home
Free eBook
Start Here
Contact
About

Ping Tutorial: 15 Effective Ping Command Examples


by Ramesh Natarajan on November 30, 2009
16

Like

75

Tweet

the peer host/gateway is reachable.

10

As you already know, ping command is used to find out whether

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.

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

2 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

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.

(Promoo Hoje)
Claro TV
ClaroTvPorAssinatura.tv.br/ClaroTV
(Quarta-Feira 13/11). 126 Canais
+ Telecine Grtis 90dias +Adeso
Zero

# ping -i 0.1 IP

Note: Only super user can specify interval less than 0.2 seconds. If not, youll 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

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

3 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

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
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=2
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=3
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=4
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=5

ttl=44
ttl=44
ttl=44
ttl=44
ttl=44

time=731 ms
time=777 ms
time=838 ms
time=976 ms
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

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

4 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

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 youll 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
108 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64
108 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64
^C
--- localhost ping statistics --3 packets transmitted, 3 received, 0% packet loss, time
rtt min/avg/max/mdev = 0.020/0.021/0.022/0.000 ms

time=0.022 ms
time=0.021 ms
time=0.020 ms
1998ms

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

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

5 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

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
64 bytes from localhost (127.0.0.1): icmp_seq=11 ttl=64 time=0.022
11/11 packets, 0% loss, min/avg/ewma/max = 0.020/0.022/0.022/0.024
64 bytes from localhost (127.0.0.1): icmp_seq=12 ttl=64 time=0.021
64 bytes from localhost (127.0.0.1): icmp_seq=13 ttl=64 time=0.022
64 bytes from localhost (127.0.0.1): icmp_seq=14 ttl=64 time=0.021
64 bytes from localhost (127.0.0.1): icmp_seq=15 ttl=64 time=0.021
19/19 packets, 0% loss, min/avg/ewma/max = 0.020/0.022/0.022/0.024
64 bytes from localhost (127.0.0.1): icmp_seq=31 ttl=64 time=0.022
64 bytes from localhost (127.0.0.1): icmp_seq=32 ttl=64 time=0.022
32/32 packets, 0% loss, min/avg/ewma/max = 0.020/0.022/0.022/0.027

ms
ms
ms
ms
ms
ms
ms
ms
ms
ms
ms

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

6 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

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
16

Tweet

10

Like

75

(same route)

> Add your comment

Linux provides several powerful administrative tools and utilities which will help
you to manage your systems effectively. If you dont know what these tools are and how to use them, you could
be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help
you understand system administration tools, which will help you to become an effective Linux system
administrator.
Get the Linux Sysadmin Course Now!

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


1. 50 Linux Sysadmin Tutorials
2. 50 Most Frequently Used Linux Commands (With

Awk Introduction 7 Awk Print Examples


Advanced Sed Substitution Examples

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

7 of 13

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

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

8 Essential Vim Editor Navigation


Fundamentals
25 Most Frequently Used Linux IPTables
Rules Examples
Turbocharge PuTTY with 12 Powerful
Add-Ons

Tags: Linux Ping Command, Ping -t, Ping Command, Ping Examples, Unix Ping Command
{ 22 comments read them below or add one }
1 Salih November 30, 2009 at 7:21 pm
Hi Ramesh,
Good Article. Thanks
Best Regards
Salih KM
2 Anonymous December 1, 2009 at 10:26 am
very good tutorial
3 diptanu paul December 2, 2009 at 11:54 pm
Excellent article Ramesh.Thanks for the increasing the kowledgebase.
4 S.RAGHU December 3, 2009 at 3:13 am
Great article.Never knew ping could be used to determine the ip or route and also get the short stat. Thanx
5 Sravan Babu December 5, 2009 at 12:53 am
Hi RameshAwesome 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

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

8 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

6 NetSpider December 6, 2009 at 1:12 pm


ive 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 im going to ping 0, ive 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 dont know why.. =(
0 should be my default GW (!not 127.0.0.1!)
7 Ramesh Natarajan December 10, 2009 at 5:55 pm
@Salih, Diptanu,
Thanks for the comment. Im 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, youll hear the beep only on the host where the ping
command is getting executed.
For example, from your laptop, if youve ssh-ed to dev-db and executing ping -a google.com on dev-db,
youll hear the beep only on the dev-db box.
@Netspider,
That is strange. Im 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?
8 Reza December 21, 2009 at 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

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

9 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

TQ
9 Anonymous March 23, 2011 at 5:12 am
superb article
10 saikrishna July 18, 2011 at 4:09 am
super article
11 TK Nallappan August 6, 2011 at 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
12 Greg Janssen October 27, 2011 at 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.
13 angel July 8, 2012 at 10:32 pm
One of the small hive of usable articles!
14 Gaurav B August 6, 2012 at 10:51 am
One word !!! Ultimate !!!
Thanks for posting.
15 sumit September 5, 2012 at 2:04 pm
im using ubuntu 11.10, and new linux user.
ping -R isnt workingit isnt showing me the return path
16 Sean January 31, 2013 at 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
17 kumar February 11, 2013 at 4:22 am
how to reduce ping
18 Heinz March 29, 2013 at 9:34 am

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

10 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

Hi
Nice tutorial. I get a correct address when I ping 0 but get something different when I ping localhost?
Strange
19 Anuraj August 28, 2013 at 6:10 am
Good Article
20 Anonymous October 25, 2013 at 12:58 pm
Awesome tutorial dude. learned alot.
21 Bob November 10, 2013 at 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
22 NetSpider November 11, 2013 at 8:29 pm
Bob, I assume youre using Mac OS X or FreeBSD?
Ive 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.
Leave a Comment
Name
E-mail
Website

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

11 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

Notify me of followup comments via e-mail

Previous post: Black Friday Deal: 40% Discount on Vim 101 Hacks Book
Next post: 4 Ways to Kill a Process kill, killall, pkill, xkill
RSS | Email | Twitter | Facebook | Google+
Search

Database Modeling
Tool
www.datanamic.com

Draw ER Diagrams with


DeZign. Create, design &
import databases.

COURSE
Linux Sysadmin CentOS 6 Course - Master the Tools, Configure it Right, and be Lazy

EBOOKS
Linux 101 Hacks 2nd Edition eBook - Practical Examples to Build a Strong Foundation in
Linux
Bash 101 Hacks eBook - Take Control of Your Bash Command Line and Shell Scripting
Sed and Awk 101 Hacks eBook - Enhance Your UNIX / Linux Life with Sed and Awk
Vim 101 Hacks eBook - Practical Examples for Becoming Fast and Productive in Vim Editor
Nagios Core 3 eBook - Monitor Everything, Be Proactive, and Sleep Well

POPULAR POSTS
12 Amazing and Essential Linux Books To Enrich Your Brain and Library
50 UNIX / Linux Sysadmin Tutorials
50 Most Frequently Used UNIX / Linux Commands (With Examples)
How To Be Productive and Get Things Done Using GTD
30 Things To Do When you are Bored and have a Computer
Linux Directory Structure (File System Structure) Explained with Examples
Linux Crontab: 15 Awesome Cron Job Examples
Get a Grip on the Grep! 15 Practical Grep Command Examples
Unix LS Command: 15 Practical Examples
15 Examples To Master Linux Command Line History

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

12 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

Top 10 Open Source Bug Tracking System


Vi and Vim Macro Tutorial: How To Record and Play
Mommy, I found it! -- 15 Practical Linux Find Command Examples
15 Awesome Gmail Tips and Tricks
15 Awesome Google Search Tips and Tricks
RAID 0, RAID 1, RAID 5, RAID 10 Explained with Diagrams
Can You Top This? 15 Practical Linux Top Command Examples
Top 5 Best System Monitoring Tools
Top 5 Best Linux OS Distributions
How To Monitor Remote Linux Host using Nagios 3.0
Awk Introduction Tutorial 7 Awk Print Examples
How to Backup Linux? 15 rsync Command Examples
The Ultimate Wget Download Guide With 15 Awesome Examples
Top 5 Best Linux Text Editors
Packet Analyzer: 15 TCPDUMP Command Examples
The Ultimate Bash Array Tutorial with 15 Examples
3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id
Unix Sed Tutorial: Advanced Sed Substitution Examples
UNIX / Linux: 10 Netstat Command Examples
The Ultimate Guide for Creating Strong Passwords
6 Steps to Secure Your Home Wireless Network
Turbocharge PuTTY with 12 Powerful Add-Ons

CATEGORIES
Linux Tutorials
Vim Editor
Sed Scripting
Awk Scripting
Bash Shell Scripting
Nagios Monitoring
OpenSSH
IPTables Firewall
Apache Web Server
MySQL Database
Perl Programming
Google Tutorials
Ubuntu Tutorials
PostgreSQL DB
Hello World Examples
C Programming
C++ Programming
DELL Server Tutorials
Oracle Database
VMware Tutorials

11/13/2013 2:07 PM

Ping Tutorial: 15 Effective Ping Command Examples

13 of 13

http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-co...

About The Geek Stuff

My name is Ramesh Natarajan. I will be posting instruction guides, how-to,


troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write
articles that will either teach you or help you resolve a problem. Read more about Ramesh Natarajan and
the blog.

Support Us
Support this blog by purchasing one of my ebooks.
Bash 101 Hacks eBook
Sed and Awk 101 Hacks eBook
Vim 101 Hacks eBook
Nagios Core 3 eBook

Contact Us
Email Me : Use this Contact Form to get in touch me with your comments, questions or suggestions about
this site. You can also simply drop me a line to say hello!.
Follow us on Google+
Follow us on Twitter
Become a fan on Facebook
Copyright 20082013 Ramesh Natarajan. All rights reserved | Terms of Service

11/13/2013 2:07 PM

Anda mungkin juga menyukai