Ping Cheat Sheet

Basic Ping Usage
Command Description Real-World Example
ping hostname Basic ping command to test connectivity to a host
    Input:  ping google.com
    Output: PING google.com (142.250.69.110) 56(84) bytes of data.
            64 bytes from mia07s58-in-f14.1e100.net (142.250.69.110): icmp_seq=1 ttl=116 time=15.2 ms
            64 bytes from mia07s58-in-f14.1e100.net (142.250.69.110): icmp_seq=2 ttl=116 time=15.4 ms
            
ping ip_address Ping an IP address directly
    Input:  ping 8.8.8.8
    Output: PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
            64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=12.3 ms
            64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=12.1 ms
            
ping -c 4 hostname Send a specific number of ping packets
    Input:  ping -c 4 example.com
    Output: PING example.com (93.184.216.34) 56(84) bytes of data.
            64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=120.1 ms
            64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=119.6 ms
            64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=120.3 ms
            64 bytes from 93.184.216.34: icmp_seq=4 ttl=56 time=119.8 ms
            
            --- example.com ping statistics ---
            4 packets transmitted, 4 received, 0% packet loss, time 3005ms
            rtt min/avg/max/mdev = 119.590/119.946/120.311/0.287 ms
            
Ctrl+C Interrupt and stop a running ping command
    Input:  [Press Ctrl+C while ping is running]
    Effect: Stops ping and shows summary statistics
            
Ping Syntax Overview
Command Description Real-World Example
ping [options] destination General syntax for ping command
    Input:  ping -c 5 -i 2 -s 1000 google.com
    Effect: Sends 5 ping packets of 1000 bytes each with 2-second intervals to google.com
            
man ping Display the manual page for ping to view all options
    Input:  man ping
    Effect: Displays the manual with all available ping options and their descriptions
            
ping --help Display brief help for ping command
    Input:  ping --help
    Effect: Shows a summary of ping command options
            
Specifying Packet Count
Command Description Real-World Example
ping -c count host Send a specific number of ping packets (Linux/macOS)
    Input:  ping -c 6 cloudflare.com
    Effect: Sends exactly 6 ping packets and then stops
            
ping -n count host Send a specific number of ping packets (Windows)
    Input:  ping -n 6 cloudflare.com
    Effect: Sends exactly 6 ping packets and then stops (Windows command)
            
ping host Send ping packets continuously (until stopped with Ctrl+C)
    Input:  ping github.com
    Effect: Continuously pings github.com until manually stopped
            
Setting Ping Interval
Command Description Real-World Example
ping -i seconds host Wait specified seconds between sending each packet
    Input:  ping -i 5 example.com
    Effect: Sends a ping packet every 5 seconds instead of the default 1 second
            
ping -i 0.2 host Send packets faster than 1 second (requires root/admin)
    Input:  sudo ping -i 0.2 192.168.1.1
    Effect: Sends 5 ping packets per second (privileged users only)
            
ping -i seconds -c count host Combine interval with count for limited monitoring
    Input:  ping -i 10 -c 6 google.com
    Effect: Sends 6 ping packets with 10-second intervals between each
            
Setting Timeout per Reply
Command Description Real-World Example
ping -W seconds host Set time to wait for each response (Linux)
    Input:  ping -W 2 slowserver.example.com
    Effect: Waits up to 2 seconds for each reply before timing out
            
ping -w timeout host Set time to wait for each response (macOS)
    Input:  ping -w 2000 example.com
    Effect: Waits up to 2000 milliseconds for each reply (macOS)
            
ping -w timeout -c count host Combine timeout with count for efficient testing
    Input:  ping -W 1 -c 10 192.168.1.100
    Effect: Sends 10 packets with a 1-second timeout for each response
            
Setting Overall Timeout
Command Description Real-World Example
ping -w seconds host Set a deadline/timeout for the entire ping operation (Linux)
    Input:  ping -w 10 example.com
    Effect: Runs ping for 10 seconds total, then exits regardless of packet count
            
ping -t seconds host Set a deadline timeout for the entire ping operation (macOS)
    Input:  ping -t 15 example.com
    Effect: Stops ping after 15 seconds total execution time
            
timeout seconds ping host Use the timeout command to limit any command’s runtime
    Input:  timeout 30 ping google.com
    Effect: Runs ping for up to 30 seconds then terminates it
            
Changing Packet Size
Command Description Real-World Example
ping -s size host Specify the size of packets sent (in bytes)
    Input:  ping -s 1000 google.com
    Effect: Sends ping packets with 1000 bytes of data (plus 8 byte ICMP header)
            
