Ping Command in Linux with Examples

Ping Command in Linux
Ping Command in Linux

Ping Command is cross-platform and most popular utility used to troubleshoot network related problems. PING stands for Packet INternet Grouper mostly used for checking connectivity between two network nodes. Mainly used to check if the host is reachable or not.

By using this command you can check whether the host is active or not. If it’s active it will reply back otherwise the destination is inactive.

Basicaly Ping command sends ICMP packets to the destination server or host and then waists for a response. After receiving a response from the destination which is echo packets, it will again send packets to the destination.

Basic Syntax of Ping Command

Following is the basic syntax for Ping command:

ping [options] destination

Where,
options: Options which are given here.
destination: Destination website or the IP address.

Ping Command Examples

Following are the examples for ping command in Linux.

1. Basic use of ping command

Let’s check if www.google.com is reachable or not by sending ICMP packets. To stop receiving packates press Ctrl+c:

ping www.google.com

The output should be:

Ping command examples - Basic Use
Ping command examples – Basic Use

In the above command, ping command starts to send ICMP packages to a destination IP address. Then prints the output responded by the destination server.

2. Change Interval Between Ping Packets

By using -i option you can change the interval between two ping packets sent to the destination server. You can change the default interval using this option. For example, if you want to send packates after every 2 second then use below command:

ping -i 2 linux4one.com

The output should be:

Ping Command Linux - Pinging After Each 2 Seconds
Ping Command Linux – Pinging After Each 2 Seconds

You can see the above command pings the destination server after every 2 seconds. You should press CTRL+c to stop pinging.

3. Limit Number of Packets

To limit the number of packets using the ping command -c option is used. You can specify any number of packets to send to the destination server. It will automatically stop after completing sending the given number of packets. Here you may not need to press CTRL+c to stop pinging.

For example, run below command to send only 4 packets to the destination server linux4one.com and stop it:

ping -c 4 linux4one.com

The output should be:

Ping Command Linux - Limit Pings
Ping Command Linux – Limit Pings

4. Specify Packet Size

By default ping command will send packets of size 56 bytes. To change this packets size you can use -s option.

Run below command to send packets of size 75 to destination server:

ping -s 75 127.0.0.1

The output should be:

Ping Command Linux - Specify Packet Size
Ping Command Linux – Specify Packet Size

5. Ping With Sound

Ping command can play a beep when a packet is received, by using -a option. This option plays a beep each a packet is received.

Run below command to ping with beep:

ping -a www.google.com

Press Ctrl+c to stop sending packets.

6. Specify Timeout for Ping

You can limit how much time the ping command should run using -w option. It will exit or stop the ping command after the given time.

In below example, ping command will stop sending packets after 3.5 seconds:

ping -w www.google.com

The output should be:

Linux ping command - Timeout
Linux ping command – Timeout

Flood network using Ping

You can also send more than 100 packets per second using ping command. To do such things -f option is used with the ping command. If this option can only be used with sudo privileges.

For example, to send more than 100 packets per second you can use below command, remember to press Ctrl+c to interrupt below command:

ping -f www.google.com

The output should be:

Ping Command Linux - Flood
Ping Command Linux – Flood

Conclusion

You have successfully learned Linux Ping command with examples. If you have any queries please don’t forget to comment below.

1 COMMENT

  1. You can put this in your bashrc file:
    alias ping=”ping -cX”
    where X is an integer of your choice. Now you don’t have to Ctrl + C to stop execution. Of course you can add whatever other options you want as well. Very handy.

LEAVE A REPLY

Please enter your comment!
Please enter your name here