linux/ping

Test Network Connectivity

Test the reachability of a network host and measure round-trip time for packets sent to it.

network
diagnostics
connectivity
icmp
linux

Command

ping

Explanation

The `ping` command is a basic network diagnostic tool used to check the reachability of a host on an IP network. It measures the round-trip time of packets sent from the source to a destination and back. Common options include `-c` to specify the number of pings, and `-i` to define the interval between packets.

Common Use Cases

  • Check if a remote host is reachable
  • Diagnose network latency issues
  • Test connectivity between servers or devices

Best Practices

  • Use `-c` to limit packet count in scripts
  • Ping IP address first if DNS resolution is in doubt

Common Mistakes to Avoid

  • Running without specifying a target host
  • Misinterpreting high latency as packet loss

Troubleshooting

Problem: No response from host

Solution: Ensure host is online and ICMP is not blocked by a firewall.

Problem: Name or service not known

Solution: Verify DNS resolution or use an IP address directly.

Examples

Test connection to Google

ping google.com

Send 4 ICMP echo requests to Google's DNS

ping -c 4 8.8.8.8