ping -s 1472 host Test maximum packet size without fragmentation
    Input:  ping -s 1472 192.168.1.1
    Effect: Tests if the path can handle maximum sized packets (1500 byte MTU)
            
ping -s size -c count host Send specific sized packets a limited number of times
    Input:  ping -s 2000 -c 5 example.com
    Effect: Sends 5 large packets (2000 bytes each) to test network capacity
            
Flood Mode
Command Description Real-World Example
ping -f host Send packets as fast as possible (flood ping, requires root)
    Input:  sudo ping -f 192.168.1.1
    Effect: Sends many packets per second with minimal output (just dots/backspaces)
            
ping -f -c count host Limit flood ping to a specific number of packets
    Input:  sudo ping -f -c 100 192.168.1.1
    Effect: Sends 100 packets in rapid succession and stops
            
ping -f -i interval host Flood ping with a delay (not truly flood)
    Input:  sudo ping -f -i 0.1 192.168.1.1
    Effect: Sends packets with 0.1 second intervals (10 per second)
            
Audible Ping
Command Description Real-World Example
ping -a host Produce a bell sound (BEL) when a packet is received
    Input:  ping -a 8.8.8.8
    Effect: Beeps on each successful ping response (useful for audio monitoring)
            
ping -a -i 2 host Audible ping with longer interval between packets
    Input:  ping -a -i 2 example.com
    Effect: Beeps every 2 seconds when responses are received
            
ping -a -O host Audible ping with report of outstanding packets
    Input:  ping -a -O google.com
    Effect: Beeps on responses and shows outstanding packets
            
Set TTL (Time to Live)
Command Description Real-World Example
ping -t ttl host Set Time-To-Live value on outgoing packets (Linux)
    Input:  ping -t 5 google.com
    Effect: Packets expire after passing through 5 routers
            
ping -m ttl host Set TTL value on macOS
    Input:  ping -m 10 example.com
    Effect: Sets the TTL to 10 hops (macOS syntax)
            
ping -i ttl host Set TTL value on Windows
    Input:  ping -i 64 8.8.8.8
    Effect: Sets the TTL to 64 hops (Windows syntax)
            
ping -t 1 host Perform a simple traceroute-like function
    Input:  ping -t 1 example.com
    Effect: Shows the first hop (router) in the path to the destination
            
Specifying Source IP or Interface
Command Description Real-World Example
ping -I interface host Specify the source interface for ping packets
    Input:  ping -I eth0 8.8.8.8
    Effect: Sends ping packets from the eth0 interface
            
ping -I source_ip host Specify the source IP address for ping packets
    Input:  ping -I 192.168.1.5 example.com
    Effect: Uses 192.168.1.5 as the source IP address for the ping
            
ping -S source_ip host Set source address on some systems (macOS)
    Input:  ping -S 10.0.0.5 8.8.8.8
    Effect: Sets 10.0.0.5 as the source IP (macOS syntax)
            
Force IPv4 or IPv6
Command Description Real-World Example
ping -4 host Force using IPv4
    Input:  ping -4 google.com
    Effect: Only uses IPv4 to connect to the target
            
ping -6 host Force using IPv6
    Input:  ping -6 google.com
    Effect: Only uses IPv6 to connect to the target
            
ping6 host Use the dedicated IPv6 ping command (on some systems)
    Input:  ping6 ipv6.google.com
    Effect: Sends IPv6 ping packets to the target
            
Record Route
Command Description Real-World Example
ping -R host Record the route packets take (may not work on all systems)
    Input:  ping -R example.com
    Effect: Records and displays the route that packets take to reach the destination
            
ping -R -c 1 host Record route for a single packet
    Input:  ping -R -c 1 8.8.8.8
    Effect: Shows the route for a single ping packet
            
traceroute host Alternative to -R (use traceroute command instead)
    Input:  traceroute google.com
    Effect: Shows the complete route to the destination
            
Timestamps in Output
Command Description Real-World Example
ping -D host Print timestamp before each line
    Input:  ping -D google.com
    Output: [1621789234.567890] 64 bytes from 142.250.69.110: icmp_seq=1 ttl=116 time=15.2 ms
            [1621789235.569012] 64 bytes from 142.250.69.110: icmp_seq=2 ttl=116 time=15.4 ms
            
ping -T tsonly host Print timestamp only (no other information)
    Input:  ping -T tsonly google.com
    Effect: Shows only timestamp information for each packet
            
ping -T tsandaddr host Print timestamps and addresses
    Input:  ping -T tsandaddr 8.8.8.8
    Effect: Shows timestamps and addresses for each router along the path
            
Quiet Mode / Statistics Only
Command Description Real-World Example
ping -q host Quiet output – only displays summary when finished
    Input:  ping -q -c 10 google.com
    Output: PING google.com (142.250.69.110) 56(84) bytes of data.
            
            --- google.com ping statistics ---
            10 packets transmitted, 10 received, 0% packet loss, time 9013ms
            rtt min/avg/max/mdev = 14.807/15.122/15.665/0.282 ms
            
ping -q -c count host Quiet output with specific packet count
    Input:  ping -q -c 5 8.8.8.8
    Effect: Silently sends 5 packets and only shows the final statistics
            
ping -q -w seconds host Quiet output with deadline timeout
    Input:  ping -q -w 10 example.com
    Effect: Quietly pings for 10 seconds and then shows summary statistics
            
Limit Ping Rate
Command Description Real-World Example
ping -i seconds host Wait specified seconds between sending each packet
    Input:  ping -i 3 example.com
    Effect: Sends ping packets every 3 seconds instead of the default 1 second
            
ping --flood --preload=50 host Send specified number of packets before starting to listen for replies
    Input:  sudo ping --flood --preload=50 192.168.1.1
    Effect: Sends 50 packets immediately, then continues in flood mode
            
ping --adaptive host Adaptive ping – interval adapts to round-trip time
    Input:  ping --adaptive google.com
    Effect: Automatically adjusts ping interval based on response times
            
Custom Payload Data
Command Description Real-World Example
ping -p pattern host Fill ICMP packet with specified hex pattern
    Input:  ping -p ff 8.8.8.8
    Effect: Fills the ping packet with 0xFF bytes (all bits set)
            
ping -p deadbeef host Specify a custom hex pattern
    Input:  ping -p deadbeef google.com
    Effect: Fills the packet with the hex pattern 0xDEADBEEF
            
ping -p pattern -s size host Custom pattern with specific size
    Input:  ping -p ff -s 1000 example.com
    Effect: Sends 1000-byte packets filled with 0xFF bytes
            
Setting Don’t Fragment Flag
Command Description Real-World Example
ping -M do host Set the Don’t Fragment flag in the IP header
    Input:  ping -M do -s 1500 example.com
    Effect: Sends 1500-byte packets with DF flag set (to test MTU)
            
ping -M do -s 1472 host Test for MTU black holes in the network path
    Input:  ping -M do -s 1472 8.8.8.8
    Effect: Tests if large packets can traverse the path without fragmentation
            
ping -M dont host Prohibit fragmentation (similar to -M do)
    Input:  ping -M dont -s 1500 192.168.1.1
    Effect: Prohibits fragmentation for testing maximum packet sizes
            
Privileged vs Unprivileged Ping
Command Description Real-World Example
sudo ping options host Run ping with root privileges
    Input:  sudo ping -f 8.8.8.8
    Effect: Allows use of flood mode which requires root privileges
            
ping -i 0.2 host Send pings faster than 1 second (requires root)
    Input:  sudo ping -i 0.2 example.com
    Effect: Sends 5 pings per second (needs root privileges)
            
sudo sysctl -w net.ipv4.ping_group_range="0 0" Allow unprivileged users to use ICMP sockets (Linux)
    Input:  sudo sysctl -w net.ipv4.ping_group_range="0 0"
    Effect: Enables all users to use ping without requiring sudo
            
Understanding Ping Output Statistics
Output Item Description Real-World Example
icmp_seq Sequence number of the packet
    Output: 64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=14.5 ms
    Meaning: This is the first packet in the sequence
            
ttl Time to Live value of the received packet
    Output: 64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=15.0 ms
    Meaning: The packet had a TTL of 117 when it arrived
            
time Round-trip time in milliseconds
    Output: 64 bytes from 8.8.8.8: icmp_seq=3 ttl=117 time=14.8 ms
    Meaning: It took 14.8 milliseconds for the packet to reach the destination and return
            
packets transmitted Total number of packets sent
    Output: 5 packets transmitted, 5 received, 0% packet loss, time 4006ms
    Meaning: 5 ping packets were sent from your system
            
packets received Total number of packets that returned successfully
    Output: 5 packets transmitted, 5 received, 0% packet loss, time 4006ms
    Meaning: All 5 packets sent were received back
            
packet loss Percentage of packets that didn’t return
    Output: 5 packets transmitted, 4 received, 20% packet loss, time 4006ms
    Meaning: 1 out of 5 packets (20%) was lost in transit
            
