Gnome WIFI 连接状态显示「问号」的问题

被 Gnome WIFI 连接状态显示「问号」的问题困扰了很久,在得到 Emacs China 论坛里的道友提示下终于得以解决。

问题在于 Gnome 下 NetworkManager 在连接到 WIFI 后会通过访问默认配置的一个 HTTP 连接来检测网络连接状态。之所以我出现这个问题,大概是因为默认的网络检测连接1在我的网络里被阻塞了。检查方法如下:

[xueshumeng@fedora math]$ NetworkManager --print-config
# NetworkManager configuration: /etc/NetworkManager/NetworkManager.conf (lib: 20-connectivity-fedora.conf) (run: 15-carrier-timeout.conf)

[main]
# plugins=
# rc-manager=auto
# auth-polkit=true
# dhcp=internal
# iwd-config-path=
configure-and-quit=no

[connectivity]
enabled=true
uri=http://fedoraproject.org/static/hotspot.txt
response=OK
interval=300

[logging]
# backend=journal
# audit=false

[device]
# wifi.backend=wpa_supplicant

# no-auto-default file "/var/lib/NetworkManager/no-auto-default.state"
[xueshumeng@fedora math]$
[xueshumeng@fedora math]$ curl http://fedoraproject.org/static/hotspot.txt
curl: (56) Recv failure: Connection reset by peer

像上面那样,通过 curl 程序访问 connectivity 章节下的 uri 字段是访问不到的。这样的状态下桌面的网络连接状态图标将会显示为「问号」。

2023-02-20_19-39-40_screenshot.png

CONNECTIVITY SECTION
       This section controls NetworkManager's optional connectivity checking functionality. This allows NetworkManager to detect whether or not the system can actually access the internet or whether it is
       behind a captive portal.

       Connectivity checking serves two purposes. For one, it exposes a connectivity state on D-Bus, which other applications may use. For example, Gnome's portal helper uses this as signal to show a
       captive portal login page. The other use is that default-route of devices without global connectivity get a penalty of +20000 to the route-metric. This has the purpose to give a better default-route
       to devices that have global connectivity. For example, when being connected to WWAN and to a Wi-Fi network which is behind a captive portal, WWAN still gets preferred until login.

       Note that your distribution might set /proc/sys/net/ipv4/conf/*/rp_filter to strict filtering. That works badly with per-device connectivity checking, which uses SO_BINDDEVICE to send requests on
       all devices. A strict rp_filter setting will reject any response and the connectivity check on all but the best route will fail.

       enabled
           Whether connectivity check is enabled. Note that to enable connectivity check, a valid uri must also be configured. The value defaults to true, but since the uri is unset by default,
           connectivity check may be disabled. The main purpose of this option is to have a single flag to disable connectivity check. Note that this setting can also be set via D-Bus API at runtime. In
           that case, the value gets stored in /var/lib/NetworkManager/NetworkManager-intern.conf file.

       uri
           The URI of a web page to periodically request when connectivity is being checked. This page should return the header "X-NetworkManager-Status" with a value of "online". Alternatively, its body
           content should be set to "NetworkManager is online". The body content check can be controlled by the response option. If this option is blank or missing, connectivity checking is disabled.

       interval
           Specified in seconds; controls how often connectivity is checked when a network connection exists. If set to 0 connectivity checking is disabled. If missing, the default is 300 seconds.

       response
           If set, controls what body content NetworkManager checks for when requesting the URI for connectivity checking. Note that this only compares that the HTTP response starts with the specifid text,
           it does not compare the exact string. This behavior might change in the future, so avoid relying on it. If missing, the response defaults to "NetworkManager is online". If set to empty, the HTTP
           server is expected to answer with status code 204 or send no data.

根据上面两则信息,在 /etc/NetworkManager/conf.d 中新增 connectivity.conf 配置文件。文件内容如下:

[connectivity]
enabled=true
uri=http://nmcheck.gnome.org/check_network_status.txt
response=NetworkManager is online
interval=3000

至此,网络连接状态显示问号的问题得以解决。但导致这个问题的根本原因在于我所在网络连接不到 Fedora 的一些 WEB 服务器,系统中其他需要连接到 Fedora 服务器的功能也还依然是访问不到,例如 DNF 安装、升级等操作时出现的网络连接失败问题:

[root@MiWiFi-RB03-srv conf.d]# dnf install gnome-screenshot
Fedora 37 - x86_64 - Updates                                                                                                                                                       0.0  B/s |   0  B     00:06
Errors during downloading metadata for repository 'updates':
  - Curl error (35): SSL connect error for https://mirrors.fedoraproject.org/metalink?repo=updates-released-f37&arch=x86_64 [OpenSSL SSL_connect: Connection reset by peer in connection to mirrors.fedoraproject.org:443 ]
Error: Failed to download metadata for repo 'updates': Cannot prepare internal mirrorlist: Curl error (35): SSL connect error for https://mirrors.fedoraproject.org/metalink?repo=updates-released-f37&arch=x86_64 [OpenSSL SSL_connect: Connection reset by peer in connection to mirrors.fedoraproject.org:443 ]

这个问题可以通过修改镜像源为国内镜像来解决,例如科大的 Fedora 镜像清华的 Fedora 镜像等。具体修改方法参考镜像站点给出的使用帮助。

Footnotes:

Date: 2023-02-20 Mon 19:24

Author: xueshumeng

Email: xue.shumeng@yahoo.com

Created: 2024-03-16 Sat 20:52