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
Again, let’s check the rule list in iptable using the following command.
In the next screenshot, we clearly see that the new rule is in iptables.
Let’s now check the ping status with the following command.
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.
Enter the following command and you will notice that there are no rules in iptables.
You can also ping the local host and you will notice that you are successful.
I hope this tutorial has been helpful to you. Wait for the new article.
How to enable / disable Ping using iptables in Debian 10