Linux prohibit Ping method detailed

Source: Internet
Author: User
Tags numeric value vps iptables

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.