How to Disable the Ping (ICMP) Response in Linux using sysctl

The Security Risk of ICMP Responses

By default, if you open a terminal and ping a Linux server’s IP address (e.g., ping 192.168.1.50), the server will happily respond with an ICMP Echo Reply. While this is incredibly useful for network administrators attempting to diagnose routing issues, it is also highly useful to malicious actors.

Hackers use automated network scanners to aggressively ping entire subnets. If your server responds to the ping, the scanner logs the IP address as “alive” and immediately begins launching deeper port scans and brute-force SSH attacks against it. By configuring your Linux server to silently drop all incoming ICMP ping requests, you effectively make the machine “invisible” to basic automated sweeps.

Method 1: The Temporary sysctl Fix

You can instantly disable the ping response by modifying a kernel parameter in the virtual /proc filesystem. Because you are modifying kernel behavior, you must use sudo or run the command as the root user.

sudo sysctl -w net.ipv4.icmp_echo_ignore_all=1

The moment you press enter, the server will stop responding to pings. Any machine attempting to ping your server will simply see “Request timeout.”

However, because this command only modifies the active kernel memory, the setting will be completely erased the next time the server reboots, and the machine will begin responding to pings again.

Method 2: The Permanent Configuration

To make the change survive a system reboot, you must hardcode the kernel parameter into the sysctl.conf configuration file.

  1. Open the configuration file in a terminal text editor (like nano):
sudo nano /etc/sysctl.conf
  1. Scroll to the very bottom of the file and paste the following line:
net.ipv4.icmp_echo_ignore_all = 1
  1. Save the file and exit the text editor (in nano, press Ctrl+O, Enter, then Ctrl+X).
  2. To force the Linux kernel to immediately read the file and apply the new permanent setting, run the following command:
sudo sysctl -p

How to Re-Enable Ping

If you are troubleshooting a complex network routing issue and you legitimately need the server to respond to your pings, you can easily reverse the process.

Simply open the /etc/sysctl.conf file, change the 1 to a 0, and run sudo sysctl -p again. The server will instantly become visible to the network once more.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.