Linux OS offers several useful command-line utilities and one of the most valuable among them is the “ping”. The “ping” or “Packet Internet Groper” is a versatile tool for testing the network connectivity and measuring the response times.
The “ping” command works by sending packets via the “ICMP” or “Internet Control Message Protocol” to test the reachability of a device or server on the internet. It allows you to check the network’s responsiveness and stability and diagnose basic internet connectivity issues.
This detailed guide discusses the methods to install and use the “ping” command on Debian 12.
Quick Outline:
- How to Install the “ping” Command on Debian 12
- How to Use the “ping” Command on Debian 12
- Bonus Tip: How to Remove the “ping” Command From Debian 12
How to Install the “ping” Command on Debian 12
You can install the “ping” command via the following methods:
- The Default Repository
- The .deb Package
The above methods are illustrated below:
Method 1: Install the “ping” Command Via the Default Repository
The “ping” command is officially available in the default repositories of many Linux distributions, including the Debian-based distributions. To install the latest version of the “ping” command on Debian 12, execute the below command:
sudo apt install iputils-ping -y
To verify the installation and view the “ping” command’s version, run:
ping -V
Method 2: Install the “ping” Command Via .deb Package
The “apt” method does not guarantee the latest version of the “ping” command and developers use the “.deb” packages to distribute their software’s latest version. To install the latest version of the “ping”, use the below command to download it first:
$ wget http://ftp.de.debian.org/debian/pool/main/i/iputils/iputils-ping_20210202-1_amd64.deb
Now, trigger the installation of the “ping” command by executing the following command:
sudo dpkg -i iputils-ping_20210202-1_amd64.deb
How to Use the “ping” Command on Debian 12
Before understanding the use of the “ping” command, let’s go through its syntax:
ping [options] <destination>
Here:
- The “ping” invokes the “ping” command.
- The “[options]” are the flags that you can use to get the desired results from the “ping” command.
- The “<destination>” specifies the IP address of the remote hostname to ping.
To view a complete list of useable options for the “ping” command, view the help page using the below command:
ping -h
Let’s understand the above flags via the following examples:
Example 1: Check the Reachability of a Specific Host
The “ping” command allows you to determine whether the specified host is reachable. For instance, below is a command to check if “google.com” is reachable or not:
ping google.com
In the above output:
- The “icmp_seq=1” represents the first sequence of the reply from the remote device or system.
- The “ttl” shows the time during which the packet remains inside the network before being discarded by the router.
- The “time” refers to the time (in milliseconds) that a network takes to initiate a request and receive a response. It is lower for good networks.
- The “packet loss” indicates the packets not reaching the target potentially due to connectivity issues.
Example 2: Specify the Packets to be Sent
By default, the “ping” command sends unlimited packets until the host disconnects or the user stops. You can modify it according to your requirements; for instance, the below command sends “4 icmp packets” to “google.com” and outputs the results:
sudo ping -c 4 google.com
Example 3: Specify the Time Interval Before the Next Packet is Sent
To quickly assess the responsiveness or check for immediate internet connection modifications, you can specify the time interval before the “ping” command sends the next packet. The following command sends a packet after every “three milliseconds” to “google.com”. It is currently only limited to IPv4:
ping -i 3 google.com
Example 4: Specify the Time to Live for the “ping” Command
The “Time to Live” is referred to as the time before the packet is discarded. For instance, the below command waits “2 seconds” before discarding it via the router:
ping -t 2 google.com
Note: To stop the “ping” command from sending more packets, press the “Ctrl + C” buttons.
Example 5: Resolve Hostname
You can use the “ping” command to unmask the hostname behind an IP address. This allows you to unhide the IP address behind the hostname. To do that, use the below format and add the specified IP address to resolve:
ping -a <IP-Address-To-Resolve>
Example 6: Set the Time Interval Between Each Packet Sent
The “Time Interval (in seconds)” represents the time before each packet is sent by the “ping” command. The default is set to “1 second” and to change it, use the following command:
ping -c 3 -i 7 www.facebook.com
In the above command:
- The “-c 3” sets the number of packets to be sent to “3”.
- The “-i 7” sets the wait time before the next packet is sent to “7 seconds”.
Example 7: “ping” Your Router
To check the connectivity and ensure that your router is working, use the “ping” command to ping your router by adding your default gateway address. The default gateway is the IP address of your router, use the “ifconfig” or “netstat” command:
ping <Your-Default-Gateway-Address>
Example 8: Force the “ping” to Use IPv6 or IPv4
Although most of the networks are using the IPv6, you can force the “ping” command to ping the IPv6 address. To do that, use the below format:
ping -t -6 <IP-Address>
If you want to force the “ping” command to use the IPv4 only, use the below format:
ping -t -4 <IP-Address>
Example 9: Change Packet Size
The default packet size that the “ping” commands send is “56 bytes” and receives “64 bytes” after adding the “8 bytes” of “icmp” data bytes. To increase the packet size to “60 bytes”, use the following command and the total bytes received would be “68 bytes”:
ping -s 60 google.com
Example 10: Set Time Before the “ping” Command Stops
The default time for the “ping” command to send packets before receiving any response is set to “4 seconds”. To change this behavior of the “ping” command, use the following command and set the connection timeout (5 seconds in this case):
ping -w 5 google.com
Example 11: Add Timestamp With the Output
You can view the time and date in every response (from google.com in this case) received via the “ping” command. To do that, run the below-stated command:
ping www.google.com | while read time; do echo "$(date): $time"; done
Example 12: Flood a Network
To test the endurance of your server or website against the DoS or DDoS attacks, use the following command:
ping -f <Your-server-or-website-address>
Warning: Use the above command only when required as it uses high bandwidth and could crash your network.
Bonus Tip: How to Remove the “ping” Command From Debian 12
Run the following command to remove the “ping” command from Debian 12:
sudo apt -y autoremove inetutils-ping
.
If you want to remove all configuration files while removing the “ping” command, use the below-stated command:
sudo apt -y purge inetutils-ping
That’s all for installing and using the “ping” command on Debian 12.
Final Words
To install the “ping” command in Debian 12, execute the command “sudo apt install iputils-ping -y” to do it via the default repositories. To download the specific version of the “ping” command, use the “.deb” file.The “ping” command lets you check the availability and responsiveness of a network or device on the internet. It works by sending data packets and outputs the response on the terminal. If it gets no response, the error “Connection Timeout” is displayed. It comes with several flags/options that you can use and this guide covers the most useful among them.