in

LinuxLinux

10+ Ping Command in Linux: Ping Command Syntax & Examples

Essential Ping commands list in Linux!

Ping Command in Linux
Reading Time: 6 minutes

P

ing Command in Linux: The expansion of ping is Packet Internet Groper, mainly used in network administration. Ping command helps us to test the server whether it is alive or not!. Ping is a network administration utility mainly used to create the connection between starting server and destination server. You can use the ping command along with the destination server (Domain or ip address) to test.

Ping uses ICMP (Internet Control Message Protocol) to send and receive echo messages. With the help of this protocol, the ping command sends an echo signal to the destination server and receive the echoed signal from the destination server. In this article, we provided the basic usages of ping command in Linux.

Jump To:

Ping Command & Basic Syntax:

Open the Linux Terminal using Ctrl + Alt + T, The enter the phrase “ping” & hit Enter button. The following output will appear in the Terminal.

Output
[email protected]:~$ ping
Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
            [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
            [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
            [-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
             [-l preload] [-m mark] [-M pmtudisc_option]
             [-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
             [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
             [-W timeout] destination

The basic syntax of ping command is,

ping [options] [Destination IP/ Destination Domain]

The basic example for ping command is,

ping tecrobust.com

The output of the above command is,

Output
[email protected]:~$ ping tecrobust.com
PING tecrobust.com(2606:4700:30::681f:422c (2606:4700:30::681f:422c)) 56 data bytes
64 bytes from 2606:4700:30::681f:422c (2606:4700:30::681f:422c): icmp_seq=1 ttl=56 time=99.3 ms
64 bytes from 2606:4700:30::681f:422c (2606:4700:30::681f:422c): icmp_seq=2 ttl=56 time=98.4 ms
64 bytes from 2606:4700:30::681f:422c (2606:4700:30::681f:422c): icmp_seq=3 ttl=56 time=101 ms
64 bytes from 2606:4700:30::681f:422c (2606:4700:30::681f:422c): icmp_seq=4 ttl=56 time=98.6 ms
^C
--- tecrobust.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 98.372/99.362/101.127/1.140 ms

The ping command sends the echo command to the “tecrobust.com” server and the destination server resends the echoed signal to the source server. The ping command provides the following details:

  • ttl= 56
  • icmp_seq=1
  • time=99.3 ms
Check this too  The Easy Hacks In Linux Using Command Line Codes, Command Line Hacks

You can use the following options along with the ping command to test the destination server.

Ping options & description:

-a Audible ping– play a beep to check whether the host is available
-A Adaptive ping. Minimal interval is 200ms for any user other than the sudo. This mode is essentially equivalent to flood mode.
-b You can use this option to allow pinging a broadcast address.
-B This option does not allow ping to change the source address of probes and the IP address is bound to one selected when ping starts.
-m use this mark option to tag the packets going out.
-c You can use this option to stop after sending count ECHO_REQUEST packets.
-d Allows you to set the SO_DEBUG option on the socket being used.
-f Flood ping. This option will send hundreds of ping packets per second to the destination server.
-i You can set the Wait interval seconds between sending each packet. The default interval time is to wait for one second between each packet normally.
-I You can set source address to specified interface address.
-l If preload is specified, ping sends that many packets not waiting for a reply.
-L You can set this option to Suppress loopback of multicast packets.
-n Numeric output only.
-p
  • You may specify up to 16 “pad” bytes to fill out the packet you send.
  • This is useful for diagnosing data-dependent problems in a network.
-D This option will Print timestamp (UNIX time + microseconds) before each line.
-Q You can use this option to set Quality of Service-related bits in ICMP datagrams.
-q Quiet output. Nothing is displayed except the summary lines at startup time and when finished.
-R Record route. It Includes the RECORD_ROUTE option in the ECHO_REQUEST packet and displays the route buffer on returned packets.
-r You can use this option to bypass the normal routing tables and send directly to a host on an attached interface.
-s You can specify the number of data bytes to be sent.
-S You can set socket sndbuf.
-t You can set the IP TTL (time-to-live).
-T  You can set special IP timestamp options.
-M You can select the Path MTU discovery strategy.
-U This option allows you to print full user-to-user latency (legacy ping behavior).
-v Verbose output.
-V This options displays version number, and exit.
-w Specify a timeout,
-W timeout Time to wait for a response, in seconds.
Check this too  Basic Linux Commands & Codes for Beginners[Ubuntu & Mint & More]

Check the host is available or not:

You can check the host is available (alive) or not. Use the following command,

$ping 127.0.0.1

The output of the above command is,

Output
[email protected]:~$ ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.066 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.072 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.051 ms
^C
--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 35ms
rtt min/avg/max/mdev = 0.051/0.063/0.072/0.008 ms

Inc/Dec ping intervals between ping pockets:

You can increase or decrease ping intervals between the ping pockets. Use the following commands,

Increase Ping Intervals between ping pockets:

$ping -i 5 127.0.0.1

The above sample command increases ping intervals between the ping pockets in the interval of 5 seconds.

Decrease Ping Intervals between ping pockets:

$ping -i 1 127.0.0.1

The above sample command decreases ping intervals between the ping pockets in the interval of 1 second.

Changing Ping Packet size:

The default size of the ping packet is 56 bytes. You can increase the ping packet size using the below command,

$ping -s 200 127.0.0.1

The above command increases the ping packet size to 200 bytes. The output of the above command is,

Output
[email protected]:~$ ping -s 200 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 200(228) bytes of data.
208 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.056 ms
208 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.080 ms
^C
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 26ms
rtt min/avg/max/mdev = 0.056/0.068/0.080/0.012 ms

From the above output, you can see the change in ping packet size.

Check this too  How to Change User Password in Ubuntu 18.04 LTS & 19.04 Disco Dingo

Set ping with a customs number of ping packets:

You can set the custom number of ping packets while using ping command,

$ping -c 3 127.0.0.1
Output
[email protected]:~$ ping -c 3 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.066 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.059 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.078 ms

--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 46ms
rtt min/avg/max/mdev = 0.059/0.067/0.078/0.012 ms

Ping command to flood packets:

This option will allows you to send hundreds of ping packets to the destination server. It requires super user permission. Use the following command,

$sudo ping -f 127.0.0.1

The above command will send the 100 number ping packets to the destination server instantly. The output of the above command is,

Output
[email protected]:~$ sudo ping -f 127.0.0.1
[sudo] password for tecrobust: 
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
^C 
--- 127.0.0.1 ping statistics ---
247885 packets transmitted, 247885 received, 0% packet loss, time 258ms
rtt min/avg/max/mdev = 0.004/0.006/0.219/0.004 ms, ipg/ewma 0.017/0.008 ms

Set ping timeout:

You can set the custom ping timeout. Use the following command,

$sudo ping -w 2 127.0.0.1

The output of the above command is,

Output
[email protected]:~$ ping -w 2 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.061 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.074 ms

--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 16ms
rtt min/avg/max/mdev = 0.061/0.067/0.074/0.010 ms

Verdict:

That’s it. We provided the basic ping command usages with examples. If you have any queries related to this topic and then feel free to comment us below.

Article Review
  • Article Explanation
  • Commands Provided
  • Command Usages
  • Examples for Ping Command
4.8

Summary

For more articles, Kindly visit our HomePage

Written by Julian

Hello Folks! I'm Julian, Promoted to the Content writer for the category of Commands & Web Apps in Tec Robust. Enjoy my content & Learn more Linux Commands!

Contact me:
tecrobust [@] gmail.com
Sub: Message to Julian

Comments

One Ping

  1. Pingback:

Leave a Reply

Loading…

0

Comments

0 comments

Control Android from ubuntu

Control Android Smartphone from Ubuntu system- How to do that using Ubuntu PC

Node-Red Ubuntu

Node Red Ubuntu- How to Install on Linux Ubuntu 18.04 LTS & 19.04, & More