VPS关闭IPV6

现在IPv4+IPv6双栈的服务器越来越普及,但有些设备不支持或其他原因需要关闭IPV6。

1、编辑sysctl配置文件

1
vim /etc/sysctl.conf

文件末尾添加以下内容

1
2
3
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

保存文件并退出编辑器

2、运行以下命令应用更改

1
sysctl -p

3、验证IPv6是否已禁用

1
ip a | grep inet6

没有输出代表已经成功

4、如果重启后失效

创建/etc/rc.local文件,文件内容如下:

1
2
3
4
5
#!/bin/bash
# /etc/rc.local
/etc/sysctl.d
/etc/init.d/procps restart
exit 0

赋予执行权限

1
chmod 755 /etc/rc.local
Author

MelonCloud

Posted on

2024-11-01

Updated on

2024-11-01

Licensed under

Comments