Fork me on GitHub

CentOS禁用ipv6

CentOS禁用ipv6

前言

如何禁用ipv6?

实践操作

根本解决办法

修改grub,在引导时就不加载IPV6模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# vim /etc/default/grub       // 第6行添加ipv6.disable=1参数
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="ipv6.disable=1 crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap biosdevname=0 net.ifnames=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-02f22e022e08404a89d15e63ef1de03f
Found initrd image: /boot/initramfs-0-rescue-02f22e022e08404a89d15e63ef1de03f.img
done
# reboot
# lsmod|grep ipv6

修改内核参数

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

If the output is 0, IPv6 is enabled.
If the output is 1, IPv6 is already disabled.
修改前后ifconfig查看网卡信息区别


完整操作步骤:
Step 1: add this rule in /etc/sysctl.conf : net.ipv6.conf.all.disable_ipv6=1
Step 2: add this rule in /etc/sysconfig/network: NETWORKING_IPV6=no
Step 3: add this setting for each nic X (X is the corresponding number for each nic) in /etc/sysconfig/network-scripts/ifcfg-ethX: IPV6INIT=no
Step 4: disable the ip6tables service : chkconfig ip6tables off
Step 5: Reload the sysctl configuration: sysctl -p or reboot

FQA

注意:禁用IPV6后,可能会导致某些服务无法启动,比如VSFTP,对于VSFTP,需要修改如下设置

1
2
3
vim /etc/vsftpd/vsftpd.conf
listen=YES
listen_ipv6=NO

参考资料

https://blog.csdn.net/bluishglc/article/details/41390785

======================================================
希望各位朋友支持一下

本文作者:dongsheng
本文地址https://mds1455975151.github.io/archives/7da246ab.html
版权声明:转载请注明出处!

坚持技术分享,您的支持将鼓励我继续创作!