Linux ping Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the Linux ping command to test the connectivity between a local host and remote hosts. The lab covers the basics of the ping command, including pinging the local loopback interface and remote hosts. You will also learn how to use the ping command to troubleshoot network issues. The lab provides practical examples and step-by-step instructions to help you understand and apply the ping command effectively in your networking and communication tasks.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/RemoteAccessandNetworkingGroup(["`Remote Access and Networking`"]) linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux/PackagesandSoftwaresGroup -.-> linux/curl("`URL Data Transferring`") linux/RemoteAccessandNetworkingGroup -.-> linux/ifconfig("`Network Configuring`") linux/RemoteAccessandNetworkingGroup -.-> linux/netstat("`Network Monitoring`") linux/RemoteAccessandNetworkingGroup -.-> linux/ping("`Network Testing`") linux/SystemInformationandMonitoringGroup -.-> linux/hostname("`Hostname Managing`") subgraph Lab Skills linux/curl -.-> lab-422858{{"`Linux ping Command with Practical Examples`"}} linux/ifconfig -.-> lab-422858{{"`Linux ping Command with Practical Examples`"}} linux/netstat -.-> lab-422858{{"`Linux ping Command with Practical Examples`"}} linux/ping -.-> lab-422858{{"`Linux ping Command with Practical Examples`"}} linux/hostname -.-> lab-422858{{"`Linux ping Command with Practical Examples`"}} end

Understanding the Basics of ping Command

In this step, you will learn the basics of the ping command in Linux. The ping command is a network diagnostic tool used to test the connectivity between a local host and a remote host. It sends Internet Control Message Protocol (ICMP) echo request packets to the target host and waits for the ICMP echo reply.

First, let's try pinging the local loopback interface:

ping 127.0.0.1

Example output:

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.027 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.024 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.025 ms
^C
--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2ms
rtt min/avg/max/mdev = 0.024/0.025/0.027/0.001 ms

The ping command sends ICMP echo request packets to the loopback address 127.0.0.1 and displays the response time and other statistics. Press Ctrl+C to stop the ping.

Now, let's try pinging a remote host, such as google.com:

ping google.com

Example output:

PING google.com (142.250.184.78) 56(84) bytes of data.
64 bytes from lax34s15-in-f14.1e100.net (142.250.184.78): icmp_seq=1 ttl=117 time=12.3 ms
64 bytes from lax34s15-in-f14.1e100.net (142.250.184.78): icmp_seq=2 ttl=117 time=12.1 ms
64 bytes from lax34s15-in-f14.1e100.net (142.250.184.78): icmp_seq=3 ttl=117 time=12.2 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 12.100/12.200/12.300/0.100 ms

The ping command resolves the hostname google.com to its IP address 142.250.184.78 and sends ICMP echo request packets to that address. The response time and other statistics are displayed.

Pinging Local and Remote Hosts

In this step, you will learn how to use the ping command to test the connectivity to both local and remote hosts.

First, let's ping the local host using the IP address:

ping 192.168.1.1

Example output:

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.041 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.034 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.035 ms
^C
--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2ms
rtt min/avg/max/mdev = 0.034/0.037/0.041/0.003 ms

Now, let's ping a remote host using the hostname:

ping github.com

Example output:

PING github.com (140.82.121.4) 56(84) bytes of data.
64 bytes from lb-140-82-121-4-iad.github.com (140.82.121.4): icmp_seq=1 ttl=54 time=24.3 ms
64 bytes from lb-140-82-121-4-iad.github.com (140.82.121.4): icmp_seq=2 ttl=54 time=24.1 ms
64 bytes from lb-140-82-121-4-iad.github.com (140.82.121.4): icmp_seq=3 ttl=54 time=24.2 ms
^C
--- github.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 24.100/24.200/24.300/0.100 ms

The ping command resolves the hostname github.com to its IP address 140.82.121.4 and sends ICMP echo request packets to that address.

Troubleshooting Network Issues with ping

In this step, you will learn how to use the ping command to troubleshoot network issues.

First, let's try pinging a host that is not reachable:

ping 8.8.8.8

Example output:

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2000ms

In this case, the ping command shows 100% packet loss, indicating that the host is not reachable.

Next, let's try pinging a host with a long response time:

ping slowweb.com

Example output:

PING slowweb.com (93.184.216.34) 56(84) bytes of data.
64 bytes from 93.184.216.34: icmp_seq=1 ttl=54 time=1000 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=54 time=1001 ms
64 bytes from 93.184.216.34: icmp_seq=3 ttl=54 time=1000 ms
^C
--- slowweb.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 1000.000/1000.333/1001.000/0.577 ms

In this case, the ping command shows a very high response time, which could indicate a network performance issue.

Finally, let's try pinging a host with a high packet loss:

ping lossy.com

Example output:

PING lossy.com (93.184.216.34) 56(84) bytes of data.
64 bytes from 93.184.216.34: icmp_seq=1 ttl=54 time=100 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=54 time=100 ms
64 bytes from 93.184.216.34: icmp_seq=3 ttl=54 time=100 ms
64 bytes from 93.184.216.34: icmp_seq=4 ttl=54 time=100 ms
^C
--- lossy.com ping statistics ---
4 packets transmitted, 4 received, 50% packet loss, time 3003ms
rtt min/avg/max/mdev = 100.000/100.000/100.000/0.000 ms

In this case, the ping command shows a 50% packet loss, which could indicate a network issue.

Summary

In this lab, you learned the basics of the ping command in Linux, which is a network diagnostic tool used to test the connectivity between a local host and a remote host. You started by pinging the local loopback interface 127.0.0.1 and then pinging a remote host google.com. You also learned how to use the ping command to test the connectivity to both local and remote hosts, and how to troubleshoot network issues using the ping command.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like