Linux ping Command


Introduction

In world of networking, ability to check if a networked device is reachable or not is a basic requirement. One of tools that can help us achieve this is ping command. ping command is a tool that sends a signal to a specified networked device, and then waits for a response. ping command is available in almost all operating systems, including Linux. In this article, we will explore Linux ping command in detail, including its syntax, options, and examples.

What is ping command in Linux?

The ping command in Linux is a utility that helps to test connectivity between two devices on a network. ping command sends a request to a specified device and waits for a response. response from device helps us to determine whether device is available or not. ping command uses ICMP (Internet Control Message Protocol) packets to communicate with target device.

Syntax of ping command

The syntax of ping command is as follows −

ping [options] [destination]
  • Options − options are arguments that can be passed to ping command to modify its behavior. There are many options available for ping command, which we will explore in detail later in article.

  • Destination − destination is IP address or hostname of device that we want to test connectivity with.

Basic usage of ping command

The basic usage of ping command is as follows −

ping <destination>

This command will send ICMP packets to specified destination, and then wait for a response. ping command will continue to send ICMP packets until it receives a response or until it is stopped manually.

Ping command options

The ping command has many options that can be used to modify its behavior. Some of commonly used options are −

  • -c count -c option is used to specify number of ICMP packets that ping command should send. syntax for using -c option is as follows −

ping -c <count> <destination>

For example, to send five ICMP packets to IP address 192.168.0.1, we can use following command −

ping -c 5 192.168.0.1
  • -i interval -i option is used to specify interval between sending ICMP packets. syntax for using -i option is as follows −

ping -i <interval> <destination>

For example, to send ICMP packets every 5 seconds to IP address 192.168.0.1, we can use following command −

ping -i 5 192.168.0.1
  • -t ttl -t option is used to specify TTL (Time To Live) value for ICMP packets. TTL value determines how many network hops ICMP packets can make before they expire. syntax for using -t option is as follows −

ping -t <ttl> <destination>

For example, to set TTL value to 64 for ICMP packets sent to IP address 192.168.0.1, we can use following command −

ping -t 64 192.168.0.1
  • -s packetsize -s option is used to specify size of ICMP packets that ping command should send. default size of ICMP packets is 64 bytes. syntax for using -s option is as follows −

ping -s <packetsize> <destination>

For example, to send ICMP packets of size 100 bytes to IP address 192.168.0.1, we can use following command −

ping -s 100 192.168.0.1
  • -v -v option is used to enable verbose mode. When verbose mode is enabled, ping command will display more information about ICMP packets being sent and received. syntax for using -v option is as follows −

ping -v <destination>
  • -f -f option is used to enable "flood" mode. When flood mode is enabled, ping command will send ICMP packets as fast as possible, without waiting for a response. syntax for using -f option is as follows −

ping -f <destination>

Note − -f option should be used with caution, as it can cause network congestion.

  • -q -q option is used to enable quiet mode. When quiet mode is enabled, ping command will not display ICMP packets being sent and received. syntax for using -q option is as follows −

ping -q <destination>

Examples of ping command −

  • To test connectivity to a specific device −

ping 192.168.0.1

This command will send ICMP packets to IP address 192.168.0.1 and wait for a response.

  • To test connectivity and limit number of ICMP packets −

ping -c 5 192.168.0.1

This command will send 5 ICMP packets to IP address 192.168.0.1 and then stop.

  • To test connectivity and change interval between ICMP packets −

ping -i 5 192.168.0.1

This command will send ICMP packets to IP address 192.168.0.1 every 5 seconds.

  • To test connectivity and set TTL value for ICMP packets −

ping -t 64 192.168.0.1

This command will set TTL value to 64 for ICMP packets sent to IP address 192.168.0.1.

  • To test connectivity and change size of ICMP packets −

ping -s 100 192.168.0.1

This command will send ICMP packets of size 100 bytes to IP address 192.168.0.1.

  • To test connectivity and enable verbose mode −

ping -v 192.168.0.1

This command will enable verbose mode and display more information about ICMP packets being sent and received.

  • To test connectivity and enable flood mode −

ping -f 192.168.0.1

This command will enable flood mode and send ICMP packets as fast as possible.

Conclusion

The ping command is a useful tool for testing connectivity between networked devices. It is available on almost all operating systems, including Linux. ping command uses ICMP packets to communicate with target device and provides many options to modify its behavior. In this article, we have explored syntax and options of ping command, as well as provided several examples of how to use it. By using ping command, network administrators can quickly test connectivity and troubleshoot network issues.

Updated on: 24-Mar-2023

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements