Basic Usage of the ping
Command
Pinging a Host by IP Address
The most basic usage of the ping
command is to ping a host by its IP address. For example, to ping the IP address 8.8.8.8
(Google's public DNS server), you can run the following command:
$ 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=63 time=13.1 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=63 time=12.9 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=63 time=12.7 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 12.700/12.917/13.129/0.186 ms
Pinging a Host by Hostname
You can also ping a host by its hostname. For example, to ping the LabEx website, you can run the following command:
$ ping labex.com
PING labex.com (104.21.78.80) 56(84) bytes of data.
64 bytes from 104.21.78.80: icmp_seq=1 ttl=55 time=26.4 ms
64 bytes from 104.21.78.80: icmp_seq=2 ttl=55 time=26.3 ms
64 bytes from 104.21.78.80: icmp_seq=3 ttl=55 time=26.2 ms
^C
--- labex.com ping statistics ---
3 packets received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 26.183/26.314/26.428/0.100 ms
Pinging a Host Continuously
By default, the ping
command will send ICMP echo request packets continuously until you stop it by pressing Ctrl+C
. If you want to limit the number of packets sent, you can use the -c
option followed by the number of packets to send. For example, to send 5 packets to www.example.com
, you can run:
$ ping -c 5 www.example.com
PING www.example.com (93.184.216.34) 56(84) bytes of data.
64 bytes from 93.184.216.34: icmp_seq=1 ttl=54 time=32.4 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=54 time=32.1 ms
64 bytes from 93.184.216.34: icmp_seq=3 ttl=54 time=32.2 ms
64 bytes from 93.184.216.34: icmp_seq=4 ttl=54 time=32.0 ms
64 bytes from 93.184.216.34: icmp_seq=5 ttl=54 time=32.1 ms
--- www.example.com ping statistics ---
5 packets received, 0% packet loss, time 4001ms
rtt min/avg/max/mdev = 32.047/32.160/32.418/0.129 ms