Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am pinging a remote IP. I know very little about the Ping command. When I ping the IP, it keeps going and going... I am not using the -t option.

Me$ ping 137.30.124.104
PING 137.30.124.104 (137.30.124.104): 56 data bytes
64 bytes from 137.30.124.104: icmp_seq=0 ttl=62 time=3.378 ms
64 bytes from 137.30.124.104: icmp_seq=1 ttl=62 time=3.825 ms
64 bytes from 137.30.124.104: icmp_seq=2 ttl=62 time=4.882 ms
64 bytes from 137.30.124.104: icmp_seq=3 ttl=62 time=1.822 ms
64 bytes from 137.30.124.104: icmp_seq=4 ttl=62 time=4.572 ms
....
64 bytes from 137.30.124.104: icmp_seq=290 ttl=62 time=3.273 ms

Does that mean it is successfully pinging the IP? Or that it is trying and failing and trying again? How do I get it to stop?

share|improve this question
3  
Yes, it is successfully pinging. You can stop it with Ctrl-C. –  Faheem Mitha Nov 3 '13 at 17:49
4  
Unix-likes ping doesn't stop like windows does by default. –  sputnick Nov 3 '13 at 18:08
    
@sputnick yeah that was what was confusing me –  akh2103 Nov 3 '13 at 18:11
    
See how you can control it in my answer! –  slm Nov 3 '13 at 18:13
add comment

2 Answers

up vote 8 down vote accepted

That's how the ping command works. You can control it using the count switch, -c.

Example

$ ping -c 2 skinner
PING skinner.bubba.net (192.168.1.3) 56(84) bytes of data.
64 bytes from skinner.bubba.net (192.168.1.3): icmp_req=1 ttl=64 time=1.00 ms
64 bytes from skinner.bubba.net (192.168.1.3): icmp_req=2 ttl=64 time=1.13 ms

--- skinner.bubba.net ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 1.001/1.069/1.138/0.075 ms

Breakdown of output

Lines like this mean that it is successfully pinging the other host:

64 bytes from skinner.bubba.net (192.168.1.3): icmp_req=2 ttl=64 time=1.13 ms

These lines show detalis about each "ping" as it occurs between your host and the host you're atempting to ping.

6th column

The column that contains this value, icmp_req=2 is telling you which ICMP packet this is regarding. The ping command manufactures network packets. There are many types, you've probably heard of TCP or perhaps UDP packets. Another type is ICMP. ICMP is similar to SMS in cell phone networks. It's primary purpose is for command and control over the network.

7th column

The 3rd column that's interesting is the TTL=64. TTL - "aka. Time to Live", mean that the packet will only transverse through at most 64 nodes before timing out. So if the system is more than 64 "hops" away from your system, you can't ping it, unless you increase the TTL.

8th column

This column shows how long, in time, the ping took to occur (in milliseconds). This would be the column that looks like this: time=1.13 ms.

The other columns are fairly self explanatory.

Ping versions

Different ping commands are implemented differently across the various Unixes. So you need to pay attention to the version.

$ ping -V
ping utility, iputils-sss20100418

I'm on a Fedora 14, Linux system.

share|improve this answer
add comment

slm's answer is great, but if you just want to quickly check whether a host is alive (and reachable, and responding to ping) then you can use fping instead of ping. It pings the host(s), and waits a short time for a response. fping's exit code reports success or failure.

e.g.

cas@ganesh:~$ fping kali
kali is alive
cas@ganesh:~$ echo $?
0

cas@ganesh:~$ fping durga 
ICMP Host Unreachable from 203.xx.xxx.1 for ICMP Echo sent to durga (203.xx.xxx.14)
ICMP Host Unreachable from 203.xx.xxx.1 for ICMP Echo sent to durga (203.xx.xxx.14)
ICMP Host Unreachable from 203.xx.xxx.1 for ICMP Echo sent to durga (203.xx.xxx.14)
ICMP Host Unreachable from 203.xx.xxx.1 for ICMP Echo sent to durga (203.xx.xxx.14)
durga is unreachable
cas@ganesh:~$ echo $?
1

The 'ICMP Host Unreachable' messages can be discarded by redirecting stderr to /dev/null. For example:

cas@ganesh:~$ fping durga 2>/dev/null 
durga is unreachable
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.