服务器出站优先使用ipv4

修改/etc/gai.conf文件,末尾添加:

1
precedence ::ffff:0:0/96  100
或者:
ipv4 优先
1
sed -i 's/#precedence ::ffff:0:0\/96  100/precedence ::ffff:0:0\/96  100/' /etc/gai.conf
ipv6 优先
1
sed -i 's/precedence ::ffff:0:0\/96  100/#precedence ::ffff:0:0\/96  100/' /etc/gai.conf

重启网络,通过以下命令查询网络管理工具:

1
systemctl list-units | grep network

networking管理网络,输入以下命令重启:

1
systemctl restart networking

如果是 systemd-networkd

1
systemctl restart systemd-networkd

如果是 NetworkManager

1
systemctl restart NetworkManager

或者重启接口:

1
networkctl reconfigure ens3

验证(或者通过ping命令):

1
getent ahosts google.com
1
curl ip.sb

检查网络状态:

1
ip addr