Install NixOS on Hetzner Cloud: Difference between revisions

imported>Raboof
add traditional ISO variant, dream about disko/declarative
imported>Mweinelt
Network configuration: Recommend a networkd based configuration
Line 39: Line 39:


== Network configuration ==
== Network configuration ==
Hetzner Cloud offers both IPv4 (/32 subnet) and IPv6 (/64 subnet) connectivity to each machine. The assigned addresses can be looked up on the [https://console.hetzner.cloud Hetzner Cloud Console] from the "Networking" tab on the instance details. The public IPv4 address of the server can automatically obtained be via DHCP. For IPv6 you have to statically configure both address and gateway.


The public IPv4 address of the server will be automatically obtained by NixOS via DHCP, no extra configuration needed. For IPv6 you have to assign the network address and gateway manually like this:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
  systemd.network.enable = true;
  systemd.network.networks."10-wan" = {
    matchConfig.Name = "ens3"; # either ens3 (amd64) or enp1s0 (arm64)
    networkConfig.DHCP = "ipv4";
    address = [
      # replace this address with the one assigned to your instance
      "2a01:4f8:aaaa:bbbb::1/64"
    ];
    routes = [
      { routeConfig.Gateway = "fe80::1"; }
    ];
  };
</nowiki>}}


<syntaxHighlight lang=nix>
=== Static IPv4 configuration ===
networking = {
The IPv4 address can also be configured statically. The trick here is, that the gateway needs to be configured with the <code>onlink</code> flag, because it is not in the same subnet as your public IP address, but still very much on that same link.
  interfaces.ens3.ipv6.addresses = [{
    address = "2a01:4f8:....:....::";
    prefixLength = 64;
  }];
  defaultGateway6 = {
    address = "fe80::1";
    interface = "ens3";
  };
};
</syntaxHighlight>


Replace the <code>address</code> part with the correct IPv6 address of your instance. You can find it on the [https://console.hetzner.cloud Hetzner Cloud Console] by selecting the respective server and navigation to the "Networking" section in the left menu.
<syntaxhighlight lang="nix">
  systemd.network.networks."10-wan" = {
    networkConfig.DHCP = "no";
    address = [
      # replace this address with the one assigned to your instance
      "A.B.C.D/32"
    ];
    routes = [
      { routeConfig = { Destination = "172.31.1.1"; }; }
      { routeConfig = { Gateway = "172.31.1.1"; GatewayOnLink = true; }; }
    ];
  }
</syntaxhighlight>