From 5729c4998a92174e6f76a9907c0ea87c2af84416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bourdeauducq?= Date: Mon, 6 May 2024 10:32:10 +0800 Subject: [PATCH] nixbld: add backup internet connection --- nixbld-etc-nixos/configuration.nix | 34 ++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/nixbld-etc-nixos/configuration.nix b/nixbld-etc-nixos/configuration.nix index 8c230852..70339ace 100644 --- a/nixbld-etc-nixos/configuration.nix +++ b/nixbld-etc-nixos/configuration.nix @@ -6,6 +6,7 @@ let netifWan = "enp4s0"; + netifWanBackup = "enp11s0"; netifLan = "enp5s0f1"; netifWifi = "wlp6s0"; netifSit = "henet0"; @@ -94,7 +95,22 @@ in allowedUDPPorts = [ 53 67 500 4500 ]; trustedInterfaces = [ netifLan ]; }; - interfaces."${netifWan}".useDHCP = true; + useDHCP = false; + interfaces."${netifWan}".useDHCP = true; # PCCW - always wants active DHCP lease or cuts you off + interfaces."${netifWanBackup}" = { # HKBN - no DHCP with static IP service + ipv4.addresses = [{ + address = "202.77.7.238"; + prefixLength = 30; + }]; + ipv4.routes = [ + { + address = "0.0.0.0"; + prefixLength = 0; + via = "202.77.7.237"; + options.table = "2"; + } + ]; + }; interfaces."${netifLan}" = { ipv4.addresses = [{ address = "192.168.1.1"; @@ -112,6 +128,11 @@ in prefixLength = 24; options.table = "1"; } + { + address = "192.168.1.0"; + prefixLength = 24; + options.table = "2"; + } ]; }; interfaces."${netifWifi}" = { @@ -243,7 +264,16 @@ in }; }; - systemd.services.custom-network-setup = { + systemd.services.network-custom-route-backup = { + wantedBy = [ "network.target" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStart = "${pkgs.iproute2}/bin/ip rule add from 202.77.7.238/30 table 2"; + ExecStop = "${pkgs.iproute2}/bin/ip rule del table 2"; + }; + }; + systemd.services.network-custom-route-alt = { wantedBy = [ "network.target" ]; serviceConfig = { Type = "oneshot";