What it does
ping sends small packets and waits for the answer. It shows the round-trip time per packet and at the end the packet loss and min/avg/max times. On Linux it runs until you press Ctrl+C, unless you give a count with -c.
No answer does not always mean the host is down: firewalls often block ICMP. Test the real service too (like curl or ss).
How to write it
ping [OPTION]... DESTINATIONOptions 38
Most used
Count and timing
Address and route
Packets
Output
Nothing matches this filter.
Examples 11
$ run as a normal user# run as root (or with sudo)
1Test a host with 3 packets
ping -c 3 192.168.122.1 PING 192.168.122.1 (192.168.122.1) 56(84) bytes of data. 64 bytes from 192.168.122.1: icmp_seq=1 ttl=64 time=0.412 ms 64 bytes from 192.168.122.1: icmp_seq=2 ttl=64 time=0.389 ms 64 bytes from 192.168.122.1: icmp_seq=3 ttl=64 time=0.401 ms --- 192.168.122.1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.389/0.400/0.412/0.009 ms0% loss = the gateway answers.
2Test the network step by step
ping -c1 192.168.122.1 && ping -c1 8.8.8.8 && ping -c1 www.redhat.comGateway → internet → DNS: the first failure shows where the problem is.
3Test IPv6
ping -6 -c 2 2001:db8:10::1Use -6 with names that have both addresses.
4Ping from a chosen interface
ping -c 3 -I enp2s0 10.0.0.1Checks a second network card.
5Find the MTU of the path
ping -c 2 -M do -s 1472 192.168.122.201472 + 28 header bytes = 1500. "Message too long" means the MTU is smaller (VPN, tunnels).
6Only the summary
ping -q -c 20 server2Good for scripts and reports.
7Stop after a fixed time
ping -w 5 server2Ends after 5 seconds even when no answer comes.
8Wait until a host is back after a reboot
Then connect with ssh.
9Log with time stamps
ping -D -i 10 server2 | tee ping.logProof of short outages for the network team.
10Quick sweep of a small subnet
Only on your own networks; better tools: nmap -sn.
11Load test (root, lab only)
ping -f -c 1000 server2Shows packet loss under load. Never on networks you do not own.
Nothing matches this filter.
Watch out
- No answer can be a firewall, not a dead host.
- A name that does not resolve gives "Name or service not known": that is a DNS problem.
Exit codes
0 :: At least one answer. 1 :: No answer (with -c or -w). 2 :: Other error (like an unknown name).