ping / ping6
ping sends an ICMP Echo Request and the Echo Reply tells you whether a host is reachable, how long the round trip took and how many packets were lost. The same letters mean different things on Windows, Linux and macOS, so knowing the options per OS matters.
38.1 Where it runs
| OS | Command | Default behaviour |
|---|---|---|
| Windows | ping.exe (built in) | Stops after 4 packets, 32 bytes of data |
| Linux | iputils ping (IPv4 + IPv6) | Runs until Ctrl+C, 56 data bytes |
| macOS | ping + separate ping6 for IPv6 | Runs until Ctrl+C, 56 data bytes |
- Step 1
1.PC 192.168.58.10 sends an Echo Request (TTL 64) to the switch
- Step 2
2.Router 1 forwards it, TTL 64 -> 63
- Step 3
3.Router 2 forwards it, TTL 63 -> 62
- Step 4
4.Server 192.168.58.130 receives it and sends an Echo Reply
- Step 5
5.Reply returns via Router 2, Router 1 and the switch: output shows ttl=62
38.2 Windows ping: count, timeout, size and header
| Option | Meaning |
|---|---|
| -n 2 | Number of echo requests (default 4) |
| -t | Ping non-stop until Ctrl+C |
| -w 1000 | Reply timeout in ms |
| -a | Resolve the IP to a name |
| -4 / -6 | Force IPv4 / IPv6 |
| -l 1000 | Data size (default 32, max 65500) |
| -f | Don't Fragment flag |
| -i 64 | Outgoing TTL (the server decides the reply TTL) |
| -v | TOS (deprecated) |
| -S | Source address |
| -r 4 / -s 4 | Record route (1-9 hops) / timestamp per hop (1-4), IPv4 only |
| -j / -k | Loose / strict source route (max 9), not together |
| -c / -p | Routing compartment / Hyper-V provider address |
ping 8.8.8.8ping -n 2 -w 1000 1.1.1.1ping -a -n 1 8.8.8.8ping -6 -n 1 dns.googleping -n 1 -l 70000 8.8.8.8ping -n 1 -f -l 1472 8.8.8.8$ ping 8.8.8.8Pinging 8.8.8.8 with 32 bytes of data:Reply from 8.8.8.8: bytes=32 time=23ms TTL=117Reply from 8.8.8.8: bytes=32 time=19ms TTL=117Reply from 8.8.8.8: bytes=32 time=20ms TTL=117Reply from 8.8.8.8: bytes=32 time=19ms TTL=117Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Minimum = 19ms, Maximum = 23ms, Average = 20ms$ ping -n 2 -w 1000 1.1.1.1Pinging 1.1.1.1 with 32 bytes of data:Reply from 1.1.1.1: bytes=32 time=18ms TTL=59Reply from 1.1.1.1: bytes=32 time=21ms TTL=59Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),$ ping -a -n 1 8.8.8.8Pinging dns.google [8.8.8.8] with 32 bytes of data:Reply from 8.8.8.8: bytes=32 time=19ms TTL=117$ ping -6 -n 1 dns.googlePinging dns.google [2001:4860:4860::8888] with 32 bytes of data:Reply from 2001:4860:4860::8888: time=20ms$ ping -n 1 -l 70000 8.8.8.8Bad value for option -l, valid range is from 0 to 65500.$ ping -n 1 -f -l 1472 8.8.8.8Pinging 8.8.8.8 with 1472 bytes of data:Request timed out.Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),- -f -l 1472 timed out on the office network, so its path MTU is below 1500.
- Source-routed packets (-j 1.1.1.1 8.8.8.8) are mostly dropped on the internet: request timed out.
38.3 Linux ping: count, timing and deadlines
- -c count (otherwise it runs until Ctrl+C); -i interval; -q summary only.
- -W = wait for one reply; -w = deadline for the whole command (with -w 2 only 2 packets went out).
- No reply -> exit code 1.
- -f flood (500 packets in 95 ms), -A adaptive (next packet as soon as a reply arrives), -l 3 preload. Flood only in your own lab.
ping -c 3 192.168.58.130ping -c 5 -i 0.2 -q 192.168.58.130ping -c 3 -W 1 192.168.58.140ping -c 5 -w 2 192.168.58.140ping -f -c 500 192.168.58.130$ ping -c 3 192.168.58.130PING 192.168.58.130 (192.168.58.130) 56(84) bytes of data.64 bytes from 192.168.58.130: icmp_seq=1 ttl=62 time=10.2 ms64 bytes from 192.168.58.130: icmp_seq=2 ttl=62 time=0.173 ms64 bytes from 192.168.58.130: icmp_seq=3 ttl=62 time=0.121 ms3 packets transmitted, 3 received, 0% packet loss, time 2017msrtt min/avg/max/mdev = 0.121/3.487/10.168/4.723 ms$ ping -c 5 -i 0.2 -q 192.168.58.130PING 192.168.58.130 (192.168.58.130) 56(84) bytes of data.--- 192.168.58.130 ping statistics ---5 packets transmitted, 5 received, 0% packet loss, time 813msrtt min/avg/max/mdev = 0.092/0.151/0.232/0.048 ms$ ping -c 3 -W 1 192.168.58.1403 packets transmitted, 0 received, 100% packet loss, time 2053ms[exit 1]$ ping -c 5 -w 2 192.168.58.1402 packets transmitted, 0 received, 100% packet loss, time 1010ms[exit 1]$ ping -f -c 500 192.168.58.130500 packets transmitted, 500 received, 0% packet loss, time 95msrtt min/avg/max/mdev = 0.015/0.046/9.136/0.407 ms, ipg/ewma 0.190/0.253 ms38.4 Linux ping: address family, interface and routing
- Step 1
1.PC pings the LAN broadcast 192.168.58.63: ping refuses and asks for -b
- Step 2
2.With -b one Echo Request goes to the switch
- Step 3
3.Switch floods it to Host 2 (192.168.58.20) and Router 1 (192.168.58.1)
- Step 4
4.Both reply: summary shows +2 duplicates
- -I eth0 sends from that interface (or -I <ip> as source, -I vrf-blue to use a VRF's table).
- Link-local IPv6 (fe80::) needs %eth0 because fe80 exists on every interface.
- -r bypasses routing: a host on the same LAN replies, the server behind routers does not.
- Others: -4/-6, -B sticky source, -L multicast loopback off, -m firewall mark, -C connect().
ping -c 2 -I eth0 192.168.58.130ping -6 -c 2 fe80::243f:c3ff:feca:d6dc%eth0ping -b -c 2 192.168.58.63ping -r -c 1 192.168.58.20ping -r -c 1 192.168.58.130$ ping -c 2 -I eth0 192.168.58.130PING 192.168.58.130 (192.168.58.130) from 192.168.58.10 eth0: 56(84) bytes of data.64 bytes from 192.168.58.130: icmp_seq=1 ttl=62 time=0.189 ms$ ping -6 -c 2 fe80::243f:c3ff:feca:d6dc%eth064 bytes from fe80::243f:c3ff:feca:d6dc%eth0: icmp_seq=1 ttl=64 time=0.841 ms$ ping -c 2 192.168.58.63ping: Do you want to ping broadcast? Then -b. If not, check your local firewall rules$ ping -b -c 2 192.168.58.63WARNING: pinging broadcast address64 bytes from 192.168.58.10: icmp_seq=1 ttl=64 time=2.33 ms64 bytes from 192.168.58.1: icmp_seq=1 ttl=64 time=2.46 ms64 bytes from 192.168.58.20: icmp_seq=1 ttl=64 time=2.47 ms2 packets transmitted, 2 received, +2 duplicates, 0% packet loss$ ping -r -c 1 192.168.58.201 packets transmitted, 1 received, 0% packet loss, time 0ms$ ping -r -c 1 192.168.58.1301 packets transmitted, 0 received, 100% packet loss, time 0ms[exit 1]38.5 Linux ping: packet content, IP header and Path MTU (-M)
- -s data bytes (default 56; -s 1000 makes a 1028-byte IP packet).
- -Q sets TOS (tos 0xb8 seen in tcpdump), -e sets the ICMP id (1234), -t sets TTL (-t 1 -> Time to live exceeded from Router 1).
- -p pad pattern, -S socket buffer, -F IPv6 flow label.
- -M do = DF set; -M want / dont = may fragment; -M probe = real DF probe every time.
ping -c 1 -Q 0xb8 192.168.58.130ping -c 1 -e 1234 192.168.58.130# on srv: tcpdump -n -v -i eth0 icmpping -c 1 -M do -s 1472 192.168.58.130ping -c 1 -M want -s 1472 192.168.58.130ip route flush cacheping -c 1 -M probe -s 1472 192.168.58.130srv$ tcpdump -n -v -i eth0 icmpIP (tos 0xb8, ttl 62, id 17455, offset 0, flags [DF], proto ICMP (1), length 84) 192.168.58.10 > 192.168.58.130: ICMP echo request, id 238, seq 1, length 64IP (tos 0x0, ttl 62, id 18010, offset 0, flags [DF], proto ICMP (1), length 84) 192.168.58.10 > 192.168.58.130: ICMP echo request, id 1234, seq 1, length 64$ ping -c 1 -M do -s 1472 192.168.58.130PING 192.168.58.130 (192.168.58.130) 1472(1500) bytes of data.From 192.168.58.1 icmp_seq=1 Frag needed and DF set (mtu = 1400)$ ping -c 1 -M do -s 1472 192.168.58.130ping: local error: message too long, mtu=1400$ ping -c 1 -M want -s 1472 192.168.58.1301480 bytes from 192.168.58.130: icmp_seq=1 ttl=62 time=0.304 ms$ ip route flush cache$ ping -c 1 -M probe -s 1472 192.168.58.130From 192.168.58.1 icmp_seq=1 Frag needed and DF set (mtu = 1400)1 packets transmitted, 0 received, +1 errors, 100% packet lossThe second -M do fails locally (message too long) because the kernel has already cached path MTU 1400 for this route.
38.6 IP options (-R, -T) and IPv6 Node Information (-N)
- Step 1
1.PC records 192.168.58.10 as the packet leaves
- Step 2
2.Router 1 adds 192.168.58.65, Router 2 adds 192.168.58.129
- Step 3
3.Server adds 192.168.58.130 and replies
- Step 4
4.On the way back Router 2 adds 192.168.58.66, Router 1 adds 192.168.58.1
- Step 5
5.PC prints all 8 addresses under RR
ping -c 1 -R 192.168.58.130ping -c 1 -T tsandaddr 192.168.58.130$ ping -c 1 -R 192.168.58.130PING 192.168.58.130 (192.168.58.130) 56(124) bytes of data.64 bytes from 192.168.58.130: icmp_seq=1 ttl=62 time=0.121 msRR: 192.168.58.10 192.168.58.65 192.168.58.129 192.168.58.130 192.168.58.130 192.168.58.66 192.168.58.1 192.168.58.10$ ping -c 1 -T tsandaddr 192.168.58.130TS: 192.168.58.10 63078910 absolute 192.168.58.1 0 192.168.58.66 0 192.168.58.130 0Unrecorded hops: 3- -T tsonly = timestamps only; tsandaddr = address + timestamp; tsprespec = timestamps from listed hosts only.
- Many internet routers drop packets carrying IP options.
- -N (RFC 4620 Node Information Query) asks an IPv6 node for its name or addresses; the Linux kernel does not answer, so querying Router 1 gave 100% loss.
38.7 Linux ping: output control and scripts
ping -c 3 -D -O -i 0.5 192.168.58.140ping -c 1 -W 1 192.168.58.140 \ >/dev/null && echo up || echo down$ ping -c 3 -D -O -i 0.5 192.168.58.140[1794159084.671554] no answer yet for icmp_seq=1[1794159085.183530] no answer yet for icmp_seq=2[1794159087.199580] From 192.168.58.66 icmp_seq=1 Destination Host Unreachable3 packets transmitted, 0 received, +3 errors, 100% packet loss$ ping -c 1 -W 1 192.168.58.130 >/dev/null && echo up || echo downup$ ping -c 1 -W 1 192.168.58.140 >/dev/null && echo up || echo downdown- -D Unix timestamp per line, -O reports 'no answer yet' for missing replies (good for monitoring).
- Exit 0 = a reply came, 1 = no reply: scripts use ping as an up/down check.
- Others: -n numeric, -a beep, -H force reverse DNS, -U user-to-user latency, -v verbose, -V version.
38.8 macOS ping and ping6
| Option | macOS ping | macOS ping6 |
|---|---|---|
| Count / interval / first reply | -c / -i / -o | -c / -i / -o |
| Timeout for whole run | -t 10 | - |
| Wait per reply | -W 500 (ms) | - |
| TTL / hop limit | -m 10 | -h 10 |
| Don't Fragment | -D | -D |
| Size sweep | -g start -G max -h step | -G max,min,step |
| Bind interface / source | -b en0 / -S ip | -B en0 or %en0 / -S ip |
| Beep each packet / no reply | -a / -A | -r / -R |
| Traffic class / service type | -k / -K | -k / -K |
| Extra | -M mask, -M time (ICMP request type) | -a, -w Node Information queries |
ping -D -g 1400 -G 1500 -h 4 8.8.8.8 -k CLASS traffic class (default CTL) BK_SYS BK BE RD OAM AV RV VI VO CTL-K TYPE network service type BK_SYS BK BE RV AV RD OAM VI SIG VO-K VI -k VO service type + explicit class exit 0 = reply came, 2 = no reply- The sweep with -D finds the exact MTU point by growing the payload step by step.
- macOS -R (record route) is now a no-op; Ctrl+T prints current statistics.
- -f and -l need root; interval below 0.002 s needs root.
38.9 Common mistakes
| Letter | Windows | Linux | macOS |
|---|---|---|---|
| -t | Non-stop ping | Sets TTL | Timeout (seconds) |
| -f | Don't Fragment | Flood | Flood |
| -l | Data size | Preload | Preload |
| -s | Timestamp per hop | Data size | Data size |
- Assuming a failed ping means the server is down: many firewalls block ICMP while the website works.
- Assuming ping OK means the app is up: check the service with curl or a port check.
- Running a flood ping on a shared network.
- Forgetting %eth0 on a link-local IPv6 address.
38.10 Interview tips
- Path MTU with ping: DF + big packet (Win -f -l, Linux -M do -s, macOS -D -s), shrink until replies come; size + 28 = path MTU (lab: 1400).
- -t means non-stop on Windows, TTL on Linux, timeout on macOS.
- Reply TTL hints at the hop count (Linux starts at 64, Windows at 128).
- Use the exit code (0/1) of ping for scripted up/down checks.