Skip to content

Enable and Disable Ping in Linux



Ping is a network diagnostic tool used to test the connectivity between two devices over a network. It sends an ICMP Echo request to the destination device and waits for a reply. In Linux, ping is enabled by default. However, there may be situations where you need to disable ping for security reasons, or enable it to troubleshoot network issues. In this blog post, we will discuss how to enable and disable ping in Linux.

I. Temporary Solution

Enable Ping

echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all

Disable Ping

echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all

II. Permanent Solution

Modify file: /etc/sysctl.conf

Allow Ping

Add a line:


Disallow Ping

Add a line:


After modification, use the following command to make it effective:

sysctl -p

Enabling Ping in Linux

To enable ping in Linux, you need to make sure that the firewall on your system is not blocking it. By default, most Linux distributions have the firewall enabled. You can use the following command to check the status of the firewall:

sudo ufw status

If the firewall is active, you need to allow ICMP traffic. Use the following command to allow ICMP traffic:

sudo ufw allow icmp

Once you have allowed ICMP traffic, you should be able to ping other devices on the network.

Disabling Ping in Linux

Disabling ping can be useful in preventing potential attacks on your system. To disable ping in Linux, you need to modify the kernel parameter that controls ICMP Echo requests. You can do this by editing the /etc/sysctl.conf file. Open the file in a text editor and add the following line at the end:


Save the file and run the following command to apply the changes:

sudo sysctl -p

This will disable ping on your system. To re-enable ping, simply remove the line you added to the /etc/sysctl.conf file and run the sudo sysctl -p command again.

Leave a message