×

ping Command in Linux/Unix with Examples

The "ping" command in Linux (and other Unix-like operating systems) is used to test the connectivity between two networked devices. The "ping" command sends a small packet of data, called an Internet Control Message Protocol (ICMP) echo request packet, to a specified network address and waits for a response. If the response is received, it indicates that the device is reachable and that the network connection is working properly. The "ping" command is often used to troubleshoot network connectivity issues and to check the reachability and response time of a device on a network.

The basic syntax of the "ping" command is:

ping [options] destination

The destination can be an IP address or a domain name.

When executed without any options, the "ping" command will send four ICMP echo request packets to the specified destination and display the response time for each packet. For example, the following command will send four ICMP echo request packets to the IP address "8.8.8.8":

ping 8.8.8.8

The "ping" command also has several options that can be used to control the behavior of the command. Some commonly used options are:

-c : specifies the number of packets to send. For example, the following command will send 10 ICMP echo request packets to the IP address "8.8.8.8":

ping -c 10 8.8.8.8

-i : specifies the time interval between packets in seconds. For example, the following command will send ICMP echo request packets to the IP address "8.8.8.8" with a time interval of 1 second:

ping -i 1 8.8.8.8

-t : specifies the time to live (TTL) value for the packets. The TTL value specifies the number of hops that a packet can make before it is discarded. For example, the following command will send ICMP echo request packets to the IP address "8.8.8.8" with a TTL value of 64:

ping -t 64 8.8.8.8

-W : specifies the timeout value in seconds. This option is used to set the amount of time to wait for a response before marking a packet as lost. For example, the following command will send ICMP echo request packets to the IP address "8.8.8.8" and wait for a response for 2 seconds:

ping -W 2 8.8.8.8

-s : specifies the packet size. This option allows you to specify the number of data bytes to be sent in each packet. For example, the following command will send ICMP echo request packets to the IP address "8.8.8.8" with a packet size of 128 bytes:

ping -s 128 8.8.8.8

-q : runs the command in quiet mode, which suppresses most of the output, leaving only the summary at the end. For example, the following command will send ICMP echo request packets to the IP address "8.8.8.8" and display only the summary at the end:

ping -q 8.8.8.8

The "ping" command is a widely used command for troubleshooting network connectivity issues in Linux and other Unix-like operating systems. Here are some additional features and uses of the "ping" command:

  • The "ping" command can be used to test the connectivity between a local device and a remote device on the internet. This is useful for verifying that the local device's internet connection is working properly and that the remote device is reachable.
  • The "ping" command can also be used to test the connectivity between two local devices on a LAN (Local Area Network). This can be useful for troubleshooting network connectivity issues within a LAN, such as verifying that a network printer or server is reachable.
  • The "ping" command can also be used to test the connectivity between a local device and a specific port on a remote device. This can be useful for troubleshooting network connectivity issues with specific services or applications running on the remote device.
  • The "ping" command can also be used in conjunction with other network troubleshooting tools such as traceroute (tracert in Windows) to identify the path that packets take between two networked devices. This can be useful for identifying and isolating network connectivity issues.
  • The "ping" command can also be used as a simple network monitoring tool. By running the command at regular intervals and recording the response times, it can be used to detect network performance issues or outages.

In summary, the "ping" command is a versatile command that can be used to test the connectivity between networked devices in Linux and other Unix-like operating systems. It can be used to test connectivity between local device and a remote device on the internet, between two local devices on a LAN, to test connectivity between a local device and a specific port on a remote device, in conjunction with other network troubleshooting tools, as a simple network monitoring tool. It is an essential tool for network administrators, developers, and other users to troubleshoot network connectivity issues, detect network performance issues or outages, and verify that network addresses are reachable.


Related Topics

Linux rmdir command

The default use case of the rmdir command in the Linux system is to delete an empty directory. The below screenshot shows how to delete the empty directory. First, we...

1 minute read.

Linux Commands List

Linux Commands List The Linux systems are filled with commands for several use cases. We have divided these commands into some of the most common implementations for a better understanding of...

2 minutes read.

touch Command in Linux/Unix with Examples

The "touch" command in Linux (and other Unix-like operating systems) is used to create new empty files or update the timestamps of existing files. The touch command is a simple...

4 minutes read.

tail Command in Linux/Unix with Examples

The "tail" command in Linux (and other Unix-like operating systems) is used to display the last few lines of a file. By default, the tail command will display the last...

4 minutes read.

echo Command in Linux/Unix with Examples

The "echo" command in Linux is used to display a line of text on the terminal. It can also be used to print the value of a variable or to...

3 minutes read.

pwd Command in Linux/Unix with Examples

The "pwd" command in Linux (and other Unix-like operating systems) stands for "print working directory." When executed, it simply displays the current directory (or folder) that the user is currently...

3 minutes read.

Linux Admin Tutorial

In publishing and graphic design, lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document without relying on meaningful content....

1 minute read.

sudo Command in Linux/Unix with Examples

The sudo command in Linux is used to run a command or set of commands with the privileges of another user, typically the root user. This allows users to perform...

3 minutes read.

Linux ls

The primary use case of the ls command is to list the content available in the directory. The default directory is the current directory of the user. The below screenshot...

5 minutes read.

grep Command in Linux/Unix with Examples

The grep command in Linux is a command-line utility that searches for patterns in text files. It stands for "global regular expression print" and it is used to search for...

5 minutes read.

scp Command in Linux/Unix with Examples

The scp (secure copy) command in Linux is a command-line utility that is used to securely transfer files between two hosts over a network. It is similar to the cp...

4 minutes read.

Linux Commands with Examples

Linux Commands with Examples All the Linux commands are executed on the terminal provided by the Linux system. This terminal is a command-line interface to implement and display command outputs. Linux...

10 minutes read.

man Command in Linux/Unix with Examples

The man command in Linux is used to display the manual pages for a given command or system call. These manual pages provide detailed information on the command's usage, options,...

3 minutes read.

How to change the ApacheHTTP port in Linux

What is an Apache HTTP server in Linux? When we talk about the most commonly used web servers, one of the web servers that cannot be missed is Apache. With the...

4 minutes read.

adduser Command in Linux with Examples

What is the adduser command? The adduser command creates a new user, and this command may be used to add apre-existing user to a group that already exists. How to use the...

4 minutes read.

mv Command in Linux/Unix with Examples

The 'mv' command in Linux is used to move or rename files and directories. The command stands for "move" and it allows you to move files and directories from one...

3 minutes read.

rename Command in Linux/Unix with Examples

The rename command in Linux is used to rename multiple files at once, using a specified pattern. The command is also known as rename, ren, and mv. This command is...

3 minutes read.

chown Command in Linux/Unix with Examples

The 'chown' command in Linux is used to change the ownership of a file or directory. The command stands for "change owner" and it allows you to change the user...

3 minutes read.

df Command in Linux/Unix with Examples

The 'df' command in Linux is used to display the amount of disk space available on the file system. The command reports the amount of disk space used and available...

3 minutes read.

cp Command in Linux/Unix with Examples

The cp (copy) command in Linux is a command-line utility that is used to copy files and directories. It is one of the most basic and commonly used commands in...

5 minutes read.