SkillPilotAI

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

OSCommandDefault behaviour
Windowsping.exe (built in)Stops after 4 packets, 32 bytes of data
Linuxiputils ping (IPv4 + IPv6)Runs until Ctrl+C, 56 data bytes
macOSping + separate ping6 for IPv6Runs until Ctrl+C, 56 data bytes
Echo Request and Echo Reply in the lab
  1. 1.PC 192.168.58.10 sends an Echo Request (TTL 64) to the switch

  2. 2.Router 1 forwards it, TTL 64 -> 63

  3. 3.Router 2 forwards it, TTL 63 -> 62

  4. 4.Server 192.168.58.130 receives it and sends an Echo Reply

  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

OptionMeaning
-n 2Number of echo requests (default 4)
-tPing non-stop until Ctrl+C
-w 1000Reply timeout in ms
-aResolve the IP to a name
-4 / -6Force IPv4 / IPv6
-l 1000Data size (default 32, max 65500)
-fDon't Fragment flag
-i 64Outgoing TTL (the server decides the reply TTL)
-vTOS (deprecated)
-SSource address
-r 4 / -s 4Record route (1-9 hops) / timestamp per hop (1-4), IPv4 only
-j / -kLoose / strict source route (max 9), not together
-c / -pRouting compartment / Hyper-V provider address
Terminal
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
Output
$ 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.
Terminal
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
Output
$ 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 ms

38.4 Linux ping: address family, interface and routing

Broadcast ping with -b
  1. 1.PC pings the LAN broadcast 192.168.58.63: ping refuses and asks for -b

  2. 2.With -b one Echo Request goes to the switch

  3. 3.Switch floods it to Host 2 (192.168.58.20) and Router 1 (192.168.58.1)

  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().
Terminal
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
Output
$ 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.
Terminal
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.130
Output
srv$ 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 loss

The 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)

Record route (-R): forward and return path in one ping
  1. 1.PC records 192.168.58.10 as the packet leaves

  2. 2.Router 1 adds 192.168.58.65, Router 2 adds 192.168.58.129

  3. 3.Server adds 192.168.58.130 and replies

  4. 4.On the way back Router 2 adds 192.168.58.66, Router 1 adds 192.168.58.1

  5. 5.PC prints all 8 addresses under RR

Terminal
ping -c 1 -R 192.168.58.130ping -c 1 -T tsandaddr 192.168.58.130
Output
$ 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

Terminal
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
Output
$ 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

OptionmacOS pingmacOS 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
Output
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

LetterWindowsLinuxmacOS
-tNon-stop pingSets TTLTimeout (seconds)
-fDon't FragmentFloodFlood
-lData sizePreloadPreload
-sTimestamp per hopData sizeData 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.