现在新版本的Linux操作系统默认启用Internet协议版本6(IPv6)。但是,在某些情况下,某些用户可能会发现需要禁用IPv6支持或在禁用后重新启用它。本文将详细介绍如何禁用或启用IPV6服务。
一、禁用IPv6
禁用IPv6有如下3中方法。
(一)在NetworkManager中禁用IPv6.
1.对于 RHEL7 和 RHEL 8.0:
[root@shizhanxia.com ~]# nmcli connection modify ipv6.method "ignore"
2.对于RHEL8.1及更高版本和9:
[root@shizhanxia.com ~]# nmcli connection modify ipv6.method "disabled"
(二)通过 sysctl 设置禁用 IPv6
1.创建一个名为的新文件/etc/sysctl.d/ipv6.conf包含以下文本。
# First, disable for all interfaces net.ipv6.conf.all.disable_ipv6 = 1 # If using the sysctl method, the protocol must be disabled on all specific interfaces, as well. net.ipv6.conf..disable_ipv6 = 1 # By default, we do not disable IPv6 on localhost, as it's important for multiple # components. If you want to disable it anyway, change the following # value to 1. net.ipv6.conf.lo.disable_ipv6 = 0
2.然后需要重新加载新设置:
[root@shizhanxia.com ~]# sysctl -p /etc/sysctl.d/ipv6.conf
3.创建初始 RAM 磁盘映像的备份:
[root@shizhanxia.com ~]# cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)_$(date +%Y-%m-%d_%H%M%S).img
4.然后使用以下命令重建 initramfs:
[root@shizhanxia.com ~]# dracut -f -v
验证
[root@shizhanxia.com ~]# lsinitrd /boot/initramfs-$(uname -r).img | grep 'etc/sysctl.d/ipv6.conf'
5.注释掉在 /etc/hosts中找到的任何IPv6 地址,包括 ::1 本地主机地址(如果您在步骤 #1 中也在本地主机上禁用了 IPv6)。
[root@shizhanxia.com ~]# cp -p /etc/hosts /etc/hosts.disableipv6 [root@shizhanxia.com ~]# sed -i 's/^[[:space:]]*::/#::/' /etc/hosts
(三)禁用 IPv6 内置内核模块
原创文章,作者:保哥,如若转载,请注明出处:https://www.shizhanxia.com/1881.html