![默认网关从路由表中消失](https://linux22.com/image/1394257/%E9%BB%98%E8%AE%A4%E7%BD%91%E5%85%B3%E4%BB%8E%E8%B7%AF%E7%94%B1%E8%A1%A8%E4%B8%AD%E6%B6%88%E5%A4%B1.png)
我在笔记本电脑上使用 NetworkManager (Arch Linux) 来连接无线网络。我使用官方的 GNOME GUI。一切正常,但半小时左右后网络仍然连接,但默认网关从路由表中消失了。
➜ log ip r
10.135.1.0/24 dev wlan0 proto kernel scope link src 10.135.1.3 metric 303
10.135.1.3 via 127.0.0.1 dev lo metric 303
默认网关应该是 10.135.1.138,我实际上可以 ping 通它。如果我重新连接、重新启动 NetworkManager 或使用“ip r”手动将其添加回来,我可以恢复它,但半小时后它会再次消失。
我尝试了两种不同的 WiFi 驱动程序,但都出现了同样的问题。我尝试使用 wicd 代替 NetworkManager,似乎解决了问题。但是,由于其他几个原因,我对 wicd 并不满意,我很好奇 NetworkManager 出了什么问题。我检查了 NetworkManager 运行时 netctl 和 wicd 是否被禁用(是否有其他服务可能会干扰它?)。
这是过去一小时的日志。不过,我没发现任何可疑的东西:
Jan 18 17:36:39 tarsonis NetworkManager[2382]: <info> (wlan0): device state change: prepare -> config (reason 'none') [40 50 0]
Jan 18 17:36:39 tarsonis NetworkManager[2382]: <info> Activation (wlan0/wireless): connection 'KrustyKrab' has security, and secrets exist. No new secrets needed.
Jan 18 17:36:39 tarsonis NetworkManager[2382]: <info> Config: added 'ssid' value 'KrustyKrab'
Jan 18 17:36:39 tarsonis NetworkManager[2382]: <info> Config: added 'scan_ssid' value '1'
Jan 18 17:36:39 tarsonis NetworkManager[2382]: <info> Config: added 'key_mgmt' value 'WPA-PSK'
Jan 18 17:36:39 tarsonis NetworkManager[2382]: <info> Config: added 'auth_alg' value 'OPEN'
Jan 18 17:36:39 tarsonis NetworkManager[2382]: <info> Config: added 'psk' value '<omitted>'
Jan 18 17:36:39 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Stage 2 of 5 (Device Configure) complete.
Jan 18 17:36:39 tarsonis NetworkManager[2382]: <info> Config: set interface ap_scan to 1
Jan 18 17:36:39 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: inactive -> scanning
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: scanning -> authenticating
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: authenticating -> associating
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: associating -> 4-way handshake
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: 4-way handshake -> completed
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> Activation (wlan0/wireless) Stage 2 of 5 (Device Configure) successful. Connected to wireless network 'KrustyKrab'.
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Stage 3 of 5 (IP Configure Start) scheduled.
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Stage 3 of 5 (IP Configure Start) started...
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> (wlan0): device state change: config -> ip-config (reason 'none') [50 70 0]
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Beginning DHCPv4 transaction (timeout in 45 seconds)
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> dhcpcd started with pid 2403
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Beginning IP6 addrconf.
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Stage 3 of 5 (IP Configure Start) complete.
Jan 18 17:36:40 tarsonis NetworkManager[2382]: <info> (wlan0): DHCPv4 state changed nbi -> preinit
Jan 18 17:36:50 tarsonis NetworkManager[2382]: <info> (wlan0): DHCPv4 state changed preinit -> bound
Jan 18 17:36:50 tarsonis NetworkManager[2382]: <info> address 10.135.1.3
Jan 18 17:36:50 tarsonis NetworkManager[2382]: <info> prefix 24 (255.255.255.0)
Jan 18 17:36:50 tarsonis NetworkManager[2382]: <info> gateway 10.135.1.138
Jan 18 17:36:50 tarsonis NetworkManager[2382]: <info> nameserver '10.135.1.138'
Jan 18 17:36:50 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Stage 5 of 5 (IPv4 Configure Commit) scheduled...
Jan 18 17:36:50 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Stage 5 of 5 (IPv4 Commit) started...
Jan 18 17:36:51 tarsonis NetworkManager[2382]: <info> (wlan0): device state change: ip-config -> secondaries (reason 'none') [70 90 0]
Jan 18 17:36:51 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Stage 5 of 5 (IPv4 Commit) complete.
Jan 18 17:36:51 tarsonis NetworkManager[2382]: <info> (wlan0): device state change: secondaries -> activated (reason 'none') [90 100 0]
Jan 18 17:36:51 tarsonis NetworkManager[2382]: <info> NetworkManager state is now CONNECTED_GLOBAL
Jan 18 17:36:51 tarsonis NetworkManager[2382]: <info> Policy set 'KrustyKrab' (wlan0) as default for IPv4 routing and DNS.
Jan 18 17:36:51 tarsonis NetworkManager[2382]: <info> Writing DNS information to /usr/bin/resolvconf
Jan 18 17:36:51 tarsonis NetworkManager[2382]: <info> Activation (wlan0) successful, device activated.
Jan 18 17:36:51 tarsonis NetworkManager[2382]: <warn> Dispatcher failed: (32) Unit dbus-org.freedesktop.nm-dispatcher.service failed to load: No such file or directory.
Jan 18 17:37:01 tarsonis NetworkManager[2382]: <info> (wlan0): IP6 addrconf timed out or failed.
Jan 18 17:37:01 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Stage 4 of 5 (IPv6 Configure Timeout) scheduled...
Jan 18 17:37:01 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Stage 4 of 5 (IPv6 Configure Timeout) started...
Jan 18 17:37:01 tarsonis NetworkManager[2382]: <info> Activation (wlan0) Stage 4 of 5 (IPv6 Configure Timeout) complete.
Jan 18 18:06:50 tarsonis NetworkManager[2382]: <info> (wlan0): DHCPv4 state changed bound -> (null)
Jan 18 18:06:55 tarsonis NetworkManager[2382]: <info> (wlan0): DHCPv4 state changed (null) -> bound
Jan 18 18:06:55 tarsonis NetworkManager[2382]: <info> address 10.135.1.3
Jan 18 18:06:55 tarsonis NetworkManager[2382]: <info> prefix 24 (255.255.255.0)
Jan 18 18:06:55 tarsonis NetworkManager[2382]: <info> gateway 10.135.1.138
Jan 18 18:06:55 tarsonis NetworkManager[2382]: <info> nameserver '10.135.1.138'
Jan 18 18:36:56 tarsonis NetworkManager[2382]: <info> (wlan0): DHCPv4 state changed bound -> (null)
Jan 18 18:37:01 tarsonis NetworkManager[2382]: <info> (wlan0): DHCPv4 state changed (null) -> bound
Jan 18 18:37:01 tarsonis NetworkManager[2382]: <info> address 10.135.1.3
Jan 18 18:37:01 tarsonis NetworkManager[2382]: <info> prefix 24 (255.255.255.0)
Jan 18 18:37:01 tarsonis NetworkManager[2382]: <info> gateway 10.135.1.138
Jan 18 18:37:01 tarsonis NetworkManager[2382]: <info> nameserver '10.135.1.138'
Jan 18 18:48:23 tarsonis NetworkManager[2382]: <warn> Connection disconnected (reason -4)
Jan 18 18:48:23 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: completed -> disconnected
Jan 18 18:48:23 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: disconnected -> scanning
Jan 18 18:48:24 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: scanning -> authenticating
Jan 18 18:48:24 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: authenticating -> associating
Jan 18 18:48:24 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: associating -> 4-way handshake
Jan 18 18:48:24 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: 4-way handshake -> completed
Jan 18 19:07:01 tarsonis NetworkManager[2382]: <info> (wlan0): DHCPv4 state changed bound -> (null)
Jan 18 19:07:07 tarsonis NetworkManager[2382]: <info> (wlan0): DHCPv4 state changed (null) -> bound
Jan 18 19:07:07 tarsonis NetworkManager[2382]: <info> address 10.135.1.3
Jan 18 19:07:07 tarsonis NetworkManager[2382]: <info> prefix 24 (255.255.255.0)
Jan 18 19:07:07 tarsonis NetworkManager[2382]: <info> gateway 10.135.1.138
Jan 18 19:07:07 tarsonis NetworkManager[2382]: <info> nameserver '10.135.1.138'
Jan 18 19:13:27 tarsonis NetworkManager[2382]: <warn> Connection disconnected (reason -4)
Jan 18 19:13:27 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: completed -> disconnected
Jan 18 19:13:27 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: disconnected -> scanning
Jan 18 19:13:28 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: scanning -> authenticating
Jan 18 19:13:28 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: authenticating -> associating
Jan 18 19:13:28 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: associating -> 4-way handshake
Jan 18 19:13:28 tarsonis NetworkManager[2382]: <info> (wlan0): supplicant interface state: 4-way handshake -> completed
Jan 18 19:37:07 tarsonis NetworkManager[2382]: <info> (wlan0): DHCPv4 state changed bound -> (null)
Jan 18 19:37:13 tarsonis NetworkManager[2382]: <info> (wlan0): DHCPv4 state changed (null) -> bound
Jan 18 19:37:13 tarsonis NetworkManager[2382]: <info> address 10.135.1.3
Jan 18 19:37:13 tarsonis NetworkManager[2382]: <info> prefix 24 (255.255.255.0)
Jan 18 19:37:13 tarsonis NetworkManager[2382]: <info> gateway 10.135.1.138
Jan 18 19:37:13 tarsonis NetworkManager[2382]: <info> nameserver '10.135.1.138'
真正奇怪的是,它实际上显示“网关 10.135.1.138”,尽管除非我重新连接,否则它不会出现在路由表中。
答案1
你不会碰巧有网控激活了吗?
sudo systemctl status netctl
这维基百科 明确指出:
有很多解决方案可供选择,但请记住,它们都是互斥的;您不应该同时运行两个守护进程。
它提到的解决方案是Connman、Netctl、网络管理器、Wicd。例如,我也只使用 NetworkManager。
答案2
我遇到了完全相同的问题,我的环境与您的非常相似。我也在 Arch Linux 上使用网络管理器和无线网卡。
您是否尝试过使用 dhclient 而不是 dhcpcd? https://wiki.archlinux.org/index.php/NetworkManager#dhcpcd_repetitively_refusing_leases
编辑:为了更明确并在帖子中包含链接材料:丢失默认网关的问题可能是由 dhcpcd 拒绝租约引起的。因此,根据上述链接,为我解决问题的方法是让网络管理器使用 dhclient。为此,请在 /etc/NetworkManager/NetworkManager.conf 中的主要部分下添加 dhcp=dhclient,然后重新启动 NetworkManager 服务。
还要确保首先安装了 dhclient 包。HTH