Install NixOS on Hetzner Online: Difference between revisions

imported>IgorM
m Fixed syntax highlighting
Klinger (talk | contribs)
 
(5 intermediate revisions by 2 users not shown)
Line 12: Line 12:
== Network configuration ==
== Network configuration ==


From Hetzner's [https://accounts.hetzner.com/login web interface], one can obtain both ipv4/ipv6 addresses and gateways.
Hetzner Online offers both IPv4 (usually in a shared /26 or /27 subnet) and IPv6 (/64 subnet) connectivity to each machine. The assigned addresses can be looked up on the [https://robot.hetzner.com/server Hetzner Robot] on the IPs tab of a machine. The public IPv4 address of the server can automatically be obtained via DHCP. For IPv6 you have to statically configure both address and gateway.
Hetzner does announce ipv6 addresses servers, so you need to assign those statically.
In this example, we use networkd to configure the interface. The same configuration can be used for both
the kexec installation image and the final server configuration.


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
{ ... }: {
{
  # This make sure that our interface is named `eth0`.
  # This should be ok as long as you don't have multiple physical network cards
  # For multiple cards one could add a netdev unit to rename the interface based on the mac address
  networking.usePredictableInterfaceNames = false;
   systemd.network = {
   systemd.network = {
     enable = true;
     enable = true;
     networks."eth0".extraConfig = ''
     networks.default = {
       [Match]
       name = "enp1s0"; # The name of the interface
       Name = eth0
       DHCP = "ipv4";
       [Network]
       addresses = [  
      # Add your own assigned ipv6 subnet here here!
        {
      Address = 2a01:4f9:ffff::1/64
          # Replace the address with the one assigned to your machine
       Gateway = fe80::1
          Address = "2a01:4f8:AAAA:BBBB::1/64";
       # optionally you can do the same for ipv4 and disable DHCP (networking.dhcpcd.enable = false;)
        }
      # Address =  144.x.x.x/26
       ];
      # Gateway = 144.x.x.1
      gateway = [ "fe80::1" ];
     '';
       linkConfig.RequiredForOnline = "routable";
     };
   };
   };
}
}
</syntaxHighlight>
</syntaxhighlight>


Another possibility is to use <code>networking.interfaces</code>:
=== Static IPv4 configuration ===
<syntaxHighlight lang=nix>
Since the IPv4 network configuration is known, it can also be configured statically, preventing reliance on the DHCP service. The gateway and subnet information is visible when hovering the IPv4 address. The subnet size is usually a /26 (<code>255.255.255.224</code>) or a /27 (<code>255.255.255.192</code>).<syntaxhighlight lang="nix">
let
{
   external-mac = "00:11:22:33:44:55";
   systemd.network = {
  ext-if = "et0";
    enable = true;
  external-ip = "144.x.x.x";
    networks."30-wan" = {
  external-gw = "144.x.x.255";
      name = "enp1s0"; # The predictable name of the network interface
  external-ip6 = "2a01:XXXX:XXXX::1";
      DHCP = "no";
  external-gw6 = "fe80::1";
      addresses = [
  external-netmask = 27;
        # Replace the addresses with the ones assigned to your machine
  external-netmask6 = 64;
        {
in {
          Address = "A.B.C.D/26";
  # rename the external interface based on the MAC of the interface
        }
  services.udev.extraRules = ''SUBSYSTEM=="net", ATTR{address}=="${external-mac}", NAME="${ext-if}"'';
        {
  networking = {
          Address = "2a01:4f8:AAAA:BBBB::1/64";
    interfaces."${ext-if}" = {
        }
      ipv4.addresses = [{
      ];
        address = external-ip;
      gateway = [
        prefixLength = external-netmask;
        # Replace the gateway address with the one in your subnet
       }];
        "A.B.C.E"
       ipv6.addresses = [{
        "fe80::1"
        address = external-ip6;
       ];
        prefixLength = external-netmask6;
       linkConfig.RequiredForOnline = "routable";
      }];
     };
     };
    defaultGateway6 = {
      address = external-gw6;
      interface = ext-if;
    };
    defaultGateway = external-gw;
   };
   };
}
}
</syntaxHighlight>
</syntaxhighlight>


== Bootstrap from the Rescue System ==
== Bootstrap from the Rescue System ==
Line 171: Line 159:
[[Category:Cookbook]]
[[Category:Cookbook]]
[[Category:Server]]
[[Category:Server]]
[[Category:Deployment]]