• RHEL7禁用IPV6


    1.查看是否开启了IPV6

    通过ifconfig,能看到inet6说明开启了IPV6

    # ifconfig -a | grep inet6
          inet6 fe80::211:aff:fe6a:9de4 prefixlen 64 scopeid 0x20
          inet6 ::1 prefixlen 128 scopeid 0x10[host]

    或者

    # cat /proc/sys/net/ipv6/conf/all/disable_ipv6

    输出结果0,表示开启了ipv6;输出结果1,表示禁用了ipv6。

     

    2.通过修改内核进行修改

    可以通过修改内核进行配置。

    # vi /etc/default/grub
    GRUB_TIMEOUT=1
    GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
    GRUB_DEFAULT=saved
    GRUB_DISABLE_SUBMENU=true
    GRUB_TERMINAL="serial console"
    GRUB_SERIAL_COMMAND="serial --speed=115200"
    GRUB_CMDLINE_LINUX="ipv6.disable=1 console=tty0 crashkernel=auto console=ttyS0,115200"
    GRUB_DISABLE_RECOVERY="true"
    # grub2-mkconfig -o /boot/grub2/grub.cfg
    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-3.10.0-1062.12.1.el7.x86_64
    Found initrd image: /boot/initramfs-3.10.0-1062.12.1.el7.x86_64.img
    Found linux image: /boot/vmlinuz-3.10.0-957.1.3.el7.x86_64
    Found initrd image: /boot/initramfs-3.10.0-957.1.3.el7.x86_64.img
    Found linux image: /boot/vmlinuz-0-rescue-05cb8c7b39fe0f70e3ce97e5beab809d
    Found initrd image: /boot/initramfs-0-rescue-05cb8c7b39fe0f70e3ce97e5beab809d.img
    done

    然后,重启系统。

    # root

    修改之后,可以使用以下命令进行验证:

    # lsmod | grep ipv6

    这种方式需要重启系统。

     

    通过以下方式可以不用重启系统:

    3.添加以下规则到/etc/sysctl.conf

    # vi /etc/sysctl.conf
    ........................................................................
    net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1
    # 或者执行
    sed -i '$ a\net.ipv6.conf.all.disable_ipv6 = 1\nnet.ipv6.conf.default.disable_ipv6 = 1' /etc/sysctl.conf

    4.添加以下规则到/etc/sysconfig/network

    # vi /etc/sysconfig/network
    NETWORKING_IPV6=no
    # 或者执行
    sed -i '$ a\NETWORKING_IPV6=no' /etc/sysconfig/network

    5.修改每个网卡的配置

    # vi /etc/sysconfig/network-scripts/ifcfg-ethX
    IPV6INIT=no

    6.禁用ip6tables服务

    systemctl status ip6tables
    systemctl stop ip6tables
    systemctl disable ip6tables

    7.重新加载sysctl配置

    执行sysctl -p使修改生效

    # sysctl -p

    这样修改后,不需要重启就可以生效。

     

    如果配置了sshd_config中的AddressFamily,要确保没有配置成inet6

    # AddressFamily any             IPV4和IPV6协议家族用哪个,any表示二者均有
    或者设置为:
    # AddressFamily inet

    或者
    sed -i '$ a\AddressFamily inet' /etc/ssh/sshd_config

    修改了sshd_config文件需要重启sshd服务

    # systemctl restart sshd

     

    注意:禁用IPV6后,可能会导致某些服务无法启动,比如VSFTP,对于VSFTP,需要修改/etc/vsftpd/vsftpd.conf文件中的listen和listen_ipv6两个选项:

    listen=YES
    listen_ipv6=NO

    8.关闭特定网卡的IPV6

    如果想关闭特定网卡的IPV6,可以使用sysctl命令,需要指定特定的网卡

    语法:

    net.ipv6.conf.[interface].disable_ipv6 = [value]

    ·interface – 网卡名 ·value – 0 (开启) 、 1 (关闭) ipv6

     

    这里以eth0为例:

    # sysctl net.ipv6.conf.eth0.disable_ipv6=1
    net.ipv6.conf.eth0.disable_ipv6 = 1

    # sysctl net.ipv6.conf.default.disable_ipv6=1
    net.ipv6.conf.default.disable_ipv6 = 1

     

  • 相关阅读:
    【博弈论】K倍动态减法游戏
    【博弈论】翻硬币游戏8种模型
    P4124 [CQOI2016]手机号码(数位DP,前导0)
    AtCoder Beginner Contest 146
    Sumitomo Mitsui Trust Bank Programming Contest 2019
    ICPC 2018 Nanjing Regional
    模拟退火基础学习&模板
    AtCoder Beginner Contest 117
    AtCoder Beginner Contest 118
    AtCoder Beginner Contest 119
  • 原文地址:https://www.cnblogs.com/abclife/p/15828248.html
Copyright © 2020-2023  润新知