nixbld: add backup internet connection

This commit is contained in:
Sébastien Bourdeauducq 2024-05-06 10:32:10 +08:00
parent 60aacb6a1b
commit 5729c4998a
1 changed files with 32 additions and 2 deletions

View File

@ -6,6 +6,7 @@
let let
netifWan = "enp4s0"; netifWan = "enp4s0";
netifWanBackup = "enp11s0";
netifLan = "enp5s0f1"; netifLan = "enp5s0f1";
netifWifi = "wlp6s0"; netifWifi = "wlp6s0";
netifSit = "henet0"; netifSit = "henet0";
@ -94,7 +95,22 @@ in
allowedUDPPorts = [ 53 67 500 4500 ]; allowedUDPPorts = [ 53 67 500 4500 ];
trustedInterfaces = [ netifLan ]; 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}" = { interfaces."${netifLan}" = {
ipv4.addresses = [{ ipv4.addresses = [{
address = "192.168.1.1"; address = "192.168.1.1";
@ -112,6 +128,11 @@ in
prefixLength = 24; prefixLength = 24;
options.table = "1"; options.table = "1";
} }
{
address = "192.168.1.0";
prefixLength = 24;
options.table = "2";
}
]; ];
}; };
interfaces."${netifWifi}" = { 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" ]; wantedBy = [ "network.target" ];
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";