Linux Mint

How to Block and Unblock Ping Requests on Linux Mint 21

A ping request is a network utility used to test the reachability of a host on an Internet Protocol (IP) network. It is used to send a small packet of data, called a “ping,” to a target device to see if it is reachable and responding.

Hackers could use a ping flood attack, also known as a “ping of death,” to overwhelm a target device with many ping requests, potentially causing it to crash or make it unresponsive. So, if you are concerned about the safety for your Linux Mint and want to block the ping request option then read this guide.

How to Block and Unblock Ping Requests on Linux Mint 21

The ping request is used to verify connectivity and determine the round-trip time it takes for a packet to be sent and received. There are different ways to block a ping request and vice versa, some of them are given below:

1: Through Kernel Parameters

2: Through iptables

1: Block and Unblock Ping Requests Through Kernel Parameters

In the Linux operating system, kernel parameters are values that can be passed to the kernel at boot time to modify its behavior or configure certain features. So, there are three ways by which kernel parameters can be used to block and unblock ping requests:

i: Using sysctl command to change the parameters

ii: Changing parameters in the .conf file

i: Using sysctl Command to Change the Parameters

One way to block or unblock the ping request through kernel parameters is by using the sysctl command and for that go through the steps mentioned below:

Step 1: Before going to block the ping request first check if it is active or not and for that use the below given syntax:

$ ping <IP-Address>

Like in my case I have used an IP address by following the above-mentioned syntax:

$ ping 192.168.18.75

Step 2: If the system is active or unblock it will receive and send packets as in the image above along with the total time, now let’s use the sysctl command to the ping request by executing:

$ sudo sysctl -w net.ipv4.icmp_echo_ignore_all=1

Text Description automatically generated

Now let’s see if the ping request is blocked or not and for that follow the given below syntax:

$ ping -c <number-of packets> <IP-address>

To test I have sent three packets on IP address by following the above given syntax:

$ ping -c 3 192.168.18.75

You will see that after some time ping statistics will appear stating 100% packet loss which depicts that ping request is blocked.

Step 3: Now to unblock the ping request and for that just change the value from 1 to zero by executing:

$ sudo sysctl -w net.ipv4.icmp_echo_ignore_all=0

Now check the of the ping request is unblocked by using the same syntax we mentioned previously:

$ ping -c 3 192.168.18.75

Calendar Description automatically generated

ii: Changing Parameters in the .conf File

Another way to block the ping request is by editing the configuration file by adding net.ipv4.icmp_echo_ignore_all=0 line, here are some steps that one need to follow to get along with this method:

Step 1: First open the sysctl.conf file with the help on nano command by executing:

$ sudo nano /etc/sysctl.conf

Graphical user interface, text, application Description automatically generated

Now enter the following line in the file and afterwards save it and close it:

net.ipv4.icmp_echo_ignore_all = 1

Step 2: Next, to apply the changes use the –p flag with sysctl:

$ sudo sysctl -p

Step 3: Now check if the ping is blocked by using the above-mentioned syntax:

$ ping -c 3 192.168.18.75

Step 4: To unblock simply change the value of the line we added previously to 0 in the configuration file from 1 and save the changes:

net.ipv4.icmp_echo_ignore_all = 0

Next To apply the changes done to the configuration file execute:

$ sudo sysctl -p

Now check if the ping request is unblocked send three packets ping request by executing:

$ ping -c 3 192.168.18.75

A picture containing calendar Description automatically generated

2: Block and Unblock Ping Requests Through Iptables

Iptables is a firewall utility built into the Linux kernel that allows users to configure rules for inbound and outbound network traffic. To make the blocking of the ping request permanently that do not reverse on reboot of Linux Mint one can use IP tables and for that go through the subsequent steps:

Step 1: Normally the iptables is already installed on Linux Mint 21 if in any case you do not have it installed then execute:

$ sudo apt install iptables -y

Step 2: Next, execute the following command to instruct the firewall to block any ping requests:

$ sudo iptables -A INPUT -p icmp --icmp-type 8 -j REJECT

Graphical user interface, text Description automatically generated

Now send a ping request of three packets to check if the ping request is blocked or not by executing:

$ ping -c 3 192.168.18.75

Step 3: Next, to unblock the ping requests just execute the same previous command, just replace the A flag with the D flag like this:

$ sudo iptables -D INPUT -p icmp --icmp-type 8 -j REJECT

Next to verify the if the ping request is unblocked send three packets in the ping request by executing:

$ ping -c 3 192.168.18.75

The changes we made in the above steps for blocking and unblocking the ping requests will not survive the system reboot.

Using iptables-presistent to save the rules

So, to save the rules one need to install iptables persistent on Linux Mint, for that follow the below steps:

Step 1: The iptables-persistent package is a utility that allows users to save their iptables firewall rules so that they are automatically applied at boot time, to install it execute:

$ sudo apt install iptables-persistent -y

Text Description automatically generated

Next, press Enter to Yes to save the rules:

Next set the rules.v6 file as the configuration file for saving the rules of IP version 6 by pressing Enter on Yes:

Graphical user interface, text, application Description automatically generated

Step 2: Once the installation is done check the list of rules saved in the iptables by executing:

$ sudo iptables -L

Step 3: Next execute the following command to save the rule for blocking or unblocking the ping request:

$ sudo netfilter-persistent save

Step 4: Next after saving the rules reload the netfilter to make the changes inevitable on reboot by executing:

$ sudo netfilter-persistent reload

Conclusion

Ping is a useful tool for troubleshooting network problems and can be used to check the status of a network connection or the availability of a particular device or service. It can be harmful as hackers can also use ping requests as a reconnaissance tool to gather information about a target network or system. To block or unblock the ping requests on Linux Mint 21 there are two primary ways one is through kernel parameters and the other is by iptables, both are discussed in this guide.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.