WebMasterCampus
WEB DEVELOPER Resources

Linux ping Command

Learn Linux ping Command with examples


Linux ping Command

In Linux, we can use “ping” command is a simple utility used to check whether a network is available and if a host is reachable.

ping Command Syntax

>> ping [option] [hostname] or [IP address]

The ping command allows you to check following.

  • Check if a remote machine is online.
  • Analyze if there are network issues, such as dropped packages or high latency.
  • Test your internet connection.

ping Command Example

>> ping google.com

Press Ctrl + C on your keyboard to stop the process.

Output Options Description
from The destination and its IP address. Note that the IP address may be different for a website depending on your geographical location.
icmp_seq=1 The sequence number of each ICMP packet. Increases by one for every subsequent echo request.
ttl=52 The Time to Live value from 1 to 255. It represents the number of network hops a packet can take before a router discards it.
time=7.68 ms The time it took a packet to reach the destination and come back to the source. Expressed in milliseconds.

ping Command Execution

  • your machine starts sending ICMP echo requests and waits for a response. If the connection is established, you receive an echo reply for every request.
  • The output for the ping command contains the amount of time it takes for every packet to reach its destination and return.
  • The terminal keeps printing the responses until interrupted. After every session, there are a few lines with ping statistics.

ping 0 Command

ping 0 is the quickest way to ping localhost. Once you type this command, the terminal resolves the IP address and provides a response.

>> ping 0

ping localhost Command

ping localhost can use the name to ping localhost. The name refers to your computer, and when we use this command, we say: “ping this computer.”

>> ping localhost

ping 127.0.0.1 Command

ping 127.0.0.1 some people prefer using the IP address 127.0.0.1 to ping localhost.

>> ping 127.0.0.1 

ping IPv6 Address Command

To request IPv6 or IPv4 address, add -6 after the ping command and before a hostname/IP.

>> ping -6 hostname/IPv6

ping IPv4 Address Command

To request IPv6 or IPv4 address, add -4 after the ping command and before a hostname/IP.

>> ping -4 hostname/IPv4

ping -i Command (Change Time Interval Between Ping Packets)

The default interval between each ping request is set to one second.

If you want to increase or decrease that time using the -i switch.

To decrease the ping interval, use values lower than 1.

>> ping -i 0.5 google.com

To increase the ping interval, enter any value higher than 1.

ping -s Command (Change Ping Packet Size)

In some scenarios, you may want to use -s to increase the packet size from the default value of 56 (84) bytes.

The number in parenthesis represents the ping bytes sent including 28 bytes of the header packet.

>> ping -s 1000 google.com

ping -f Command (Flood a Network)

You can use ping flood to test your network performance under heavy load.

Ping flood -f option requires root to execute.

Otherwise, apply sudo to your ping command to flood a host. This command sends a large number of packets as soon as possible.

>> sudo ping -f hostname-IP

The output prints a dot for every sent package, and a backspace for every response. The statistics line shows a summary of the ping command.

ping -c Command (Limit the Number of Pings Packets)

The default setting for the ping command is to keep sending the request until you interrupt it. You can limit the number of pings using one of the two methods.

To make the ping command automatically stop after it sends a certain number of packets, use -c and a number. This sets the desired amount of ping requests, as shown in this example:

>> ping -c 2 google.com

As you can see on the image above, the ping command stopped sending packets after two requests.

ping -w Command (Set Time Limit for ping Command)

To stop receiving a ping output after a specific amount of time, add -w and an interval in seconds to your command.

For example, to stop printing ping results after 15 seconds, enter the ping command.

>> ping -w 15 google.com

ping -q Command

If you do not want to clog your screen with information for every packet, use the -q switch to display the summary only.

The -q option prints one line with the regular ping information and then provides the statistics at the end. The letter “q” in this command stands for “quiet” output.

>> ping -c 20 -q google.com

We usually combine the quiet output with other options. In this case, we will limit the ping to send 20

ping -D Command (Add Timestamp Before Each Line in ping Output)

If you want to note the time of day when you execute the ping command, add the -D option.

>> ping -D google.com

This prints a timestamp in UNIX format before each line.

ping -a Command (Get an Audible Ping When a Host is Reachable)

When you use the -a switch, the system plays a sound when there is a response from a host.

An audible ping is useful when you are troubleshooting network issues and do not want to look at the screen until there is a response.

>> ping -a google.com

The output looks the same as a regular ping command output.

ping -V Command (Show Ping Version and Exit)

At any time, you can check the version of the ping tool on your system.

Append -V to the ping command to display the version of this utility.

>> ping -V google.com

ping Command Options

Command Description
a Generates a sound when the peer can be reached.
b Allows to ping a broadcast IP address.
B Prevents the ping to change the source address of the probe.
c (count) Limits the number of sent ping requests.
d Sets the SO-DEBUG option on the used socket.
f Floods the network by sending hundreds of packets per second.
i (interval) Specifies an interval between successive packet transmissions. The default value is one second.
I (interface address) Sets the source IP address to the specified interface IP address. The option is required when pinging IPv6 link local address. You can use an IP address or name of the device.
l (preload) Defines the number of packets to send without waiting for a reply. To specify a value higher than 3; you need superuser permissions.
n Displays IP addresses in the ping output rather than hostnames.
q Shows a quiet output. One ping line is displayed and the summary of the ping command at the end.
T (ttl) Sets the Time To Live.
v Provides verbose output.
V Displays the ping version and exits to a new command prompt line.
w (deadline) Specifies a time limit before the ping command exits; regardless of how many packets have been sent or received.
W (timeout) Determines the time; in seconds; to wait for a response.
Created with love and passion.