Several ways Centos7 prohibits ping

Several ways to prohibit ping in Centos7

Temporarily ban ping

Change the 0 in the /proc/sys/net/ipv4/icmp_echo_ignore_all file to 1 temporarily, so as to prohibit all requests of ICMP packets, and achieve the effect of prohibiting Ping. When other hosts in the network ping this host, they will display "Request timeout ", but the server can ping other hosts at this time.

# Ban ping
echo 1>/proc/sys/net/ipv4/icmp_echo_ignore_all
# Enable ping
echo 0>/proc/sys/net/ipv4/icmp_echo_ignore_all

Permanently ban ping

# Edit configuration
vim /etc/sysctl.conf
# Set ping prohibited (if you have this configuration, you don't need to add it repeatedly, just update the value)
net.ipv4.icmp_echo_ignore_all =1
# Refresh configuration
sysctl -p

# Enable ping
net.ipv4.icmp_echo_ignore_all =0

IPTABLES firewall prohibits ping

Ping
iptables -A INPUT -p icmp --icmp-type 8-s 0/0-j DROP
Enable ping
iptables -D INPUT -p icmp --icmp-type 8-s 0/0-j DROP

# Parameter notes
- A: Add firewall rules.
INPUT: Inbound rules.-p icmp: Specify the protocol for packet inspection as ICMP.--icmp-type 8: Specify the ICMP type as 8.-s: Specify IP and mask, "0/0" means this rule applies to all IPs and masks.-j: Specify the target rule, that is, what should be done when the package matches,"DROP"Means discard.

Precautions###

After banning ping by modifying the configuration method, the internal ping will also be invalid. After pinging through the firewall, you can ping your own internal network.

effect

Take a little gift away, come to Jianshu and follow me

( adsbygoogle = window.adsbygoogle || []).push({});

Recommended Posts

Several ways Centos7 prohibits ping