How to disable ping and enable ping in CentOS

Source: Internet
Author: User
By default, Linux allows Ping responses. whether or not the system allows Ping is determined by two factors: A, kernel parameters, B, and firewall. Ping is allowed only when two factors are allowed at the same time, one of the two factors cannot be pinged if Ping is disabled. The specific configuration method is as follows: A. kernel parameter settings 1. allow PING settings &

By default, Linux allows Ping responses. whether or not the system allows Ping is determined by two factors: A, kernel parameters, B, and firewall. Ping is allowed only when two factors are allowed at the same time, one of the two factors cannot be pinged if Ping is disabled.

 

The specific configuration method is as follows:

 

 A. kernel parameter settings

1. allow PING settings

A. The Command for temporarily allowing PING operation is: # echo 0>/proc/sys/net/ipv4/icmp_echo_ignore_all

B. The PING configuration method is permanently allowed.

/Etc/sysctl. confAdd a row

Net. ipv4.icmp _ echo_ignore_all = 1

If the line net. ipv4.icmp _ echo_ignore_all already exists, you can directly modify the value after the = sign (0 indicates allow, 1 indicates forbidden ).

After modification, executeSysctl-pMake the new configuration take effect.

2. disable Ping settings

A. The Command for temporarily disabling PING is: # echo 1>/proc/sys/net/ipv4/icmp_echo_ignore_all

B. The PING configuration method is permanently allowed.

/Etc/sysctl. confAdd a row

Net. ipv4.icmp _ echo_ignore_all = 0

If the line net. ipv4.icmp _ echo_ignore_all already exists, you can directly modify the value after =. (0 indicates allow, 1 indicates forbidden)

After modification, executeSysctl-pMake the new configuration take effect.

 

 

B. firewall settings (Note: The premise of this method is that the kernel configuration is the default value, that is, Ping is not prohibited)

Take Iptables firewall as an example. For more information about firewall operations, see the official firewall documentation.

1. allow PING settings

Iptables-a input-p icmp -- icmp-type echo-request-j ACCEPT

Iptables-a output-p icmp -- icmp-type echo-reply-j ACCEPT

Or you can temporarily stop the firewall operation.

Service iptables stop

 

2. disable PING settings

Iptables-a input-p icmp -- icmp-type 8-s 0/0-j DROP

Related Article

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.