Javatpoint Logo
Javatpoint Logo

Linux ping Command

Linux ping command stands for (Packet Internet Groper). It checks connectivity between two nodes to see if a server is available. It sends ICMP ECHO_REQUEST packets to network hosts and displays the data on the remote server's response. It checks if a remote host is up, or that network interfaces can be reached. Further, it is used to check if a network connection is available between two devices. It is also handy tool for checking your network connection and verifying network issues.

Ping command keeps executing and sends the packet until you interrupt.

To stop the execution, press "CTRL+C" keys.

Syntax:

The ping command supports various command-line options. But, the basic syntax for the ping command is as follows:

Options:

The ping command supports the following command-line options:

-4: It used to use IPv4 only.

-6: It is used to use IPv6 only.

-a: It is used for the audible ping.

-A: It is used for an adaptive ping.

-b: It is used to ping a broadcast address.

-B: It is used for not changing the source address of probes.

-c count: It is used to stop after sending count ECHO_REQUEST packets.

-d: It is used to set the SO_DEBUG option on the socket being used.

-D: It is used to print the timestamp before each line.

-f: It stands for flood ping. It prints a period for every sent ECHO_REQUEST and backspaces for every received ECHO_REPLY.

-F flow label: It is used for IPv6 only. It allocates a 20-bit flow label (in hex) on echo request packets.

-h: It is used to display the help manual having a brief description of the usage and support options.

-i interval: It is used to specify the time interval in seconds between each packet. By default, it is set to one.

-I interface: It is used to specify the source interface.

-l preload: If preload is specified, it sends packets and does not wait for the reply. Only the super-user (user with sudo privilege) has the right to select preload more than.

-L: It is used to crush the loopback of multicast packets. It is useful for multicast destination addresses.

-m mark: It is used to tag the outgoing packets. It is useful for selecting policy routing in outbound processing.

-M pmtudisc_opt: It is used to select the Path MTU Discovery strategy.

-N nodeinfo_option: It is used for IPv6 only.

-n: It is used to display the numeric output.

-O: It is used to report outstanding ICMP ECHO reply before sending the next packet.

-p pattern: It allows us to specify up to 16 "pad'' bytes to fill out sent packets. It is useful for determining the "data-dependent problems in a network."

-q: It is used to quiet from the terminal.

-Q tos: It is used to set the quality of service-related bits in ICMP datagrams.

-r: It is used to bypass the normal routing tables. Further, it sends it directly to a host on an attached interface.

-R: It is used to record the route.

-s packet size: It is used to determine the number of data bytes to be sent. By default, it sents 56 bytes.

-S sndbuf: It is used to set socket sndbuf. If it is not specified, the buffer will not select more than one packet.

-t ttl: It is used for ping only, it sets the IP Time to Live.

-T timestamp option: It is used to set special IP timestamp options such as tsonly, tsandaddr, or tsprespec host1 [host2 [host3 [host4]]].

-U: It is used to display full user-to-user latency. Generally, the ping command displays the network round trip time.

-v: It prints the more detailed output.

-V: It is used to display version information.

-w deadline: It is used to specify a timeout, in seconds, before ping command exits.

-W timeout: It is used to specify the waiting time for a response in seconds.

Examples of the ping Command

Let' see the following examples of the ping command:

  • Ping Using DNS
  • Ping Using IP address
  • Limit the packets
  • Check if a remote host is up
  • Check IPv4 Connectivity
  • Check IPv6 Connectivity
  • Add a timestamp before each line
  • Specify the Source Interface
  • Change Time Interval Between Ping Packets

Ping using DNS

To check the connectivity using DNS, execute the command as follows:

Consider the below command:

The above command will ping the 'javatpoint.com.' Consider the below output:

Linux ping

Ping using IP address

We can use the IP address instead of DNS with a ping command. To use the IP address to ping a destination, execute the command as follows:

Consider the below command:

The above command will check the connectivity with the given IP address. Consider the below output:

Linux ping

Limit the packets

We can limit the number of sent packets by using the ping command. To limit the packet, specify the 'c' option followed by the number of packets to be sent. It will be executed as:

Consider the below command:

The above command will limit the packets up to 5. Consider the below output:

Linux ping

Check if a Remote Host is up.

To check if a remote host is up, execute the ping command, followed by the remote server's hostname or IP address. Consider the below command:

The above command will check the connectivity with 'javatpoint.com.' Consider the below output:

Linux ping

from the above output, the command will keep running; we can interrupt it manually by pressing CTRL+C keys.

Check IPv4 Connectivity

The '-4' option is used for the Ipv4 interface. To check whether IPv4 interface is up, execute the command as follows:

The above command will display the connectivity with 'javatpoint.com' by using the Ipv4 address. Consider the below output:

Linux ping

Check IPv6 Connectivity

The '-6' option is used for the IPv6 interface. To check whether IPv6 interface is up, execute the command as follows:

The above command will display the connectivity with 'javatpoint.com' by using the IPv6 address. Consider the below output:

Linux ping

Add a Timestamp before each Line.

The '-D' option is used to add a timestamp before each line. To add a timestamp before each line, execute the command as follows:

The above command will add a UNIX timestamp to the beginning of each line. Consider the below output:

Linux ping

Specify the Source Interface

By default, the ping command uses the default route to send ICMP packages. To specify a particular source interface, use the '-I' option as follows:

Consider the below command:

The above command will ping javatpoint.com using ' enp7s0' as a source interface. Consider the below output:

Linux ping

Change Time Interval between Ping Packets

By default, the time interval between ping packets is one second. We can set it according to our needs. The '-i' option is used to set the time interval between each ping request. To set the ping interval, execute the command as follows:

Consider the below command:

The above command will request the ping packets for every '1.5' seconds. Consider the below output:

Linux ping

From the above output, we can see the transmission time of 8 packets is the 1050s.


Next TopicLinux netstat




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA