コンテンツにスキップ

ping - Network Connectivity Testing

Comprehensive ping commands and network connectivity testing across Windows, Linux, and macOS.

Basic Usage

Simple Connectivity Test

Platform Command Description
All ping hostname Basic connectivity test
All ping 8.8.8.8 Test with Google DNS
All ping google.com Test with domain name

Platform-Specific Differences

Feature Windows Linux/macOS
Default count 4 packets Continuous
Stop continuous N/A Ctrl+C
IPv6 ping -6 ping6 or ping -6

Advanced Options

Packet Count and Timing

Platform Command Description
Windows ping -n 10 hostname Send 10 packets
Linux/macOS ping -c 10 hostname Send 10 packets
Windows ping -t hostname Continuous ping
Linux/macOS ping hostname Continuous (default)

Packet Size and Interval

Platform Command Description
Windows ping -l 1024 hostname Set packet size to 1024 bytes
Linux/macOS ping -s 1024 hostname Set packet size to 1024 bytes
Windows ping -w 5000 hostname Timeout in milliseconds
Linux/macOS ping -W 5 hostname Timeout in seconds
Linux/macOS ping -i 2 hostname 2-second interval between packets

Advanced Testing

Platform Command Description
All ping -f hostname Flood ping (requires root on Linux/macOS)
Linux/macOS ping -D hostname Print timestamp
Linux/macOS ping -a hostname Audible ping
Windows ping -a hostname Resolve hostname to IP

IPv6 Support

IPv6 Ping Commands

Platform Command Description
Windows ping -6 hostname IPv6 ping
Linux ping6 hostname IPv6 ping (traditional)
Linux ping -6 hostname IPv6 ping (modern)
macOS ping6 hostname IPv6 ping

IPv6 Examples

# Test IPv6 connectivity
ping6 google.com
ping6 2001:4860:4860::8888  # Google DNS IPv6

# Windows IPv6
ping -6 google.com
ping -6 2001:4860:4860::8888

Network Diagnostics

MTU Discovery

Platform Command Description
Windows ping -f -l 1472 hostname Test MTU (don't fragment)
Linux/macOS ping -M do -s 1472 hostname Test MTU (don't fragment)

Route Testing

# Test specific route
ping -R hostname  # Record route (Linux/macOS)
ping -r hostname  # Record route (Windows, limited)

# Test with specific interface
ping -I eth0 hostname  # Linux
ping -S source_ip hostname  # Windows

Troubleshooting

Common Issues and Solutions

Problem Symptoms Solution
Request timeout No response Check firewall, network connectivity
Destination unreachable ICMP error Check routing, DNS resolution
Permission denied Flood ping fails Use sudo/administrator privileges
Name resolution failed Unknown host Check DNS settings

Diagnostic Commands

# Test local connectivity
ping 127.0.0.1        # Loopback test
ping localhost        # Local hostname test

# Test gateway
ping $(route -n get default|grep gateway|awk '\\\\{print $2\\\\}')  # macOS
ping $(ip route|grep default|awk '\\\\{print $3\\\\}')             # Linux
ping $(ipconfig|findstr "Default Gateway"|awk '\\\\{print $NF\\\\}') # Windows

# Test DNS
ping 8.8.8.8          # Google DNS
ping 1.1.1.1          # Cloudflare DNS

Performance Analysis

Statistics Interpretation

Metric Description Good Value
RTT (Round Trip Time) Time for packet round trip < 50ms local, < 200ms internet
Packet Loss Percentage of lost packets 0% ideal, < 1% acceptable
Jitter Variation in RTT < 10ms

Continuous Monitoring

# Long-term monitoring
ping -c 1000 hostname > ping_results.txt  # Linux/macOS
ping -n 1000 hostname > ping_results.txt  # Windows

# Monitor with timestamps
ping hostname|while read line; do echo "$(date): $line"; done  # Linux/macOS

Scripting and Automation

Bash Scripting Examples

#!/bin/bash
# Network connectivity checker

hosts=("google.com" "github.com" "stackoverflow.com")

for host in "$\\\\{hosts[@]\\\\}"; do
    if ping -c 1 "$host" &> /dev/null; then
        echo "✓ $host is reachable"
    else
        echo "✗ $host is unreachable"
    fi
done

PowerShell Examples

# PowerShell network test
$hosts = @("google.com", "github.com", "stackoverflow.com")

foreach ($host in $hosts) \\\\{
    if (Test-Connection -ComputerName $host -Count 1 -Quiet) \\\\{
        Write-Host "✓ $host is reachable" -ForegroundColor Green
    \\\\} else \\\\{
        Write-Host "✗ $host is unreachable" -ForegroundColor Red
    \\\\}
\\\\}

Security Considerations

Firewall and ICMP

  • Many firewalls block ICMP traffic
  • Some networks disable ping responses
  • Use alternative tools if ping is blocked

Rate Limiting

  • Avoid flood pings on production networks
  • Respect network policies and rate limits
  • Use appropriate intervals for monitoring

Best Practices

Network Testing

  1. Start Simple: Begin with basic ping to known hosts
  2. Test Layers: Test IP, then DNS, then application
  3. Document Results: Keep logs of network tests
  4. Use Multiple Targets: Test various destinations
  5. Consider Time: Network performance varies by time

Monitoring

  1. Baseline: Establish normal performance metrics
  2. Alerting: Set up alerts for packet loss or high latency
  3. Trending: Track performance over time
  4. Correlation: Correlate with other network metrics
  5. Documentation: Document network topology and expected performance