ping

networkLinux/Unix
The ping command is one of the most frequently used commands in Linux/Unix-like operating systems. ping Send ICMP ECHO_REQUEST to network hosts

Quick Reference

Command Name:

ping

Category:

network

Platform:

Linux/Unix

Basic Usage:

ping [options] [arguments]

Common Use Cases

    Syntax

    ping [options] destination

    Options

    Option Description
    -4 Use IPv4 only
    -6 Use IPv6 only
    -a Audible ping
    -A Adaptive ping
    -b Allow pinging a broadcast address
    -B Do not allow ping to change source address
    -c count Stop after sending count packets
    -D Print timestamp before each line
    -d Set SO_DEBUG option
    -f Flood ping (requires root privileges)
    -i interval Wait interval seconds between sending each packet
    -I interface Specify interface to use
    -l preload Send preload number of packages while waiting for responses
    -n Numeric output only, no hostname resolution
    -p pattern Up to 16 'pad' bytes to fill out the packet
    -q Quiet output - only show summary
    -R Record route
    -s packetsize Specify the number of data bytes to send
    -S sndbuf Set socket sndbuf
    -t ttl Set time to live
    -T timestamp Set special IP timestamp options
    -v Verbose output
    -w deadline Specify a timeout, in seconds, before ping exits
    -W timeout Time to wait for a response, in seconds

    Examples

    How to Use These Examples

    The examples below show common ways to use the ping command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    ping google.com
    Send ICMP echo requests to google.com until interrupted.
    ping -c 4 192.168.1.1
    Send 4 ICMP echo requests to the specified IP address.
    # Advanced Examples Advanced
    ping -i 2 -c 5 example.com Send 5 pings with 2 second intervals. ping -s 1500 server.example.com Send pings with a packet size of 1500 bytes. ping -f server.example.com Flood ping (send packets as fast as possible). ping -I eth0 192.168.1.100 Specify the network interface to use. ping -4 example.com Force using IPv4. ping -6 example.com Force using IPv6. ping -q -c 10 -w 5 server.example.com Quiet output, 10 pings, exit after 5 seconds. ping -D -c 5 example.com Print timestamp before each line.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The ping command is one of the most fundamental and widely used network diagnostic tools. It sends ICMP (Internet Control Message Protocol) Echo Request packets to a target host and listens for ICMP Echo Reply messages. The name is derived from active sonar terminology, where a "ping" is the sound made to detect objects underwater. Developed by Mike Muuss in December 1983 as a tool to troubleshoot network issues on early ARPANET, ping has become an essential utility for network administrators, system engineers, and even everyday users to verify basic network connectivity. Key features of the ping command include: 1. Network Reachability Testing: The primary function of ping is to determine if a host is reachable across an IP network, making it the first tool used when troubleshooting network connectivity issues. 2. Round-Trip Time Measurement: Ping reports the round-trip time (RTT) for each packet, providing valuable information about network latency and performance. 3. Packet Loss Detection: By sending multiple packets, ping can reveal if any packets are being lost in transit, which may indicate network congestion or other problems. 4. Path MTU Discovery: With specific options, ping can help discover the Maximum Transmission Unit (MTU) along the network path, which is useful for optimizing packet sizes. 5. DNS Resolution Testing: Since ping typically resolves hostnames to IP addresses before sending packets, it can also indirectly test if DNS resolution is working correctly. 6. IPv4 and IPv6 Support: Modern implementations of ping support both IPv4 and IPv6 protocols, allowing for testing of both network types. 7. Multiple Output Formats: Ping can provide verbose output with detailed timing information or simplified summaries, depending on the options used. Common use cases for ping include: - Verifying basic network connectivity to remote hosts - Testing whether a server or network device is operational - Measuring network latency and stability - Identifying packet loss in network paths - Troubleshooting network routing problems - Performing long-term network monitoring - Testing DNS resolution functionality - Diagnosing local network adapter issues While ping is incredibly useful, it's worth noting that many networks and hosts block ICMP traffic for security reasons. As a result, a lack of ping response doesn't necessarily mean a host is unreachable through other protocols like HTTP or SSH. This limitation has led to the development of complementary tools like traceroute/tracert, mtr, and application-specific connection tests. The ping command is available on virtually all operating systems with networking capabilities, including Linux, Unix, macOS, Windows, and embedded systems, though the specific options and behavior may vary slightly between implementations. For security-conscious network administrators, it's important to understand that responding to ping requests can potentially expose information about network infrastructure. Many organizations implement selective filtering of ICMP traffic at network boundaries while still allowing internal ping operations for network diagnostics.

    Related Commands

    These commands are frequently used alongside ping or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the ping command works in different scenarios.

    $ ping
    View All Commands