How To Use Ping Command in Linux

In this guide, we intend to teach you How To Use Ping Command in Linux.

Ping is a command-line utility, available on virtually any operating system with network connectivity, that acts as a test to see if a networked device is reachable.

The ping command sends a request over the network to a specific device. A successful ping results in a response from the computer that was pinged back to the originating computer.

The ping command allows you to:

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

Use Ping Command in Linux with Examples

To see how the ping command works, follow the steps below from the Linux commands tutorials.

General Syntax of Ping Command

The basic syntax of the ping command is followed by a hostname, a name of a website, or the exact IP address.

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

For example, ping

PING (2a06:98c1:3121::8)) 56 data bytes
64 bytes from 2a06:98c1:3121::8 (2a06:98c1:3121::8): icmp_seq=1 ttl=57 time=36.7 ms
64 bytes from 2a06:98c1:3121::8 (2a06:98c1:3121::8): icmp_seq=2 ttl=57 time=27.6 ms
64 bytes from 2a06:98c1:3121::8 (2a06:98c1:3121::8): icmp_seq=3 ttl=57 time=27.6 ms

You will get various information such as:

icmp_seq: It is used to show the sequence number of packets sent

TTL: TTL means “time to live“. It is a value on an ICMP packet that prevents that packet from propagating back and forth between hosts ad infinitum.

Time: The ping time, measured in milliseconds, is the round trip time for the packet to reach the host and for the response to return to the sender.

To stop the ping process in Linux, press “Ctrl C”, the command will tell the number of packets it transmitted/received, the number of packets lost, and the time.

--- ping statistics ---
12 packets transmitted, 12 received, 0% packet loss, time 11017ms
rtt min/avg/max/mdev = 27.573/28.462/36.722/2.498 ms

Note: If you don’t get a ping reply, then there is no network connectivity between your device and the host server.

Check Local Network With Ping Command

At this point, if you get issues reaching a website or a remote machine, you can ping localhost to confirm you have a network connection. To do this, you can use one of the three ways to check the local network interface:

# ping 0
# ping localhost
# ping

The results will be the same.

PING 0 ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=0.091 ms
64 bytes from icmp_seq=2 ttl=64 time=0.048 ms
64 bytes from icmp_seq=3 ttl=64 time=0.049 ms
64 bytes from icmp_seq=4 ttl=64 time=0.037 ms

Change Interval Time Between Ping Packets

The default interval between each ping request is set to one second. You can increase or decrease that time using the -i switch.

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

ping -i 0.5

To increase the ping interval, enter any value higher than 1 in the Ping command in your Linux server. For example:

ping -i 1.5

Change packet Size with Ping Command

At this point, if you want to change the default 56 (84) packet size, you can use the -s option in the ping command. For example:

ping -s 1000
PING (2a06:98c1:3120::8)) 1000 data bytes
1008 bytes from 2a06:98c1:3120::8 (2a06:98c1:3120::8): icmp_seq=2 ttl=57 time=28.9 ms

This command is useful when testing network performance. You can test if a network link throttles when you increase the packet size to a few thousand bytes.

Flood the Network with Ping Command

To check the performance of the network under heavy load, the ping command can also be used to flood the network.

sudo ping -f

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.

Specify the Internet Protocol in the Ping command

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

# ping -6 hostname/IPv6 
# ping -4 hostname/IPv4 

Limit Number of Packets

The Ping command keeps on sending packets until it is manually stopped. But you can easily set it to a certain number of packets by using the -c option in the ping command.

For example:

ping -c 2
PING (2a06:98c1:3121::8)) 56 data bytes
64 bytes from 2a06:98c1:3121::8 (2a06:98c1:3121::8): icmp_seq=1 ttl=57 time=30.2 ms
64 bytes from 2a06:98c1:3121::8 (2a06:98c1:3121::8): icmp_seq=2 ttl=57 time=27.6 ms

--- ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 27.619/28.930/30.241/1.311 ms

As you can see in the output, the Ping command stopped sending packets after two requests in Linux.

Set a Time Limit for Ping Command

To stop receiving a ping output after a specific amount of time, you can use the -w option in your ping command.

For example, to stop printing ping results after 25 seconds, run the command below:

ping -w 25

Get an Audible Ping 

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.

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

For example:

ping -a

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

The following image is shown the common options used for the ping command.

Ping command options in Linux


At this point, you learn to Use Ping Command In Linux with Examples.

Hope you enjoy it.

You may be like these articles:

Monitor Linux Network Bandwidth Usage with nload Command

How To Find the CPU Information on Centos 7

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!