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

In this tutorial, I am going to show you the way you can use iptables firewall to disable or enable the ping port. I have run the commands on Debian 10. However, it should work on most other Linux systems as well.

Checking Ping in iptables

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

ping 127.0.0.1

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

Test network ping

Disabling Ping with iptables

When we have verified that the ping is enabled, let us disable it in iptables.

Open the terminal with root privileges and execute the following command.

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

Ping disabled

Again, let us check the list of rules in iptable using the following command.

iptables -L

From the following screenshot, we can clearly see that the new rule is in iptables.

List iptables rules

Let us check the ping status now using the following command.

ping 127.0.0.1

Test ping status

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

Enabling Ping in iptables

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

Enable ping in IPTables firewall

Issue the following command and you will notice that there is no rule in iptables.

List iptable firewall rules

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

ping 127.0.0.1

Test ping after enabling it in the firewall

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

How to Enable/Disable Ping using iptables on Debian 10
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.