Updated April 17, 2023
Introduction to Linux Ping
In the Linux ecosystem, the ping is used to check whether the host is reachable or not over the internet protocol. It is working on the ICMP protocol i.e. Internet Control Message Protocol. Ping command utility is cross-platform. Primarily, it is working packet level. Widely, the ping command is also known as the Packet Internet Groper.
Syntax of Ping Command:
ping [option] hostname or IP address
- ping: We can use the ping keyword in the syntax or command. It will take the two-argument as an option and hostname or IP address. As per the input argument, the ping command will provide the end result of whether the IP or hostname is reachable or not.
- option: We can provide the different flags as options that are compatible with the ping command.
- hostname or IP address: As per the requirement, we can pass the different hostname or the IP address.
How does Linux Ping Command work?
The ping is widely used to check the host or IP address availability or reachability.
While the source machine is using the ping command, the ping command will follow the below steps:
- It is trying to connect the destination host or IP address.
- It is calculating the amount of time it is taking from the destination host to the sender or source host.
- It is also calculating the average packet loss between the source and destination host.
The ping command is working on the ICMP protocol. It is also known as the Internet Control Message Protocol. With the help of the same protocol, the ping command is sending the series of ECHO REQUEST messages or packets to the destination address and waiting for the reply from destination packages. The destination packets are also replying in the ICPM protocol. If the sources machine will receive the packet or message response from the destination machine. Then only we can say the connection or connectivity is established in between the source or destination servers.
Examples of Linux Ping
Given below are the examples mentioned:
Example #1
Ping Command
It is a very simple and common way to use the ping command in a Linux environment. It will work in the default ping format.
Code:
ping google.com
Explanation:
The ping command is widely used in the cross-platform. As per the above ping command, we are trying to ping “google.com” and make sure that the connectivity is established or not. If we are getting the reply from the destination host or IP address then the sure that the connectivity was established.
Output:
Example #2
Ping Command – With “-c” Option
By default, the ping command is continuously printing the echo-response on the screen unless and until we do not interrupt it screen. To avoid this condition, we can use the “-c” option with the ping command. It is useful to send the limited ECHO REQUEST packets.
Code:
ping -c 3 google.com
Explanation:
By default, we are getting the ping response. But we need a limited response or reply from the destination server then we need to use the “-c” option with the response value.
Output:
Example #3
Ping Command – With “i” Option
In ping command, we are having the functionality to send the packets in a specific interval of time.
Code:
ping -i 2 -c 2google.com
Explanation:
As per the above ping command, we are able to send the packets or response to the destination server or host in a specific interval of time i.e., two sec.
Output:
Example #4
Ping Command – With “-f” Option
Sometimes we need to test the network load or network response on the high load. In ping command, we are having the functionality to check the high performance on the network level.
Code:
ping -f google.com
Explanation:
In ping command, we are sending the huge amount of load in the network via the “-f” option. We can also test the load-carrying capacity of the network.
Output:
Example #5
Ping Command – With “-b” Option
In ping command, we are having the functionality to enable the broadcast.
Code:
ping -b 192.168.1.1
Explanation:
As per the above command, we are able to broadcast in the Linux environment with the help of ping command.
Output:
Example #6
Ping command – With “-s” Option
In the Linux environment, we can test the ping response in different packets sizes. We can define the packet size with the help of “-s” option in the ping command.
Code:
ping -s 1024 google.com
Explanation:
In general, the ping command is using 64 bytes for the source and destination communication. Sometimes due to high traffic or latency, the packets may drop and the necessary packets are not able to reach the source machine. To avoid this condition, we need to use the “-s” option to increase the bytes size in the ping command.
Output:
Example #7
Ping Command – With “-l” Option
In Ping command, we are having the functionality to send the packages at the same time without waiting for the reply from the destination host or IP address.
Code:
ping -l 5 google.com
Explanation:
As per the above command, we are sending the 5 requests at the same time. Here, we are not waiting from the destination response.
Output:
Example #8
Ping Command – With “-v” Option
In the ping command, we are having the functionality to get the verbose output.
Code:
ping -v google.com
Explanation:
As per the above ping command, we are able to get the ping command output in the verbose mode.
Output:
Example #9
Ping Command – With “-W” Option
In the ping command, we are having the functionality to define the time to wait for response value. The ping command will wait for the destination response at the curtain time period.
Code:
ping -W 10 google.com
Explanation:
As per the below screenshot, we are waiting for a response from google.com. We have defined the waiting time is 10 sec.
Output:
Conclusion
We have seen the uncut concept of “Linux Ping Command” with the proper example, explanation and command with different outputs. The ping command utility is widely used in the multiple platforms. It is the best way to check the connectivity in between the source and destination machine.
Recommended Articles
We hope that this EDUCBA information on “Linux Ping” was beneficial to you. You can view EDUCBA’s recommended articles for more information.