What it is
ping is a network utility used to test the reachability of a host on an Internet Protocol (IP) network and to measure the round-trip time for messages sent from the originating host to a destination computer.
Installation
Linux
ping is usually pre-installed on most Linux distributions. If not, you can install it using your distribution’s package manager:
Debian/Ubuntu:
sudo apt update
sudo apt install iputils-ping
Fedora/CentOS/RHEL:
sudo dnf install iputils
# or
sudo yum install iputils
macOS
ping is pre-installed on macOS.
Windows
ping is pre-installed on Windows. You can access it via Command Prompt (cmd.exe) or PowerShell.
Commands / Usage
Basic Reachability Testing
Send ICMP ECHO_REQUEST packets to a host.
ping google.com
Tests if google.com is reachable and shows the round-trip time for each packet.
ping 8.8.8.8
Tests if the IP address 8.8.8.8 (Google’s public DNS server) is reachable.
Controlling Packet Count
Specify the number of packets to send.
ping -c 5 google.com
Sends exactly 5 ICMP packets to google.com and then stops.
ping -n 10 192.168.1.1
(Windows) Sends exactly 10 ICMP packets to 192.168.1.1 and then stops.
Setting Interval Between Packets
Specify the time interval in seconds between sending each packet.
ping -i 2 google.com
Sends ICMP packets to google.com with a 2-second delay between each packet.
ping -i 0.5 google.com
Sends ICMP packets to google.com with a 0.5-second delay between each packet.
Setting Packet Size
Specify the number of data bytes to be sent. The default is usually 56 bytes, plus 8 bytes for the ICMP header, totaling 64 bytes.
ping -s 1000 google.com
Sends ICMP packets with 1000 bytes of data to google.com. Note that the total packet size will be larger due to ICMP and IP headers.
ping -l 1024 192.168.1.1
(Windows) Sends ICMP packets with 1024 bytes of data to 192.168.1.1.
Setting Time To Live (TTL)
Specify the maximum number of hops the packet can travel before being discarded.
ping -t 10 google.com
Sends ICMP packets to google.com with a TTL of 10. This is useful for tracing network paths.
ping -ttl 15 192.168.1.1
(Windows) Sends ICMP packets to 192.168.1.1 with a TTL of 15.
Flooding the Network (Use with Caution!)
Send packets as fast as possible.
ping -f google.com
(Requires root/administrator privileges) Sends ICMP packets to google.com as fast as the network can handle. This can overload the network and the target host.
Pinging a Specific Network Interface
Specify the source IP address or interface to send the ping from.
ping -I eth0 google.com
Sends ICMP packets to google.com using the eth0 network interface.
ping -S 192.168.1.100 google.com
Sends ICMP packets to google.com originating from the IP address 192.168.1.100.
Receiving and Sending Specific ICMP Types
Specify the ICMP type and code to send. Primarily used for advanced diagnostics or testing specific network device behaviors.
ping -T 8 google.com
(Linux) Sends an ICMP Echo Request (type 8, code 0) to google.com. This is the default behavior.
ping -T 0 google.com
(Linux) Sends an ICMP Echo Reply (type 0, code 0) to google.com. This is generally not useful for standard reachability tests.
Other Useful Flags
ping -v google.com
Verbose mode. Shows more detailed information about the ICMP packets being sent and received.
ping -q google.com
Quiet mode. Only displays a summary of statistics at the end.
ping -a google.com
(Windows) Attempts to resolve the hostname from the IP address of replies.
ping -r 4 google.com
(Windows) Records the route taken by each packet. The output may show up to 4 hops.
ping -w 5000 google.com
(Windows) Specifies a timeout in milliseconds to wait for each reply. If no reply is received within 5000ms (5 seconds), the packet is considered lost.
ping -W 5 google.com
(Linux) Specifies a timeout in seconds to wait for each reply. If no reply is received within 5 seconds, the packet is considered lost.
Common Patterns
Continuous Ping Until Interrupted
Ping a host indefinitely until you manually stop it (Ctrl+C).
ping google.com
(Linux/macOS)
ping -t google.com
(Windows)
Checking for Packet Loss to a Specific Host
Send a moderate number of packets and check the loss percentage.
ping -c 50 google.com
Sends 50 packets and then shows statistics including packet loss.
Basic Network Troubleshooting (Gateway)
Ping your default gateway to check local network connectivity.
ping 192.168.1.1
(Replace 192.168.1.1 with your actual gateway IP)
Checking DNS Resolution and Reachability
Ping a hostname and an IP address for the same service to differentiate between DNS issues and network reachability issues.
ping www.example.com
ping 93.184.216.34
If pinging the hostname fails but pinging the IP succeeds, it suggests a DNS problem.
Testing Bandwidth (with large packets)
While not a true bandwidth test, sending large packets can reveal network saturation or issues with high-volume traffic.
ping -s 1400 google.com
(Linux/macOS) Sends packets close to the typical MTU size (1500 bytes) for Ethernet.
ping -l 1400 google.com
(Windows)
Continuous Ping with Timeout
Ping a host for a specific duration.
# Linux/macOS: Ping for 60 seconds
timeout 60 ping google.com
# Windows: Ping for 60 seconds (send 10 packets every second)
# This is less direct, requires a loop or external script for precise duration.
# A common approach is to set a packet count.
ping -n 60 google.com
Gotchas
- Permissions for Flood Ping: The
-f(flood) option on Linux/macOS typically requires root privileges. Without them, you’ll get a "Operation not permitted" error. - Firewalls: ICMP packets (which
pinguses) can be blocked by firewalls. Ifpingfails, it doesn’t always mean the host is down; it could be that ICMP is being filtered. - Windows vs. Linux/macOS Flags: The syntax for some options differs between Windows (
-n,-l,-t,-w) and Linux/macOS (-c,-s,-i,-W). Be mindful of your operating system. - Packet Size Interpretation: The
-s(Linux/macOS) or-l(Windows) flag specifies the data payload size. The total packet size sent over the network will be larger due to ICMP and IP headers. - "Destination Host Unreachable" vs. Timeout:
- Timeout: The sender never received a reply within the expected time. This can be due to network congestion, routing issues, or the destination host being down/unreachable.
- Destination Host Unreachable: An intermediate router or the destination host itself explicitly sent back an ICMP "Destination Unreachable" message. This often indicates a more specific routing or network configuration problem.
ping -t(Windows) Behavior: The Windows-tflag means "ping continuously" until interrupted, not "set TTL to t". This is a common point of confusion.- MTU Discovery:
pingdoesn’t perform Path MTU Discovery by default. For large packets, you might need to use the "Don’t Fragment" (DF) bit if available in yourpingversion (e.g.,ping -M do google.comon Linux) to diagnose MTU issues. - Return Codes:
pingtypically returns an exit code of0if successful (at least one reply received) and non-zero if unsuccessful (no replies, or an error occurred). This is useful in scripting.