如何在 CentOS/RHEL 上禁用 ICMP 重定向

在这篇文章中,我们将看到如何禁用 ICMP 重定向处理,这可能有助于在混淆的交换机或者网络服务器将流量从选定路径分流的情况下保持网络连接。

从命令行禁用 ICMP 重定向

可以通过命令行关闭 ICMP 重定向处理,直到下一次重新启动,如下所示。

对于所有网络接口:

# /sbin/sysctl -w net.ipv4.conf.all.accept_redirects = 0
# /sbin/sysctl -w net.ipv4.conf.all.send_redirects   = 0
# /sbin/sysctl -w net.ipv6.conf.all.accept_redirects = 0
# /sbin/sysctl -w net.ipv6.conf.all.send_redirects   = 0

对于选定的网络接口,例如 eth0:

# /sbin/sysctl -w net.ipv4.conf.eth0.accept_redirects = 0
# /sbin/sysctl -w net.ipv4.conf.eth0.send_redirects   = 0
# /sbin/sysctl -w net.ipv6.conf.eth0.accept_redirects = 0
# /sbin/sysctl -w net.ipv6.conf.eth0.send_redirects   = 0
查看更多教程 https://on  itroad.com

永久禁用 ICMP 重定向

使用以下行创建文件 /etc/sysctl.d/50-icmp_redirect.conf:

# Uncomment the lines below as needed.
# Disable ICMP Redirect Globally
# net.ipv4.conf.all.accept_redirects = 0
# net.ipv4.conf.all.send_redirects   = 0
# net.ipv6.conf.all.accept_redirects = 0
# net.ipv6.conf.all.send_redirects   = 0
# Disable ICMP Redirect For A Selected NIC
# net.ipv4.conf.eth0.accept_redirects = 0
# net.ipv4.conf.eth0.send_redirects   = 0
# net.ipv6.conf.eth0.accept_redirects = 0
# net.ipv6.conf.eth0.send_redirects   = 0

取消注释适合部署的行。
更改将在重新启动后持续存在。

在当前环境中应用设置:

# sysctl --system       ## for CentOS/RHEL 7 and above
# sysctl -p             ## for CentOS/RHEL 6
日期:2020-09-17 00:12:28 来源:oir作者:oir