Cyberithub

Top 10 Ping Command Examples in Linux

Advertisements

In this tutorial, I will take you through Best Ping Command in Linux. Ping is a computer network administration software utility used to test the reachability of a host on an Internet Protocol network. It is abbreviated as "Packet Internet Groper". It is available for virtually all operating systems that have networking capability, including most embedded network administration software.

Often we think How to ping ip address or how to ping google or how to use ping ttl in Linux. To Know how to ping ip address, you need to first understand how ping command works. To understand how to ping ip address in a simple way you can just ping on google ip and check. Once you understand this you will also understand how to ping google, ping ttl values and how to ping on a specific address. I have covered sections like how to ping ip address, how to ping google, ping on ip address, ping ttl values below. Initially we all start by ping on google ip and understand how to ping google.

Ping Command in Linux

It sends ICMP ECHO_REQUEST to network hosts. It is a tool to check and verify if the destination node is up or not. It also gives few more information like RTT(round trip time), no of packets transmitted, no of packets received etc. We will look at the few best ping command examples below.

How to Ping IP Address

To understand how to ping ip address, you need to understand the Ping Command Syntax as mentioned below:-

ping <options> <IP Address>

How to Ping Internet

If you want to check if internet is working in your system or not, you can ping on Google DNS Address and check.

