How to Enable or Disable Ping on Linux: Kernel and iptables Settings
This guide explains why Linux ping responses depend on both kernel parameters and firewall rules, and provides step‑by‑step commands to temporarily or permanently enable or block ping using /proc/sys settings, sysctl configuration, and iptables rules.
Linux allows ICMP echo (ping) responses by default, but whether a system actually replies is controlled by two factors: a kernel parameter and the firewall configuration. Both must permit ping; if either blocks it, ping fails.
Kernel Parameter Configuration
Temporary change : modify the runtime value in /proc/sys/net/ipv4/icmp_echo_ignore_all. Setting the value to 0 enables ping, while 1 disables it.
# To temporarily disable ping (set to 1). Change to 0 to enable.
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_allPermanent change : add a line to /etc/sysctl.conf and reload the settings.
# Add this line to /etc/sysctl.conf
net.ipv4.icmp_echo_ignore_all=1
# Apply the new configuration
sysctl -pAfter editing, run sysctl -p to make the change effective. Replace 1 with 0 in the above line if you want to permanently enable ping.
Firewall (iptables) Configuration
These commands assume the kernel parameter is at its default (ping allowed). Use iptables to explicitly allow or block ICMP traffic.
Allow ping :
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPTYou can also temporarily stop the firewall entirely: service iptables stop Block ping (drop incoming echo requests):
iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -j DROPWith these kernel and iptables settings, you can control whether your Linux host responds to ping requests.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
