The ping command
The ping command checks that another machine answers on the network…
The ping command checks that another machine answers on the network: ping -c 3 example.com sends three small packets and shows how long each reply took.
Taught in Intermediate, lesson 30; more in Ninja
A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.
Usage
ping [-c COUNT] [-i SECONDS] HOST
Check that another machine answers. Sends small packets to HOST and shows each reply and how long it took. Replies mean the machine is up and reachable; no replies mean it is down, missing, or something in between drops the packets. Without -c it keeps going until you press Ctrl+C, then prints a summary. "Name or service not known" means the name itself didn’t resolve. In this practice shell the network is a simulation inside your browser: the machines web, db and router and the website example.com are pretend, and nothing leaves your device.
In the practice terminal:A simulation: web, db, router and example.com are pretend machines inside your browser, and no network traffic leaves your device.
How to use ping
Check that a machine answers
Each reply shows how long it took, in milliseconds. Without -c, ping carries on until you press Ctrl+C.
ping -c 3 webPING web (10.0.0.10) 56(84) bytes of data. 64 bytes from web (10.0.0.10): icmp_seq=1 ttl=64 time=0.451 ms 64 bytes from web (10.0.0.10): icmp_seq=2 ttl=64 time=0.492 ms 64 bytes from web (10.0.0.10): icmp_seq=3 ttl=64 time=0.420 ms --- web ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.420/0.454/0.492/0.029 ms
Ping a website by name
ping looks the name up first and shows the address it found, which also tells you DNS works.
ping -c 2 example.comPING example.com (203.0.113.80) 56(84) bytes of data. 64 bytes from example.com (203.0.113.80): icmp_seq=1 ttl=54 time=15.6 ms 64 bytes from example.com (203.0.113.80): icmp_seq=2 ttl=54 time=17.0 ms --- example.com ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1000ms rtt min/avg/max/mdev = 15.600/16.300/17.000/0.700 ms
Only the summary: ping -q
ping -c 3 -q webPING web (10.0.0.10) 56(84) bytes of data. --- web ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.420/0.454/0.492/0.029 ms
When there is no answer
"Name or service not known" means the name couldn’t be looked up: a typo, or a DNS problem. No replies at all means the machine is down, unreachable, or behind a firewall that drops ping.
ping -c 2 nosuch.exampleping: nosuch.example: Name or service not known
Ping the router’s address
An address skips DNS, which helps tell a network problem from a name problem. ip route shows the router (the default gateway).
ip routedefault via 10.0.0.1 dev eth0 proto dhcp src 10.0.0.5 metric 100 10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.5 metric 100
ping -c 1 10.0.0.1PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data. 64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.451 ms --- 10.0.0.1 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.451/0.451/0.451/0.000 ms
Options
| -c COUNT | stop after COUNT replies |
|---|---|
| -i SECONDS | wait this long between packets |
| -q | only the summary |
More examples
ping -c 1 example.comPING example.com (203.0.113.80) 56(84) bytes of data. 64 bytes from example.com (203.0.113.80): icmp_seq=1 ttl=54 time=15.6 ms --- example.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 15.600/15.600/15.600/0.000 ms
Questions about ping
How do I stop ping?
Press Ctrl+C. ping then prints a summary of how many packets were sent and answered. ping -c 4 sends four and stops by itself.
What does 0% packet loss mean?
Every packet ping sent got a reply. Some loss points to an unreliable link; 100% means no answer at all, from a machine that is down, unreachable or blocking ping.
If a website doesn’t answer ping, is it down?
Not always. Many servers and firewalls ignore ping on purpose. Check the website itself with curl -I.
Learn it step by step
Related commands
Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.