Systemd/networkd: Difference between revisions

imported>Mweinelt
Mention some limitations
imported>Mweinelt
→‎Examples: Static network configuration
Line 97: Line 97:
     # make acquiring a DHCP lease a dependency for network-online.target
     # make acquiring a DHCP lease a dependency for network-online.target
     linkConfig.RequiredForOnline = true;
     linkConfig.RequiredForOnline = true;
  };
</syntaxhighlight>
=== Static ===
Apply a static address and routing configuration onto <code>enp1s0</code>. When the gateway is not on the same prefix as the address configured, you usually also need to set <code>GatewayOnLink</code>, to indicate the gateway is directly reachable on the interface.
<syntaxhighlight lang="nix">
  systemd.network.networks."10-wan" = {
    # match the interface by name
    matchConfig.Name = "enp1s0";
    address = [
        # configure addresses including subnet mask
        "192.0.2.100/24"
        "2001:DB8::2/64"
    ];
    routes = [
      # create default routes for both IPv6 and IPv4
      { routeConfig.Gateway = "fe80::1"; }
      { routeConfig.Gateway = "192.0.2.1"; }
      # or when the gateway is not on the same network
      { routeConfig = {
        Gateway = "172.31.1.1";
        GatewayOnLink = true;
      }
    ];
    # make the routes on this interface a dependency for network-online.target
    linkConfig.RequiredForOnline = "routable";
   };
   };
</syntaxhighlight>
</syntaxhighlight>