更换NetworkManager的检测URI

容小狸 Lv3

每次需要连接到含有Captive Portal(强制认证)的网络时,我的Arch Linux会弹出需要登录的提示。但是点击之后,跳转到Firefox(我的默认浏览器),就会提示不可信,然后又打开一个新页面,跳转到Firefox的detect portal。这种跳转方式非常不优雅,那么有什么办法能够统一Captive Portal Detection的URI呢?

NetworkManager

方法是有的。见这篇文章

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.

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.
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 specified 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.

由此可知,我们需要设置uri为Firefox的检测URI,并将返回值设置为Firefox的默认返回值就可以了。那么具体的操作如下,以Arch Linux为例:

具体步骤

修改配置文件

修改/usr/lib/NetworkManager/conf.d/20-connectivity.conf为:

1
2
3
[connectivity]
uri=http://detectportal.firefox.com/
response=success

其实更推荐的做法是:在/etc/NetworkManager/conf.d下新建文件20-connectivity.conf,并写入上方的配置,以免在重新安装NetworkManager之类的软件时被覆盖。

应用更改

执行以下指令:

1
sudo nmcli general reload

或者:

1
sudo systemctl restart NetworkManager

令NetworkManager重启即可。非常简单!

  • 标题: 更换NetworkManager的检测URI
  • 作者: 容小狸
  • 创建于 : 2026-07-26 01:51:00
  • 更新于 : 2026-07-25 05:24:38
  • 链接: https://blog.rongxiaoli.top/2026/07/25/NetworkManager-detect-change/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论