How to use the Ping command in Linux
Among the tools used in network administration and computer diagnostics, the ping command stands out as one of the most basic and widely used. A command-line utility available in almost every operating system, ping serves as an important diagnostic tool for network engineers, system administrators, and even technology enthusiasts. curious.
The ping command sends small data packets to a specified IP address or server and in return, it receives a response. By doing so, it helps users determine whether a network device is reachable or not and provides valuable information about network response time and reliability. Whether you're troubleshooting connectivity issues, monitoring network performance, or just starting your network management journey, the ping command is a must-know.
General syntax for the ping command:
ping [IP-ADDRESS]
1. Specify the number of packages
ping -c [number] [IP-Address]
Use the -c option to have the ping command automatically stop after a certain number of packets are sent.
For example, when you run the ping command with the -c 5 option to send 5 packets to IP address 127.0.0.1, you may see results similar to the following:
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.045 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.058 ms 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.056 ms 64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.059 ms 64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.057 ms --- 127.0.0.1 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 3999ms rtt min/avg/max/mdev = 0.045/0.055/0.059/0.006 ms
2. Check the Localhost network
ping localhost
If you're having trouble connecting to a remote computer or site, ping localhost to make sure you're connected.
For example, when you ping localhost, you are essentially pinging your own machine. Here is a sample result you can see:
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.033 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.031 ms 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.031 ms 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.030 ms --- localhost ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 2998ms rtt min/avg/max/mdev = 0.030/0.031/0.033/0.001 ms
3. Only send pings for a limited period of time
ping -i [number] [IP-Address]
The -i option sets the timeout period in seconds before each packet is sent.
For example, the command ping -i 5 127.0.0.1 will send ICMP Echo Request packets to loopback address 127.0.0.1 every 5 seconds. Here is a sample 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.035 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.040 ms 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.038 ms 64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.039 ms --- 127.0.0.1 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 15005ms rtt min/avg/max/mdev = 0.035/0.038/0.040/0.007 ms
In this example, each request is responded to in less than a millisecond, and no packets are lost. Output may vary depending on your system configuration and current system load.
4. Flood ping the target host
ping -f [IP-address]
The -f option will send packets as fast as possible. This can flood the network so is often called 'flood ping'. It is mainly used to test endurance and should be used with caution.
Since packets are sent as quickly as possible, there may not be as detailed an output as a regular ping. Instead, you'll just see a series of dots and spaces that may be printed as packets are sent and received.
For example, a typical output might look something like this:
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. ..........^C --- 127.0.0.1 ping statistics --- 468751 packets transmitted, 468750 received, 0% packet loss, time 330ms rtt min/avg/max/mdev = 0.025/0.035/0.139/0.002 ms, pipe 2, ipg/ewma 0.182/0.037 ms
Note that ^C above represents pressing Ctrl + C to stop the command. It's important to know that the flood option requires root privileges, so you may need to run this command with sudo if you are not the root user.
5. Change ping packet size
ping -s [number] [IP-Address]
Using the -s option to increase the default packet size, you can send light and heavy packets.
For example, the command ping -s 1000 127.0.0.1 sends an ICMP echo request to loopback address 127.0.0.1 with a packet size of 1000 bytes. Here's an example of what the output might look like:
PING 127.0.0.1 (127.0.0.1) 1000(1028) bytes of data. 1008 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.050 ms 1008 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.054 ms 1008 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.050 ms 1008 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.054 ms --- 127.0.0.1 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3071ms rtt min/avg/max/mdev = 0.050/0.052/0.054/0.002 ms
6. Show only summary lines
ping -q [IP-Address]
The -q option outputs a line with the usual ping information, followed by statistics.
For example, when you run the ping command with the -q flag on the loopback address 127.0.0.1, it will send ICMP ECHO_REQUEST packets to the network host. Flag -q causes the command to run in 'silent' mode, where it only displays summary statistics when completed. The output might look something like this:
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. --- 127.0.0.1 ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 8999ms rtt min/avg/max/mdev = 0.045/0.057/0.082/0.012 ms
7. Set a time limit for receiving packages
ping -w [seconds] [IP-Address]
This option stops receiving ping output after a certain period of time.
For example, when you run the ping command with the -w 10 option to the loopback address 127.0.0.1, it sends ICMP echo request packets to that address and waits up to 10 seconds to receive a response. Here is an example output you can see:
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.041 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.040 ms 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.041 ms 64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.038 ms . --- 127.0.0.1 ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 8999ms rtt min/avg/max/mdev = 0.038/0.041/0.045/0.002 ms
You should read it
- How to Ping in Linux
- How to Ping on Linux
- What is PING? How is PING Test?
- How to Ping an IP Address
- How to use the which command in Linux
- 20+ essential Linux security commands
- How to use the stat command on Linux
- 14 interesting Linux commands in Terminal
- Basic Linux commands everyone needs to know
- How to use the Ping command to test the network
- The Cat command in Linux
- How to use the last command in Linux
Maybe you are interested
Top best mind mapping software on computers and laptops today
Top 5 best mind mapping software
How to fix font errors in Excel when typing Vietnamese
9 Ways to Fix Keyboard Typing Delay on Windows 10/11
How to Avoid Post-Tracking Targeted Ads After Shopping Online
OpenAI Announces ChatGPT Pro Plan for a whopping $200 per month