rtt min/avg/max/mdev Round-trip time statistics
    Output: rtt min/avg/max/mdev = 14.776/15.015/15.137/0.193 ms
    Meaning: Minimum RTT: 14.776ms, Average: 15.015ms, Maximum: 15.137ms, Mean deviation: 0.193ms
            
Common Ping Error Messages
Error Message Description Troubleshooting
Destination Host Unreachable Local router knows the route but can’t deliver the packet
    Output: From 192.168.1.1 icmp_seq=1 Destination Host Unreachable
    Solution: Check if the target host is powered on and connected to the network
            
Request Timed Out No response was received within the timeout period
    Output: Request timed out.
    Solution: Check connectivity, firewall settings, or try increasing timeout
            
Unknown host Hostname cannot be resolved to an IP address
    Output: ping: unknown host example.invalid
    Solution: Verify hostname is correct, check DNS settings
            
Operation not permitted User doesn’t have permissions to create raw sockets
    Output: ping: socket: Operation not permitted
    Solution: Run with sudo/administrator privileges or adjust system settings
            
Packet filtered Packets are being blocked by a firewall
    Output: From 192.168.1.1 icmp_seq=1 Packet filtered
    Solution: Check firewall settings on both source and destination
            
Network is unreachable No route exists to the target network
    Output: ping: connect: Network is unreachable
    Solution: Check if gateway is configured, VPN is connected, or network interface is up
            
Ping Sweeps (Multiple Targets)
Command Description Real-World Example
for i in {1..254}; do ping -c 1 192.168.1.$i; done Basic ping sweep of a subnet using Bash loop
    Input:  for i in {1..254}; do ping -c 1 -W 1 192.168.1.$i | grep "64 bytes"; done
    Effect: Pings all IPs in 192.168.1.0/24 subnet and shows only successful responses
            
nmap -sn 192.168.1.0/24 Use Nmap for efficient ping sweep
    Input:  nmap -sn 192.168.1.0/24
    Effect: Performs ping sweep of entire subnet and shows hosts that are up
            
fping -g 192.168.1.1 192.168.1.254 Use fping for faster ping sweeps
    Input:  fping -g 192.168.1.1 192.168.1.254
    Effect: Pings all addresses in the range and reports status
            
Alternatives and Related Tools
Command Description Real-World Example
traceroute host Trace the route packets take to a host
    Input:  traceroute google.com
    Effect: Shows all routers in the path to google.com
            
mtr host Combines functionality of ping and traceroute
    Input:  mtr 8.8.8.8
    Effect: Shows a real-time, continuously updated traceroute with ping statistics
            
fping hosts Ping multiple hosts efficiently
    Input:  fping google.com yahoo.com example.com
    Effect: Pings multiple hosts in parallel and reports results
            
arping ip_address Ping hosts using ARP packets (layer 2)
    Input:  arping -I eth0 192.168.1.1
    Effect: Sends ARP requests rather than ICMP echo requests
            
hping3 host Advanced ping tool for custom packet creation
    Input:  hping3 -S -p 80 example.com
    Effect: Send TCP SYN packets to port 80 instead of ICMP
            
nmap -sP network/cidr Network discovery using ping
    Input:  nmap -sP 192.168.1.0/24
    Effect: Scans the entire subnet to discover active hosts
            
Troubleshooting with Ping
Scenario Commands to Try Interpretation
Basic Connectivity Test ping 8.8.8.8
    Command: ping 8.8.8.8
    Success: Internet connectivity is working at ICMP level
    Failure: Network connection, router, or ISP issue
            
DNS Resolution Test ping google.com
    Command: ping google.com
    Success: Both DNS resolution and internet connectivity work
    Failure: If 8.8.8.8 works but domain doesn't, indicates DNS issue
            
Local Network Test ping 192.168.1.1 (gateway address)
    Command: ping default gateway
    Success: Local network connectivity is working
    Failure: Network adapter or local network issue
            
Packet Loss Analysis ping -c 100 host
    Command: ping -c 100 server.example.com
    Result: 5% packet loss
    Meaning: Network has quality issues - congestion or hardware problems
            
Latency Analysis ping host (observe time values)
    Command: ping cloud-server.example.com
    Result: time=150ms with high variation
    Meaning: High latency with jitter - might affect real-time applications
            
MTU Issues ping -M do -s 1472 host
    Command: ping -M do -s 1472 example.com
    Failure: "Message too long"
    Meaning: Path MTU is smaller than 1500 bytes, indicating a potential MTU issue
            
Security Implications
Security Aspect Description Recommendation
Firewall ICMP Blocking Many firewalls block ICMP echo requests for security
    Issue: Host may be up but not responding to ping
    Note: Lack of ping response doesn't mean a service is down
    Alternative: Try connecting to specific service ports (e.g., HTTP/80)
            
