最近,我的一位朋友问我该如何禁止IPv6。在搜索了一番之后,我找到了下面的方案。下面就是在我的CentOS 7 迷你服务器禁止IPv6的方法。
你可以用两个方法做到这个。
编辑文件/etc/sysctl.conf,
vi /etc/sysctl.conf添加下面的行:
net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1如果你想要为特定的网卡禁止IPv6,比如,对于enp0s3,添加下面的行。
net.ipv6.conf.enp0s3.disable_ipv6 = 1保存并退出文件。
执行下面的命令来使设置生效。
sysctl -p要在运行的系统中禁止IPv6,依次输入下面的命令:
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6 echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6或者,
sysctl -w net.ipv6.conf.all.disable_ipv6=1 sysctl -w net.ipv6.conf.default.disable_ipv6=1就是这样。现在IPv6已经禁止了。
你可能在禁止IPv6后遇到一些问题
如果你在禁止IPv6后SSH遇到问题,按照下面的做。
编辑 /etc/ssh/sshd_config 文件
vi /etc/ssh/sshd_config
找到下面的行:
#AddressFamily any把它改成:
AddressFamily inet或者,在这行的前面去掉注释(#):
#ListenAddress 0.0.0.0接着重启ssh来使改变生效。
systemctl restart sshd如果你在禁止Ipv6后启动postfix遇到问题,编辑/etc/postfix/main.cf:
vi /etc/postfix/main.cf注释掉配置中的localhost部分,并且使用ipv4回环。
#inet_interfaces = localhost inet_interfaces = 127.0.0.1就是这样,干杯!
----------------------------------------------------------------------------------------------------------------------------