[root@localhost ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=49 time=46.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=49 time=50.5 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=49 time=46.2 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=49 time=50.6 ms

How to Ping Google Address

If you want to ping on google, you need to use ping google.com command. This is the very basic command anyone can use to understand how to ping google address in Linux using ping command.

[root@localhost ~]# ping google.com 
PING google.com (216.58.197.78) 56(84) bytes of data.
64 bytes from maa03s21-in-f78.1e100.net (216.58.197.78): icmp_seq=1 ttl=48 time=41.6 ms
64 bytes from maa03s21-in-f78.1e100.net (216.58.197.78): icmp_seq=2 ttl=48 time=41.9 ms
64 bytes from maa03s21-in-f78.1e100.net (216.58.197.78): icmp_seq=3 ttl=48 time=42.2 ms

Also Read: How to Ping Google through Bash Script

What is Ping TTL

Ping TTL means time to live. In above section of How to ping google address, you might have seen ping ttl value of 48. It means packets will only live for 48 network hops and then it will be discarded. ping ttl is an important parameter to trace the packets.

Top 10 Ping Command Examples in Linux 1

To ping on local interface using continuous ping Command

If you want to check if the localhost is up and running, you can perform continuous ping command in Linux and check.

[root@localhost ~]# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.041 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.040 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.047 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.051 ms
64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.037 ms

If you want to check the local interface is up or not through IP address instead of hostname, you can run below continuous ping command in Linux and check:-

[root@localhost ~]# 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.044 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.078 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.058 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.050 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.066 ms

To set interval of 2 seconds between each packets

If you want to send total of 5 packets with a time interval of 2 seconds between them, you can do that by continuous ping command using -i ping options.  The default value is one second.

[root@localhost ~]# ping -i 2 -c 5 192.168.0.104
PING 192.168.0.104 (192.168.0.104) 56(84) bytes of data.
64 bytes from 192.168.0.104: icmp_seq=1 ttl=64 time=0.335 ms
64 bytes from 192.168.0.104: icmp_seq=2 ttl=64 time=0.275 ms
64 bytes from 192.168.0.104: icmp_seq=3 ttl=64 time=0.350 ms
64 bytes from 192.168.0.104: icmp_seq=4 ttl=64 time=0.273 ms
64 bytes from 192.168.0.104: icmp_seq=5 ttl=64 time=0.277 ms

To enable pinging a broadcast

If you want to ping a broadcast address, you need to use -b switch with ping command in Linux.

[root@localhost ~]# ping -b 192.168.0.255
WARNING: pinging broadcast address
PING 192.168.0.255 (192.168.0.255) 56(84) bytes of data.
^C
--- 192.168.0.255 ping statistics ---
53 packets transmitted, 0 received, 100% packet loss, time 52182ms

To limit the number of Network hops

If you want to set the TTL(time to live) value of packets, you can use -t switch with ping command.

[root@localhost ~]# ping -t 10 192.168.0.104
PING 192.168.0.104 (192.168.0.104) 56(84) bytes of data.
64 bytes from 192.168.0.104: icmp_seq=1 ttl=64 time=0.298 ms
64 bytes from 192.168.0.104: icmp_seq=2 ttl=64 time=0.245 ms
64 bytes from 192.168.0.104: icmp_seq=3 ttl=64 time=0.307 ms
64 bytes from 192.168.0.104: icmp_seq=4 ttl=64 time=0.280 ms
64 bytes from 192.168.0.104: icmp_seq=5 ttl=64 time=0.298 ms

Change the default packet size from 56 to 100.

To change the default packet size from 56 bytes, you need to use -s ping options along with the specified packet value.

[root@localhost ~]# ping -s 100 192.168.0.104
PING 192.168.0.104 (192.168.0.104) 100(128) bytes of data.
108 bytes from 192.168.0.104: icmp_seq=1 ttl=64 time=0.315 ms
108 bytes from 192.168.0.104: icmp_seq=2 ttl=64 time=0.338 ms
108 bytes from 192.168.0.104: icmp_seq=3 ttl=64 time=0.269 ms
108 bytes from 192.168.0.104: icmp_seq=4 ttl=64 time=0.260 ms
108 bytes from 192.168.0.104: icmp_seq=5 ttl=64 time=1.16 ms

Ping Options to enable verbose output

If you want to enable the verbose feature of ping request, you need to use -v ping options with below ping command in Linux.

[root@localhost ~]# ping -v 192.168.0.104
ping: socket: Permission denied, attempting raw socket...
PING 192.168.0.104 (192.168.0.104) 56(84) bytes of data.
64 bytes from 192.168.0.104: icmp_seq=1 ttl=64 time=0.302 ms
64 bytes from 192.168.0.104: icmp_seq=2 ttl=64 time=0.306 ms
64 bytes from 192.168.0.104: icmp_seq=3 ttl=64 time=0.316 ms
64 bytes from 192.168.0.104: icmp_seq=4 ttl=64 time=0.378 ms
64 bytes from 192.168.0.104: icmp_seq=5 ttl=64 time=0.282 ms
64 bytes from 192.168.0.104: icmp_seq=6 ttl=64 time=0.245 ms

To enable debugging of IP Packet

If you want to enable debugging feature of IP Packet, you need to use -d continuous ping options.

[root@localhost ~]# ping -d 192.168.0.104
PING 192.168.0.104 (192.168.0.104) 56(84) bytes of data.
64 bytes from 192.168.0.104: icmp_seq=1 ttl=64 time=0.355 ms
64 bytes from 192.168.0.104: icmp_seq=2 ttl=64 time=0.314 ms
64 bytes from 192.168.0.104: icmp_seq=3 ttl=64 time=0.326 ms
64 bytes from 192.168.0.104: icmp_seq=4 ttl=64 time=0.257 ms
64 bytes from 192.168.0.104: icmp_seq=5 ttl=64 time=0.865 ms
64 bytes from 192.168.0.104: icmp_seq=6 ttl=64 time=0.286 ms

Set time to wait for a response from ping server

If you want set time to wait for a response in seconds, you can use -W ping options. This option affects only timeout in absence of any responses, otherwise ping waits for two RTTs.

[root@localhost ~]# ping -W 10 192.168.0.104
PING 192.168.0.104 (192.168.0.104) 56(84) bytes of data.
64 bytes from 192.168.0.104: icmp_seq=1 ttl=64 time=0.295 ms
64 bytes from 192.168.0.104: icmp_seq=2 ttl=64 time=0.336 ms
64 bytes from 192.168.0.104: icmp_seq=3 ttl=64 time=0.271 ms
64 bytes from 192.168.0.104: icmp_seq=4 ttl=64 time=0.329 ms
64 bytes from 192.168.0.104: icmp_seq=5 ttl=64 time=0.264 ms

To specify preload value

If preload is specified,continuous ping command sends that many packets without waiting for any reply. Only the super-user may select preload more than 3.

[root@localhost ~]# ping -l 5 192.168.0.110
PING 192.168.0.110 (192.168.0.110) 56(84) bytes of data.
From 192.168.0.105 icmp_seq=1 Destination Host Unreachable
From 192.168.0.105 icmp_seq=2 Destination Host Unreachable
From 192.168.0.105 icmp_seq=3 Destination Host Unreachable
From 192.168.0.105 icmp_seq=4 Destination Host Unreachable
From 192.168.0.105 icmp_seq=5 Destination Host Unreachable
From 192.168.0.105 icmp_seq=6 Destination Host Unreachable
From 192.168.0.105 icmp_seq=7 Destination Host Unreachable
From 192.168.0.105 icmp_seq=8 Destination Host Unreachable
^C
--- 192.168.0.110 ping statistics ---
8 packets transmitted, 0 received, +8 errors, 100% packet loss, time 3000ms
pipe 8

To send more than 50,000 packets in few seconds.

If you want to flood any server in your network with packets, you can use continuous ping command with -f switch to ping server.

[root@localhost ~]# ping -f 192.168.0.104
PING 192.168.0.104 (192.168.0.104) 56(84) bytes of data.
.^
--- 192.168.0.104 ping statistics ---
51024 packets transmitted, 51024 received, 0% packet loss, time 26936ms
rtt min/avg/max/mdev = 0.059/0.419/47.685/1.311 ms, pipe 2, ipg/ewma 0.527/1.663 ms

Also Read: How to install or enable ssh on Ubuntu 18.04

Reference: Ping Documentation

Leave a Comment