我有一个带有 wifi 和有线网络的设备。每个网络都有一个 nmcli 连接,并且 eth0 上的连接优先于 wlan0。问题是,即使没有电缆插入 eth0,nmcli 也会认为它已启动并且其连接变为活动状态,因此使用 wifi 的实际连接无法正常工作。以下是拔下网线并连接 wifi 时的一些信息:
~$ cat /sys/class/net/eth0/operstate
down
~$ sudo ethtool eth0
Settings for eth0:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 10Mb/s
Duplex: Half
Port: MII
PHYAD: 0
Transceiver: external
Auto-negotiation: on
Link detected: no
~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether 76:14:a0:8d:39:51 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.100/24 brd 192.168.0.255 scope global eth0
inet6 fe80::7414:a0ff:fe8d:3951/64 scope link
valid_lft forever preferred_lft forever
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 18:93:7f:35:a3:30 brd ff:ff:ff:ff:ff:ff
inet 10.42.0.61/24 brd 10.42.0.255 scope global wlan0
inet6 fe80::1a93:7fff:fe35:a330/64 scope link
valid_lft forever preferred_lft forever
到目前为止,一切都表明 eth0 已关闭,但从现在开始,信息是错误的
~$ ifconfig
eth0 Link encap:Ethernet HWaddr 76:14:a0:8d:39:51
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::7414:a0ff:fe8d:3951/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:314 (314.0 B)
Interrupt:114
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1344 errors:0 dropped:0 overruns:0 frame:0
TX packets:1344 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:166860 (166.8 KB) TX bytes:166860 (166.8 KB)
wlan0 Link encap:Ethernet HWaddr 18:93:7f:35:a3:30
inet addr:10.42.0.61 Bcast:10.42.0.255 Mask:255.255.255.0
inet6 addr: fe80::1a93:7fff:fe35:a330/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:234 errors:0 dropped:0 overruns:0 frame:0
TX packets:153 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21791 (21.7 KB) TX bytes:19559 (19.5 KB)
~$ nmcli d show
GENERAL.DEVICE: eth0
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 76:14:A0:8D:39:51
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: wired_con
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/0
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.0.100/24
IP4.GATEWAY: 192.168.0.1
IP6.ADDRESS[1]: fe80::7414:a0ff:fe8d:3951/64
IP6.GATEWAY:
GENERAL.DEVICE: wlan0
GENERAL.TYPE: wifi
GENERAL.HWADDR: 18:93:7F:35:A3:30
GENERAL.MTU: 0
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: wave_admin
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1
IP4.ADDRESS[1]: 10.42.0.61/24
IP4.GATEWAY: 10.42.0.1
IP4.DNS[1]: 10.42.0.1
IP6.ADDRESS[1]: fe80::1a93:7fff:fe35:a330/64
IP6.GATEWAY:
GENERAL.DEVICE: lo
GENERAL.TYPE: loopback
GENERAL.HWADDR: 00:00:00:00:00:00
GENERAL.MTU: 16436
GENERAL.STATE: 10 (unmanaged)
GENERAL.CONNECTION: --
GENERAL.CON-PATH: --
IP4.ADDRESS[1]: 127.0.0.1/8
IP4.GATEWAY:
IP6.ADDRESS[1]: ::1/128
IP6.GATEWAY:
~$ nmcli connection show --active
NAME UUID TYPE DEVICE
wave_admin 5843d36e-ef73-4f06-8d02-561ed320f235 802-11-wireless wlan0
wired_con 50218355-86b8-4134-af28-5585c542e886 802-3-ethernet eth0