How To Set A Custom Internet Connection Check Domain On Linux

If like me you've got something on your network monitoring DNS requests, such as Pi Hole or AdGuard Home, and you have a computer or two or three running Linux, you've probably seen many requests like the above. Odds are they hit your top domains, especially if you have multiple machines running the same distro.

I fiddle with a few different distros but I tend to stick to Ubuntu for my main one. I have three machines on my network running Ubuntu. As you can see, they frequently connect to the domain connectivity-check.ubuntu.com.

Every single OS on every single device – whether it's a computer, smartphone, or IoT device – pretty much does the same thing. For example Windows uses the rather more cryptic domain msftncsi.com, standard Android pings connectivitycheck.gstatic.com, and even my phone running Graphene OS – a fork of Android focused heavily on security and privacy – checks in now and then with connectivitycheck.grapheneos.network.

The purpose of these domains is quite self-explanatory: it's simply a way for the device to check if it's connected to the internet. If not, it'll show an error letting you know there's a connection problem, or if it detects a captive portal (e.g. a login page for hotel WiFi) it'll redirect you to that.

Behind the scenes, the way it works within Linux is very simple. Using Ubuntu as an example, NetworkManager pings http://connectivity-check.ubuntu.com/check_network_status.txt and if the requested text file reads NetworkManager is online it does nothing. If for any reason it's unable to retrieve this file, it will throw up a connection error.

This works the same way across virtually every single distro. If your distro uses NetworkManager, it will ping the distro's server looking for that file. For instance, Arch will use ping.archlinux.org and Zorin will use connectivity.zorin-os.com while, if your distro has left the NetworkManager package unaltered, it will default to nmcheck.gnome.org.

The virtually universal presence of NetworkManager across distros and the simple method it uses also make it very easy to direct these connectivity checks on your machine to your own domain if you wish. This way, instead of constantly pinging the distro's server or Gnome's server, it can ping a server you control. Another benefit is you can direct your machine to a URL that connects via HTTPS, as opposed to the default domains from virtually every distro which instead use plaintext HTTP.

So first of all, login to a server you control and either setup a new subdomain or simply use an existing one and create a text file in the public web directory entitled check_network_status.txt and within that file simply put NetworkManager is online and save it.

For example:

sudo nano /var/www/html/check_network_status.txt

In the empty text file you enter the magic words:

NetworkManager is online

Hit ctrl + O, enter, then ctrl + X.

Now open up the URL in your browser and verify the text file shows. If it does, we now just need to tell NetworkManager to use it.

Fire up the terminal on your local machine and run:

sudo nano /etc/NetworkManager/conf.d/20-connectivity.conf

You'll likely have just created a new blank file, depending on your distro. If so, enter all of the below:

[connectivity]
uri=https://[your domain here]/check_network_status.txt
interval=300

The interval is measured in seconds and 300 is the default. Feel free to adjust this to your liking if you wish. An interval of 0 will disable connectivity checks.

If you already have something that looks like the above in place, you just need to change the URL.

Mine looks like the following:

[connectivity]
uri=https://networkcheck.xanny.family/check_network_status.txt
interval=420

Now save the file and simply reload NetworkManager:

sudo systemctl restart NetworkManager

When this is done, verify everything is working by running:

nmcli networking connectivity

If it comes back with full all is good.

Now go look at whatever software you're using to monitor your DNS requests and you should see your own URL showing up:

Easy peasy. You can now add your URL to any Linux distro using NetworkManager in the same way. Just make sure your server has good uptime and if you later decide to shut the server down, switch back to a default URL or point it to a new server you control, otherwise you'll get connection failure alerts.

That's all folks!

#Linux #tutorial #guide #Ubuntu #Debian #Arch #ZorinOS #NetworkManager #connectivitycheck #server #customisation #configuration