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.
As you can see from the following screenshot, the ping is enabled on our system.
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
Again, let us check the list of rules in iptable using the following command.
From the following screenshot, we can clearly see that the new rule is in iptables.
Let us check the ping status now using the following command.
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.
Issue the following command and you will notice that there is no rule in iptables.
You can also ping the localhost and you will notice that you are successful.
I hope this tutorial was helpful to you. Wait for the new article.