One - One Code All

Blog Content

linux系统关闭IPv6的方式

Linux-Mac   2013-12-18 19:40:15

IPv6被认为是IPv4的替代产品,它用来解决现有IPv4地址空间即将耗尽的问题。但目前,开启IPv6可能会导致一些问题。因此有时我们需要关闭IPv6。下面是IPv6的关闭方法应该适用于所有主流的Linux发行版包括Ubuntu、Debian、CentOS。


方法1:


编辑文件/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



方法 2:


要在运行的系统中禁止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已经禁止了。

 

可以通过ip address list 查看是否已经生效

 


在禁止IPv6后可能会遇到一些问题


问题1:


如果你在禁止IPv6后SSH时遇到问题,按照下面的做。

编辑 /etc/ssh/sshd_config 文件

vi /etc/ssh/sshd_config

找到下面的行:


#AddressFamily any


把它改成:


AddressFamily inet


或者,在这行的前面去掉注释(#):

#ListenAddress 0.0.0.0


接着重启ssh来使改变生效。

systemctl restart sshd



问题2:


如果你在禁止IPv6后启动postfix遇到问题,编辑/etc/postfix/main.cf:


vi /etc/postfix/main.cf


注释掉配置中的localhost部分,并且使用ipv4回环。


#inet_interfaces = localhost

inet_interfaces = 127.0.0.1


问题3:


mysql安装后监听IPv6地址

关闭IPv6后,编辑 /etc/my.cnf


在[mysqld]中添加 bind-addres=0.0.0.0


重启mysql  /etc/init.d/mysql restart



上一篇:数据科学工具箱之julia篇
下一篇:python库pandas的to_csv()使用方法

The minute you think of giving up, think of the reason why you held on so long.