Network configuration with networkd
Flatcar Container Linux machines are preconfigured with networking customized for each platform. You can write your own networkd units to replace or override the units created for each platform. This article covers a subset of networkd functionality. You can view the full docs here .
Drop a networkd unit in /etc/systemd/network/ or inject a unit on boot via a Butane Config. Files placed manually on the filesystem will need to reload networkd afterwards with sudo systemctl restart systemd-networkd. Network units injected via a Butane Config will be written to the system before networkd is started, so there are no work-arounds needed.
Let’s take a look at two common situations: using a static IP and turning off DHCP.
Static networking
To configure a static IP on enp2s0, create static.network:
|
|
Place the file in /etc/systemd/network/. To apply the configuration, run:
|
|
Butane Config
Setting up static networking in your Butane Config can be done by writing out the network unit. Be sure to modify the [Match] section with the name of your desired interface, and replace the IPs:
|
|
Turn off DHCP on specific interface
If you’d like to use DHCP on all interfaces except enp2s0, create two files. They’ll be checked in lexical order, as described in the
full network docs
. Any interfaces matching during earlier files will be ignored during later files.
10-static.network:
|
|
Put your settings-of-last-resort in 20-dhcp.network. For example, any interfaces matching en* that weren’t matched in 10-static.network will be configured with DHCP:
20-dhcp.network:
|
|
To apply the configuration, run sudo systemctl restart systemd-networkd. Check the status with systemctl status systemd-networkd and read the full log with journalctl -u systemd-networkd.
Turn off IPv6 on specific interfaces
While IPv6 can be disabled globally at boot by appending ipv6.disable=1 to the kernel command line, networkd supports disabling IPv6 on a per-interface basis. When a network unit’s [Network] section has either LinkLocalAddressing=ipv4 or LinkLocalAddressing=no, networkd will not try to configure IPv6 on the matching interfaces.
Note however that even when using the above option, networkd will still be expecting to receive router advertisements if IPv6 is not disabled globally. If IPv6 traffic is not being received by the interface (e.g. due to sysctl or ip6tables settings), it will remain in the configuring state and potentially cause timeouts for services waiting for the network to be fully configured. To avoid this, the IPv6AcceptRA=no option should also be set in the [Network] section.
A network unit file’s [Network] section should therefore contain the following to disable IPv6 on its matching interfaces.
|
|
Configure static routes
Specify static routes in a systemd network unit’s [Route] section. In this example, we create a unit file, 10-static.network, and define in it a static route to the 172.16.0.0/24 subnet:
10-static.network:
|
|
To specify the same route in a Butane Config, create the systemd network unit there instead:
|
|
Configure multiple IP addresses
To configure multiple IP addresses on one interface, we define multiple Address keys in the network unit. In the example below, we’ve also defined a different gateway for each IP address.
20-multi_ip.network:
|
|
To do the same thing through a Butane Config:
|
|
To verify whether your configuration was successful and view all IP addresses associated with a specific interface, you can use the following syntax: ip [-4|-6] addr show dev <interface_name>. Here is an example of the command and its output:
|
|
By executing the command ip -4 addr show dev <interface_name>, you can obtain detailed information about the eth0 interface. The output includes the interface’s state, such as whether it is UP or DOWN, its assigned IP addresses, the corresponding subnet masks, and other relevant details.
Debugging networkd
If you’ve faced some problems with networkd you can enable debug mode following the instructions below.
Enable debugging manually
|
|
Create a
Drop-In
/etc/systemd/system/systemd-networkd.service.d/10-debug.conf with following content:
|
|
And restart systemd-networkd service:
|
|
Enable debugging through a Butane Config
Define a Drop-In in a Butane Linux Config :
|
|