Use Ping Command in Linux with Best 9 Examples – OrcaCore
In this comprehensive guide, we will explore How To Use Ping Command in Linux. The Ping command is a fundamental command-line utility, ubiquitous across operating systems with network capabilities. It serves as a diagnostic tool to verify the reachability of a networked device.
The ping command operates by sending a request across the network to a specified device. A successful ping operation results in a response, known as an echo reply, from the targeted computer back to the originating computer.
The ping command empowers you to:
- Diagnose network connectivity issues.
- Measure round-trip time for network packets.
- Verify hostname resolution.
- Troubleshoot network latency.
Let’s dive into practical examples demonstrating the power of the ping command in Linux. The ping command is a very useful tool.
To understand the workings of the ping command, follow the examples below, derived from Linux commands tutorials.
1. Ping Command Examples General Syntax
The basic syntax of the ping command involves the command itself, followed by either a hostname (e.g., a website address) or a numerical IP address.
ping [option] [hostname] or [IP address]
For instance, to ping the OrcaCore website, you would use:
ping orcacore.com

The output provides valuable information:
icmp_seq
: Indicates the sequence number of the ICMP (Internet Control Message Protocol) packets sent.TTL
: Stands for "time to live." It’s a value in the ICMP packet header that prevents packets from endlessly looping between hosts. Each hop decrements the TTL value.Time
: Represents the round-trip time (RTT) in milliseconds, measuring the duration for the packet to reach the host and return to the sender. Lower values indicate better network performance.
To terminate the ping process in Linux, press "Ctrl + C." The command will then display a summary of the transmission, including the number of packets transmitted and received, packet loss percentage, and the total time elapsed.
Note: If you do not receive a ping reply, it suggests a lack of network connectivity between your device and the target server.
2. Check Local Network With Ping Command
If you encounter difficulties reaching a website or a remote machine, pinging localhost can help determine if you have a basic network connection. You can use one of the following three equivalent commands to check the local network interface:
# ping 0
# ping localhost
# ping 127.0.0.1
These commands will produce identical results.
3. Change Interval Time Between Ping Packets
The default interval between consecutive ping requests is one second. You can modify this interval using the -i
switch.
To decrease the ping interval, specify a value less than 1. For example:
ping -i 0.5 orcacore.com
This command sends ping requests every 0.5 seconds.
To increase the ping interval, use a value greater than 1:
ping -i 1.5 orcacore.com
This command sends ping requests every 1.5 seconds.
4. Change Packet Size with Ping Command
The default packet size for ping requests is 56 bytes (84 bytes including the IP and ICMP headers). You can adjust this size using the -s
option. For instance:
ping -s 1000 orcacore.com
This command is useful for network performance testing. You can assess whether a network link experiences throttling when the packet size is increased significantly.
5. Flood the Network with Ping Command
To evaluate network performance under heavy load, the ping command can be used to flood the network with packets.
sudo ping -f orcacore.com
The ping -f
(flood) option requires root privileges to execute. Using sudo
before the ping
command enables this functionality. This command sends a large number of packets as rapidly as possible. Use with caution, as it can potentially disrupt network services.
6. Specify the Internet Protocol in the Ping Command
To explicitly request either an IPv6 or IPv4 address, include the -6
or -4
flag, respectively, after the ping
command and before the hostname or IP address.
# ping -6 hostname/IPv6
# ping -4 hostname/IPv4
7. Limit Number of Packets
By default, the ping command continues sending packets indefinitely until manually stopped. To limit the number of packets sent, use the -c
option.
For example:
ping -c 2 orcacore.com
In this case, the ping command will send only two packets and then automatically terminate.
8. Set a Time Limit for Ping Command
To automatically stop the ping process after a specified duration, use the -w
option.
For instance, to stop printing ping results after 25 seconds, execute:
ping -w 25 orcacore.com
9. Get an Audible Ping
An audible ping can be useful in situations where you are troubleshooting network issues and want to be alerted to responses without constantly monitoring the screen.
The -a
switch causes the system to play a sound when a response is received from a host. For example:
ping -a google.com
The output will resemble that of a standard ping command, but a sound will be played upon receiving each response.
Conclusion
This guide has provided a comprehensive overview of How To Use Ping Command In Linux with Examples. The ping command in Linux is a versatile tool for verifying network connectivity and diagnosing network issues. By sending ICMP echo requests, it allows you to measure response times and packet loss, providing valuable insights into network performance. The ping command can be customized.
Alternative Solutions for Network Connectivity Testing
While ping
is a widely used and effective tool, alternative methods exist for testing network connectivity and diagnosing network issues. Here are two such approaches:
1. Using traceroute
(or tracepath
)
traceroute
(or its simpler counterpart tracepath
) provides a more detailed view of the network path between your system and a target host. Unlike ping
, which simply confirms reachability and round-trip time, traceroute
displays each hop (router) along the route, along with the response time for each hop. This can be invaluable for identifying where network latency or connectivity problems are occurring.
Explanation: traceroute
works by sending packets with progressively increasing TTL (Time-To-Live) values. The first packet has a TTL of 1, causing it to expire at the first router. This router sends back an ICMP "Time Exceeded" message, revealing its IP address and response time. Subsequent packets have higher TTLs, allowing them to reach subsequent routers, and so on, until the destination is reached or a maximum hop limit is exceeded.
Code Example:
traceroute orcacore.com
The output will show a list of routers along the path to orcacore.com, along with the round-trip time for each hop. High latency at a particular hop indicates a potential bottleneck or problem at that point in the network.
2. Using nc
(netcat) for Port Scanning and Connection Testing
nc
(netcat) is a powerful utility for reading from and writing to network connections using TCP or UDP. While not specifically designed for network connectivity testing in the same way as ping
or traceroute
, it can be used to verify that a specific port on a remote host is open and accepting connections. This is particularly useful for testing the availability of specific services, such as web servers (port 80 or 443) or SSH servers (port 22).
Explanation: nc
can attempt to establish a TCP connection to a specified host and port. If the connection is successful, it indicates that the port is open and the service is running. If the connection fails, it suggests that the port is blocked, the service is not running, or there is a network connectivity issue preventing the connection.
Code Example:
nc -zv orcacore.com 80
In this example:
-z
: Specifies zero-I/O mode, which means thatnc
will only attempt to establish a connection without sending or receiving any data.-v
: Enables verbose output, providing more information about the connection attempt.orcacore.com
: The target hostname.80
: The port number to test (in this case, the standard HTTP port).
If the command is successful, the output will indicate that the connection was established. If it fails, it will indicate that the connection was refused or timed out.