提权
sudo -i
通过nmcli
禁用
sudo nmcli device modify enp125s0f1 ipv6.method ignore
解释:
sudo
:以管理员权限运行命令。nmcli device modify
:修改设备属性。enp125s0f1
:要修改的连接的名称。ipv6.method ignore
:将 IPv6 方法设置为 ignore,以禁用 IPv6。
执行此命令后,您需要重新启动网络管理器服务以应用更改:
效果
gxxc@gxxc-PC:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN group default qlen 1000
link/tunnel6 :: brd ::
3: enp125s0f0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether ff:ff:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff
4: enp125s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether ff:ff:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff
inet IP地址/24 brd 网络号 scope global noprefixroute enp125s0f1
valid_lft forever preferred_lft forever
inet6 ff:ff:ff:ff:ff:ff/64 scope link
valid_lft forever preferred_lft forever
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether ff:ff:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
gxxc@gxxc-PC:~$ sudo nmcli device modify enp125s0f1 ipv6.method ignore
成功重新应用连接到设备 "enp125s0f1"。
gxxc@gxxc-PC:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN group default qlen 1000
link/tunnel6 :: brd ::
3: enp125s0f0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether ff:ff:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff
4: enp125s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether ff:ff:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff
inet IP地址/24 brd 网络号 scope global noprefixroute enp125s0f1
valid_lft forever preferred_lft forever
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether ff:ff:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
gxxc@gxxc-PC:~$
结果中可以看到,执行了命令之后,IP信息已经没有
inet6 ff:ff:ff:ff:ff:ff/64 scope link
信息中IP和mac地址已经经过处理
请注意,此更改仅适用于指定的网卡,不会禁用整个系统的 IPv6 功能。如果您需要完全禁用 IPv6,请参考其他资源,如禁用内核模块或配置 sysctl。
通过sysctl配置
配置
# 删除原配置
sed -i '/net.ipv6.conf.all.disable_ipv6/d' /etc/sysctl.conf
sed -i '/net.ipv6.conf.default.disable_ipv6/d' /etc/sysctl.conf
sed -i '/net.ipv6.conf.lo.disable_ipv6/d' /etc/sysctl.conf
# 删除原配置
sed -i '/net.ipv6.conf.all.disable_ipv6/d' /etc/sysctl.d/*
sed -i '/net.ipv6.conf.lo.disable_ipv6/d' /etc/sysctl.d/*
sed -i '/net.ipv6.conf.default.disable_ipv6/d' /etc/sysctl.d/*
# 写入新配置
echo 'net.ipv6.conf.all.disable_ipv6 = 1'> /etc/sysctl.d/ipv6.conf
echo 'net.ipv6.conf.lo.disable_ipv6 = 1'>> /etc/sysctl.d/ipv6.conf
echo 'net.ipv6.conf.default.disable_ipv6 = 1'>> /etc/sysctl.d/ipv6.conf
sysctl --system | grep net.ipv6.conf