Gateway Backup Links
When the box goes down, the gateway switches by itself to a backup link : a free ethernet port, a phone’s connection sharing over wifi… The zone stays on Internet in degraded mode, then goes back to the box as soon as it responds.
Principle
Section titled “Principle”Every Internet link (the WAN, then the backups) carries its own default route. The lowest metric wins.
| Link | Metric |
|---|---|
| WAN (the box) | 100 |
| Backup link | 200 + 10 × priority (300 by default) |
| Return link, in probation | metric + 10000 |
| Link without Internet | metric + 20000 |
Three situations are covered :
| Situation | Detection | Effect |
|---|---|---|
| Unplugged cable, box powered off, no DHCP lease anymore | the WAN route disappears | the kernel takes the next route |
| Box powered on but Internet cut off | the dnf-uplink-monitor probe fails 3 times (about 40 seconds) | the WAN goes to 20100, the backup takes over |
| Internet back on the box | 6 successful probes | switch back to the WAN |
| Unplugged or changed cable, box restarted, 3 rounds without a route | loss of carrier or of route | the link returns to probation (10100), then finds its place back after 6 successful probes |
The probe sends a ping through each link (1.1.1.1 and 9.9.9.9, every 10 seconds). It does not depend on DNS : it targets IP addresses.
The two link types do not wait the same way :
| Type | While waiting | Wake-up |
|---|---|---|
ethernet | connected, without traffic (the metric keeps everything on the box) | immediate |
wifi | radio off (rfkill) : no connection to the sharing | as soon as no preferred link reaches the Internet |
Declare a backup link
Section titled “Declare a backup link”-
Identify the interface on the gateway :
Fenêtre de terminal ip -br linkIt must be free : neither the WAN, nor a LAN port, nor a wifi access point’s radio.
-
Declare the link in the host’s file :
usr/machines/gw/configuration.nix darkone.host.gateway.backupLinks = {phone = {type = "wifi";interface = "wlp4s0";};voisin = {type = "ethernet";interface = "enp3s0";priority = 20;};};Option Role typeethernet(DHCP client) orwifi(WPA2/WPA3 client)interfaceinterface that carries the link priority1 to 99, the lowest is preferred among the backups -
For a wifi link, enter the SSID and the passphrase in sops with
just sops:usr/secrets/secrets.yaml backup-link:phone:ssid: "Partage du téléphone"psk: "passphrase-du-partage"The SSID and the passphrase never go through the Nix store.
-
Deploy :
Fenêtre de terminal just apply gw
Verify
Section titled “Verify”networkctl list # the link is “routable” when it is activeip -4 route show default # the first line is the link in userfkill # backup wifi radio “blocked” in standbyjournalctl -u dnf-uplink-monitor -f # radio switches and wake-ups, liveWith the box down and the phone sharing its connection :
default via 192.168.1.254 dev enp1s0 proto dhcp src 192.168.1.10 metric 20100default via 192.168.43.1 dev wlp4s0 proto dhcp src 192.168.43.20 metric 300Tune the probe
Section titled “Tune the probe”| Option | Default | Role |
|---|---|---|
darkone.host.gateway.linkCheck.targets | 1.1.1.1, 9.9.9.9 | pinged addresses, a single reply is enough |
darkone.host.gateway.linkCheck.interval | 10 | seconds between two rounds |
darkone.host.gateway.linkCheck.failAfter | 3 | failures before penalizing a link |
darkone.host.gateway.linkCheck.recoverAfter | 6 | successes before restoring it |
Monitoring
Section titled “Monitoring”The probe publishes three metrics for Prometheus :
| Metric | Value |
|---|---|
dnf_gateway_link_up | 1 if the link has a route and reaches the Internet |
dnf_gateway_link_active | 1 on the link carrying the default route |
dnf_gateway_link_standby | 1 on a backup wifi radio turned off and waiting |
The GatewayOnBackupLink alert (warning) triggers after 2 minutes on a backup
link.
Limits to know about
Section titled “Limits to know about”| Limit | Detail |
|---|---|
| Streams cut on switchover | in-progress connections restart over the new link (call or download to relaunch) |
| Subnet in conflict | a link that hands out addresses from the zone network (e.g. 10.0.0.0/16) breaks routing; a phone’s connection sharing uses a small, distinct network (/24), so no conflict in practice |
| SSID and passphrase | without double quotes (") |
| Remote LUKS unlock | over the WAN or the LAN only |
| Removed links | a running penalty stays until reboot : delete /run/systemd/network/*.network.d/90-dnf-penalty.conf, then networkctl reload |