CentOS 7 - 禁止 ping 响应
环境信息
操作系统:
# rpm -q centos-release
centos-release-7-6.1810.2.el7.centos.x86_64
禁止 ping 响应
编辑 /etc/sysctl.conf 文件,加入 net.ipv4.icmp_echo_ignore_all=1
(0 允许,1 禁止):
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.icmp_echo_ignore_all=1
修改完成之后,执行 sysctl -p
命令从文件读取值,使配置生效。
测试
在另一台主机中使用 ping 命令测试配置是否生效:
# ping -c 10 192.168.88.171 // -c 10 表示在 10 次回答之后停止
PING 192.168.88.171 (192.168.88.171) 56(84) bytes of data.
--- 192.168.88.171 ping statistics ---
10 packets transmitted, 0 received, 100% packet loss, time 9196ms