1, by modifying the configuration file
This method requires root permissions, and after the success of the set can not ping the computer, the machine can not ping others, may bring a little trouble.
(1) Directly modify the/proc/sys/net/ipv4/icmp_echo_ignore_all file (this file is read-only by default)
The file has only one numeric value:
Disable ping for open (run) after changing this value to "1"
Disable ping for shutdown (stop) after changing this value to "0"
(2) Direct input command line settings (this method requires root permissions)
Enter the following instructions directly at the command line
The code is as follows |
Copy Code |
Running: no ping Echo 1 >/proc/sys/net/ipv4/icmp_echo_igore_all Stop: Ping is not allowed echo 0 >/proc/sys/net/ipv4/icmp_echo_igore_all |
After testing the above methods in the OpenVZ VPS (CentOS 5.5, 5.6) set failed, the other hosting methods of the system temporary unconditional test (figure)
Error tip: Disallowed operation (Operation not permitted)
Attach: Set up automatically prohibit Ping method
To disable the ping response immediately after powering up, add the run statement to the/etc/rc.d/rc.local.
2. Use iptables limit (recommended)
This method under the OpenVZ VPS, also in the virtual machine test pass, prohibit others ping this machine at the same time, this machine can ping others.
(1) Set the method is very simple, in the SSH input the following command, enter directly into effect without restarting iptables.
The code is as follows |
Copy Code |
Iptables-a input-p ICMP--icmp-type 8-s 0/0-j DROP |
The above operation is to use iptables discard the ICMP packets from the extranet request, to achieve the ban ping effect. Instead, look below.
(2) Remove the Set method (that is, delete this rule)
The code is as follows |
Copy Code |
iptables-d input-p ICMP--icmp-type 8-s 0/0-j DROP |
Share your own methods and points
code is as follows |
copy code |
Root@redhat7 root]# echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all If you want to recover, just: [Root@redhat7 root]# echo 0 >/proc /sys/net/ipv4/icmp_echo_ignore_all |