Container Runtimes

Docker

rkt

Reference

Network configuration with networkd

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 Container Linux Config. Files placed manually on the filesystem will need to reload networkd afterwards with sudo systemctl restart systemd-networkd. Network units injected via a Container Linux 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:

[Match]Name=enp2s0[Network]Address=192.168.0.15/24Gateway=192.168.0.1

Place the file in /etc/systemd/network/. To apply the configuration, run:

sudo systemctl restart systemd-networkd

Container Linux Config

Setting up static networking in your Container Linux 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:

This is the human-readable config file. This should not be immediately passed to Container Linux. Learn more.

# This config is meant to be consumed by the config transpiler, which will# generate the corresponding Ignition config. Do not pass this config directly# to instances of Container Linux.networkd:units:-name:00-eth0.networkcontents:|[Match]Name=eth0[Network]DNS=1.2.3.4Address=10.0.0.101/24Gateway=10.0.0.1

This is the raw machine configuration, which is not intended for editing. Learn more. Validate the config here.

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

[Match]Name=enp2s0[Network]Address=192.168.0.15/24Gateway=192.168.0.1

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

[Match]Name=en*[Network]DHCP=yes

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.

[Network]LinkLocalAddressing=noIPv6AcceptRA=no

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

[Route]Gateway=192.168.122.1Destination=172.16.0.0/24

To specify the same route in a Container Linux Config, create the systemd network unit there instead:

This is the human-readable config file. This should not be immediately passed to Container Linux. Learn more.

# This config is meant to be consumed by the config transpiler, which will# generate the corresponding Ignition config. Do not pass this config directly# to instances of Container Linux.networkd:units:-name:10-static.networkcontents:|[Route]Gateway=192.168.122.1Destination=172.16.0.0/24

This is the raw machine configuration, which is not intended for editing. Learn more. Validate the config here.

This is the human-readable config file. This should not be immediately passed to Container Linux. Learn more.

# This config is meant to be consumed by the config transpiler, which will# generate the corresponding Ignition config. Do not pass this config directly# to instances of Container Linux.networkd:units:-name:20-multi_ip.networkcontents:|[Match]Name=eth0[Network]DNS=8.8.8.8Address=10.0.0.101/24Gateway=10.0.0.1Address=10.0.1.101/24Gateway=10.0.1.1

This is the raw machine configuration, which is not intended for editing. Learn more. Validate the config here.

Enable debugging through a Container Linux Config

This is the human-readable config file. This should not be immediately passed to Container Linux. Learn more.

# This config is meant to be consumed by the config transpiler, which will# generate the corresponding Ignition config. Do not pass this config directly# to instances of Container Linux.systemd:units:-name:systemd-networkd.servicedropins:-name:10-debug.confcontents:|[Service]Environment=SYSTEMD_LOG_LEVEL=debug

This is the raw machine configuration, which is not intended for editing. Learn more. Validate the config here.