How to enable / disable Ping using iptables in Debian 10

In a production environment, it is common practice to disable network ping for security reasons so that no one can ping your server. However, ping is enabled by default on Linux servers.

In this tutorial, I will show you how you can use the iptables firewall to disable or enable the ping port. I ran the commands on Debian 10. However, it should work on most other Linux systems.

Ping checking in iptables

Open a terminal and check the status of the ping using the following command.


As you can see from the following screenshot, ping is enabled in our system.

Disabling ping using iptables

When we verify that ping is enabled, let’s disable it in iptables.

Open a terminal with superuser rights and run the following command.

$ sudo iptables -A INPUT -p icmp --icmp-type echo-request -j REJECT

Ping is disabled

Again, let’s check the rule list in iptable using the following command.

iptables -L

In the next screenshot, we clearly see that the new rule is in iptables.

Iptables rules list

Let’s now check the ping status with the following command.


Ping Test Status

As you can see in the screenshot above, ping is now disabled.

Enable ping in iptables

If you want to enable ping in iptables, run the following command to remove the above rule.

Enable ping in the IPTables firewall

Enter the following command and you will notice that there are no rules in iptables.

Iptable firewall rule list

You can also ping the local host and you will notice that you are successful.


Test ping after enabling it in the firewall

I hope this tutorial has been helpful to you. Wait for the new article.

How to enable / disable Ping using iptables in Debian 10