打开和禁用IPV6的方法

基于linux7
                            禁止
一:禁止ipv6嵌入内核模
1.编辑 /etc/default/grub增加 ipv6.disable=1 到 GRUB_CMDLINE_LINUX ,例如下面的方法:    
    GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/swap crashkernel=auto rd.lvm.lv=rhel/root ipv6.disable=1"

2.运行 grub2-mkconfig命令去重新产生grub.cfg文件:
        # grub2-mkconfig -o /boot/grub2/grub.cfg

在UEFI系统上,运行一下命令:
        # grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

重启系统后有效
如果以上方法有selinux的报错,在audit.log中发现诸如avc: denied { module_request } 的报错,可再采用方法二禁止:

二:通过/etc/sysctl.d/ipv6.conf文件禁止ipv6
    1.创建一个新文件/etc/sysctl.d/ipv6.conf,并增加以下条目:
        # To disable for all interfaces
n
            net.ipv6.conf.all.disable_ipv6 = 1
#
        # the protocol can be disabled for specific interfaces as well.
n
            net.ipv6.conf.<interface>.disable_ipv6 = 1
     2.重新加载新设置
            sysctl -p /etc/sysctl.d/ipv6.conf

 3.重构init RAM DISK image
            dracut -f
二:使能ipv6
1.编辑 /etc/default/grub去掉ipv6.disable=1在GRUB_CMDLINE_LINUX字段中 ,例如下面的方法:    GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/swap crashkernel=auto rd.lvm.lv=rhel/root"

2.运行 grub2-mkconfig命令去重新产生grub.cfg文件:
        # grub2-mkconfig -o /boot/grub2/grub.cfg

在UEFI系统上,运行一下命令:
        # grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

3.删除文件:包含以下条目的文件 /etc/sysctl.d/ipv6.conf:
        # To disable for all interfaces
n
        net.ipv6.conf.all.disable_ipv6 = 1
#
        # the protocol can be disabled for specific interfaces as well.
n
        net.ipv6.conf.<interface>.disable_ipv6 = 1

4. 重构init RAM DISK image
        #dracut -f
5.检查 /etc/ssh/sshd_config文件,确保 AddressFamily 条目备注释:
        #AddressFamily inet
6.确保/etc/hosts文件中存在下行内容,并没有注释掉:
        ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

7.重启系统生效

参考红帽链接:https://access.redhat.com/solutions/8709(包含4 5 6红帽版本的方法)

猜你喜欢

转载自blog.csdn.net/hzj_001/article/details/81542625
今日推荐