Time to learn how to disable ping in Linux.
You can’t avoid this step if you are doing a server hardening.
Run the following command to disable the ping request to your server.
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
This is a temporary method to disable ping. This will erase after reboot. To make it permanent, follow the steps given below.
Add the following lines to /etc/sysctl.conf
net.ipv4.icmp_echo_ignore_all = 1
Now update the changes using the following command.
That will disable incoming ICMP Requests or PIng requests in your system.
You can also do the same using Iptables. Please run the below command if you want to disable the ping request using IPtables.
iptables -A INPUT -p icmp -j DROP
Now save the firewall rules by executing the following command.
You just disabled incoming ping using the firewall.
( You only have to check this section if you have a CSF firewall installed )
Most of you may have a CSF firewall installed. If you want to know how to install CSF, please refer to the article –How to install CSF in Linux? It is easy to disable incoming ping using CSF. Find the steps below.
Edit the CSF main configuration file.
You can find the below lines.
# Allow incoming PING ICMP_IN = "1"
Change it as follows to disable ping.
ICMP_IN = "0"
Now restart CSF and LFD to update the changes.
/etc/init.d/csf restart /etc/init.d/lfd restart csf -r
That’s how you Disable Ping in Linux using CSF.