Linux 禁用 IPV6

验证是否开启 ipv6

1
2
3
4
# ifconfig -a | grep inet6
inet6 fe80::42:b8ff:feb5:4214 prefixlen 64 scopeid 0x20<link>
inet6 fe80::5054:ff:fec3:d3bb prefixlen 64 scopeid 0x20<link>
inet6 ::1 prefixlen 128 scopeid 0x10<host>

出现 inet6 相关即为开启 ipv6

修改内核模块配置

编辑 /etc/default/grub 文件并在 GRUB_CMDLINE_LINUX 中添加 ipv6.disable=1

如果是 Ubuntu 可能还有 GRUB_CMDLINE_LINUX_DEFAULT,同样也需要添加 ipv6.disable=1

1
2
3
4
# cat /etc/default/grub
......
GRUB_CMDLINE_LINUX="crashkernel=auto console=ttyS0 console=tty0 panic=5 net.ifnames=0 biosdevname=0 intel_idle.max_cstate=1 intel_pstate=disable"
......

修改后为

1
2
3
4
# cat /etc/default/grub
......
GRUB_CMDLINE_LINUX="crashkernel=auto console=ttyS0 console=tty0 panic=5 net.ifnames=0 biosdevname=0 intel_idle.max_cstate=1 intel_pstate=disable ipv6.disable=1"
......

应用更改

1
2
3
4
# CentOS
grub2-mkconfig -o /boot/grub2/grub.cfg
# Ubuntu
update-grub

重启

1
shutdown -r now