How to enable/disable ping on Linux system

To prevent others from discovering and potentially attacking your machine through network ping scans, you can configure your system to disable or block the ping command.

 

Linux systems allow ping responses by default. The ability to ping is determined by two factors:

  • Kernel parameters
  • Firewall

To allow ping, both factors need to be enabled. If either of the two factors prohibits ping, it will not be possible to ping the system.

 

一.The method to disable ping at the kernel level is as follows:

 

First, let's check if the IP is responding properly by using the ping.pe website. Input the IP and test the connectivity. This will show if the target IP allows ping requests.

 

 

Temporarily disabling ping.  

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

 

At this point, if we check the IP, we can see that ping is disabled. If we still want to test the IP connectivity, we can perform a ping test on a specific port. Here, we can see that the connection is successful. Since ping is temporarily disabled, the ping functionality will be restored after a machine reboot.

 

 

Permanent disabling of ping 

#vi  /etc/sysctl.conf   #Enter the configuration file.

Add a line inside:net.ipv4.icmp _echo_ignore_all= 1 

 

If you already have "net.ipv4.icmp_echo_ignore_all" in the file, you can directly modify the value after the "=" sign. (0 means allow, 1 means deny)

#  sysctl -p    #Apply the new configuration. 

 

Check if ping is disabled.
# cat /proc/sys/net/ipv4/icmp_echo_ignore_all
The value "1" indicates that ping is disabled, while the value "0" indicates that ping is enabled.
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to switch to a different repository for CentOS 8 EOL

 CentOS 8 reached its end of life at the end of 2021. When using yum repositories for...

To change the network interface name in CentOS 7.x

一.modify GRUB 1.Edit the GRUB configuration file by running the command: `vi...

To modify the hostname on CentOS

Method One:   1.Open a terminal or SSH into the Linux system. 2.Log in to the system with...

An incorrect configuration in the /etc/fstab file on the Linux system is causing login issues

Encountering communication issues with the machine, I checked the system error messages through...

How to use the atop monitoring tool in Linux

Atop is a monitoring tool used to monitor resources and processes in Linux systems. It...