From 5fab811812b4d4524def2fc17b60820bafe32329 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Thu, 19 Jan 2023 20:12:14 +0800 Subject: [PATCH] hosts/plover: update networking setup --- .../modules/hardware/hetzner-cloud-cx21.nix | 50 +++++++++++++++++-- hosts/plover/modules/hardware/networks.nix | 9 +++- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/hosts/plover/modules/hardware/hetzner-cloud-cx21.nix b/hosts/plover/modules/hardware/hetzner-cloud-cx21.nix index 90f63bf2..46a07a9d 100644 --- a/hosts/plover/modules/hardware/hetzner-cloud-cx21.nix +++ b/hosts/plover/modules/hardware/hetzner-cloud-cx21.nix @@ -5,9 +5,11 @@ # from nixos-generators. let network = import ./networks.nix; - inherit (network) publicIP publicIPv6 privateNetworkGatewayIP; -in + inherit (network) publicIP' publicIPv6 publicIPv6PrefixLength privateNetworkGatewayIP; + # This is just referring to the same interface just with alternative names. + mainEthernetInterfaceNames = [ "ens3" "enp0s3" ]; +in { imports = [ (modulesPath + "/profiles/qemu-guest.nix") @@ -50,9 +52,47 @@ in # https://discourse.nixos.org/t/nixos-on-hetzner-cloud-servers-ipv6/221/ systemd.network = { enable = true; - networks."20-wan" = { - matchConfig.Name = "en*"; - networkConfig.DHCP = "yes"; + + # For more information, you can look at Hetzner documentation from + # https://docs.hetzner.com/robot/dedicated-server/ip/additional-ip-adresses/ + networks = { + "60-wan" = { + matchConfig.Name = lib.concatStringsSep " " mainEthernetInterfaceNames; + + # Setting the primary static IPs. + address = [ + publicIP' + + # The public IPv6 is assigned to a server so we'll to have to go with + # something else. + "${publicIPv6}1/${publicIPv6PrefixLength}" + ]; + + networkConfig = { + DHCP = "yes"; + IPForward = true; + IPMasquerade = "both"; + }; + + routes = [ + { routeConfig.Gateway = "fe80::1"; } + { routeConfig.Destination = publicIP'; } + + { + routeConfig = { + Gateway = publicIP'; + GatewayOnLink = true; + }; + } + ]; + }; + + # This is to make use of the remaining ethernet interfaces as we can + # build a local network. + "60-dhcpv6-pd-downstreams" = { + matchConfig.Name = "en*"; + networkConfig.DHCP = "yes"; + }; }; }; diff --git a/hosts/plover/modules/hardware/networks.nix b/hosts/plover/modules/hardware/networks.nix index 3d9f4fd5..cff587ac 100644 --- a/hosts/plover/modules/hardware/networks.nix +++ b/hosts/plover/modules/hardware/networks.nix @@ -1,9 +1,14 @@ # It just contains a set of network-related variables mainly used for # network-related services. Make sure to change this every time you migrate to # a new server. -{ - publicIP = "95.217.212.19/32"; +rec { + publicIP = "95.217.212.19"; + publicIPPrefixLength = 32; + publicIP' = "${publicIP}/${publicIPPrefixLength}"; + publicIPv6 = "2a01:4f9:c011:a448::"; + publicIPv6PrefixLength = 64; + publicIPv6' = "${publicIPv6}/${publicIPv6PrefixLength}"; privateIPNetworkRange = "172.16.0.0/32"; privateNetworkGatewayIP = "172.16.0.1/32";