ICMP Flood Attacks Flooding a host with ping packets can cause DoS
    Risk: Ping flood can consume bandwidth or server resources
    Mitigation: Configure rate limiting for ICMP on network equipment
    Example: iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j ACCEPT
            
Network Discovery Ping sweeps can reveal active hosts
    Risk: Attackers use ping to map networks before attacks
    Mitigation: Consider selective ICMP filtering at your network edge
    Best practice: Block external pings to internal hosts, but allow internal ping
            
Privileged Access Ping traditionally requires raw socket access
    Issue: Running ping often requires root/administrator privileges
    Solution: Modern Linux systems allow unprivileged ping via capabilities
    Configuration: sysctl -w net.ipv4.ping_group_range="0 0"
            
Different Ping Versions
Platform/Implementation Notable Features Examples
Linux iputils-ping Comprehensive feature set with many options
    Features: Flood ping, timestamp, pattern filling, preload
    Example: ping -f -c 100 -i 0.01 192.168.1.1
    Version check: ping -V
            
BSD/macOS ping Different flags from Linux version
    Features: Some options vary from Linux (e.g., -i for interval)
    Example: ping -c 5 -i 2 -s 1000 example.com
    Note: Use man ping to check options specific to your system
            
Windows ping More limited feature set than Unix versions
    Features: Basic functionality with fewer options
    Example: ping -n 4 -l 1000 -w 5000 example.com
    Note: -n (count), -l (size), -w (timeout in ms)
            
Busybox ping Minimal implementation for embedded systems
    Features: Limited options optimized for size
    Example: ping -c 4 192.168.1.1
    Common in: Routers, IoT devices, minimal Linux distributions
            
Using Ping in Scripts
Script/Command Purpose Example
Check if host is up Simple connectivity test in a script
    Bash script:
    if ping -c 1 -W 1 8.8.8.8 > /dev/null; then
        echo "Network is up"
    else
        echo "Network is down"
    fi
            
Monitor connection stability Continuously log ping results to a file
    Bash script:
    while true; do
        date >> ping_log.txt
        ping -c 10 example.com | grep -A 2 "ping statistics" >> ping_log.txt
        sleep 60
    done
            
Parse ping output programmatically Extract specific metrics from ping results
    Bash/awk:
    # Extract average ping time
    avg_ping=$(ping -c 4 google.com | grep 'avg' | awk -F'/' '{print $5}')
    echo "Average ping: $avg_ping ms"
            
Check multiple hosts Ping several hosts and report status
    Bash script:
    hosts=("google.com" "cloudflare.com" "example.com")
    for host in "${hosts[@]}"; do
        if ping -c 1 -W 2 $host > /dev/null; then
            echo "$host is up"
        else
            echo "$host is down"
        fi
    done
            
Alert on connectivity issues Send notification when ping fails
    Bash script:
    while true; do
        if ! ping -c 3 8.8.8.8 > /dev/null; then
            echo "Alert: Internet connection down!" | mail -s "Network Alert" admin@example.com
        fi
        sleep 300
    done
            
Platform Differences
Platform Option Differences Examples
Linux -c (count), -i (interval), -W (timeout), -s (size)
    Count:   ping -c 5 example.com
    Interval: ping -i 2 example.com
    Timeout:  ping -W 2 example.com
    Size:     ping -s 1000 example.com
            
macOS/BSD -c (count), -i (interval), -W (per-packet timeout in ms), -t (ttl)
    Count:   ping -c 5 example.com
    Interval: ping -i 2 example.com
    Timeout:  ping -W 2000 example.com (milliseconds)
    TTL:      ping -t 64 example.com
            
Windows -n (count), -w (timeout in ms), -l (size), -i (ttl)
    Count:   ping -n 5 example.com
    Timeout:  ping -w 2000 example.com
    Size:     ping -l 1000 example.com
    TTL:      ping -i 64 example.com
            
Network Equipment (Cisco) Different syntax, using keywords instead of flags
    Basic:    ping 192.168.1.1
    Count:    ping 192.168.1.1 repeat 5
    Size:     ping 192.168.1.1 size 1000
    Extended: ping ip 192.168.1.1 df-bit size 1500 timeout 2
            
Android Limited subset via terminal apps, lacks some advanced options
    Basic:   ping google.com
    Count:   ping -c 5 google.com
    Note: Requires terminal app or ADB access
            
iOS Only via third-party apps, no built-in terminal
    Method: Use network utility apps from App Store
    Note: Native ping command not accessible to users
            

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart