Categories
SysOps

How to disable Network Manager connectivity checks

Four different ways to disable Network Manager connectivity checks.

Solution #1 – Alter user configuration using system settings

You can disable connectivity checking inside system settings -> privacy -> connectivity.

Solution #2 – Alter user configuration using D-Bus

Inspect bus traffic to identify the altered property.

$ sudo busctl monitor
[...]
‣ Type=signal  Endian=l  Flags=1  Version=1 Cookie=9088
  Sender=:1.11  Path=/org/freedesktop/NetworkManager  Interface=org.freedesktop.DBus.Properties  Member=PropertiesChanged
  UniqueName=:1.11
  MESSAGE "sa{sv}as" {
          STRING "org.freedesktop.NetworkManager";
          ARRAY "{sv}" {
                  DICT_ENTRY "sv" {
                          STRING "ConnectivityCheckEnabled";
                          VARIANT "b" {
                                  BOOLEAN true;
                          };
                  };
          };
          ARRAY "s" {
          };
  };
[...]

Now, you can check the current connectivity check setting.

$ busctl get-property org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager ConnectivityCheckEnabled
b true

Disable connectivity check.

$ busctl set-property org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager ConnectivityCheckEnabled b false

Ensure that it is disabled.

$ busctl get-property org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager ConnectivityCheckEnabled
b false

Solution #3 – Alter package configuration

Default URI is defined inside /usr/lib/NetworkManager/conf.d/20-connectivity-ubuntu.conf file.

$ sudo cat /usr/lib/NetworkManager/conf.d/20-connectivity-ubuntu.conf 
[connectivity]
uri=http://connectivity-check.ubuntu.com./

Override this configuration using file in /etc/NetworkManager/conf.d/ directory.

$ sudo touch /etc/NetworkManager/conf.d/20-connectivity-ubuntu.conf

Reload configuration.

$ sudo nmcli general reload 

Notice, system settings are stored using /var/lib/NetworkManager/NetworkManager-intern.conf and read after above-mentioned configuration, so you cannot disable it directly, but as the uri parameter is empty connection checking is disabled indirectly and cannot be enabled by user.

$ sudo cat  /var/lib/NetworkManager/NetworkManager-intern.conf
# Internal configuration file. This file is written and read
# by NetworkManager and its configuration values are merged
# with the configuration from 'NetworkManager.conf'.
#
# Keys with a ".set." prefix specify the value to set.
# A corresponding key with a ".was." prefix records the value
# of the user configuration at the time of storing the file.
# The value from internal configuration is rejected if the corresponding
# ".was." key no longer matches the configuration from 'NetworkManager.conf'.
# That means, if you modify a value in 'NetworkManager.conf', the internal
# overwrite no longer matches and is ignored.
#
# Certain sections can only be overwritten whole, not on a per key basis.
# Such sections are marked with a ".was" key that records the user configuration
# at the time of writing.
#
# Internal sections of the form [.intern.*] cannot
# be set by user configuration.
#
# CHANGES TO THIS FILE WILL BE OVERWRITTEN

[connectivity]
.set.enabled=true

Why does this work in such a strange way?

$ man NetworkManager.conf
[...]
       If a default NetworkManager.conf is provided by your distribution's packages, you should not modify it, since your changes may get overwritten by package updates. Instead, you can
       add additional .conf files to the /etc/NetworkManager/conf.d directory. These will be read in order, with later files overriding earlier ones. Packages might install further
       configuration snippets to /usr/lib/NetworkManager/conf.d. This directory is parsed first, even before NetworkManager.conf. Scripts can also put per-boot configuration into
       /run/NetworkManager/conf.d. This directory is parsed second, also before NetworkManager.conf. The loading of a file /run/NetworkManager/conf.d/name.conf can be prevented by adding a
       file /etc/NetworkManager/conf.d/name.conf. Likewise, a file /usr/lib/NetworkManager/conf.d/name.conf can be shadowed by putting a file of the same name to either
       /etc/NetworkManager/conf.d or /run/NetworkManager/conf.d.

       NetworkManager can overwrite certain user configuration options via D-Bus or other internal operations. In this case it writes those changes to
       /var/lib/NetworkManager/NetworkManager-intern.conf. This file is not intended to be modified by the user, but it is read last and can shadow user configuration from
       NetworkManager.conf.
[...]

It should be apparent by now how and in which order configuration files are processed.

Solution #4 – Remove package

Remove network-manager-config-connectivity-ubuntu package.

$ sudo apt remove network-manager-config-connectivity-ubuntu

Reload configuration to apply changes immediately.

$ sudo nmcli general reload

This is the most radical solution.

There is more

Display URI (it is not writable).

$ busctl get-property org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager ConnectivityCheckUri 
s "http://connectivity-check.ubuntu.com./"

You can perform a connectivity check using the command-line.

$ nmcli networking connectivity check
full

It will create HTTP connection to the defined URI

> GET / HTTP/1.1
> Host: connectivity-check.ubuntu.com
> Accept: */*
> Connection: close
< HTTP/1.1 204 No Content
< Date: Fri, 26 Mar 2021 17:28:26 GMT
< Server: Apache/2.4.18 (Ubuntu)
< X-NetworkManager-Status: online
< Connection: close

... and look for the specific header.

#define HEADER_STATUS_ONLINE "X-NetworkManager-Status: online\r\n"

It will return full when the header is found, limited when there is a connection problem, portal when the header is not found which indicates a captive portal and none when there is no link.