Getting Started with Ping
Ping is one of the easiest commands to use on Ubuntu. Its syntax is incredibly simple and is described as:
If this utility is able to resolve the domain name passed to it, it will show output as:
64 bytes from 22.214.171.124: icmp_req=1 ttl=64 time=0.016 ms
64 bytes from 126.96.36.199: icmp_req=2 ttl=64 time=0.028 ms
64 bytes from 188.8.131.52: icmp_req=3 ttl=64 time=0.021 ms
. . .
This will be regularly output on the terminal window until you break the loop with Ctrl + C combination key. If you want the command to ping only certain number of times, you can tell the utility with an added parameter:
This time, we will see the output as:
This way, we can use the command to check if the domain name resolves to the IP address that we assigned to it or not.
We can check the version which is currently installed on our Ubuntu machine for the Ping command-line utility with the following command:
We will see the following output with the above command:
Controlling the size of Packet with Ping
When we ping a domain, a default sized packets are sent to the hosting server. If we want to control the size of packets which are sent to the host when we perform a ping operation, we can use the following command:
This way, we are sending 40-byte packet data 5 times to the specified hostname, the output we will get is:
Time Interval for Ping
With Ping utility, the data packets are sent at an interval of one second to the host server. We can update the time gap between the pings with the following command:
The -i option can accept the second count. We will see a similar output:
Making a noise with Ping
Ping can even be modified to make a bell sound whenever a response packet is received back from the host server with the following command:
Of course, showing its output is not possible.
Suppressing Output for Ping
Usually, we do not care about what happened when each packet is sent and data is received back as a response with each Ping. In these cases, we can suppress the output by showing information related to first Ping and the final data. This can be done as follows:
With this command, ping command will be executed in quiet mode and following output will appear on screen:
Total Time to Ping
We can even tell Ping command to reach a server and ping it for an only specified amount of time. So, with the following command, we ping the server for only 5 seconds in total:
The following output will appear on screen:
In this lesson, we saw how we can reach out to a server and ping for its availability using one of the most simple command-line utility available on an Ubuntu machine. Read more Ubuntu lessons here.