2

I'm fiddling with systemd-nspawn containers on my RaspberryPi. So far booting works fine. I use the --network-veth and --network-bridge=br0 options and bridging did work well with a kvm virtual machine.

Now I want to configure the container IP to a specific address and created a /etc/systemd/network/host.network file which seems to be ignored as the container gets its IP via DHCP.

This is the file.

[Match]
Name=host0

[Network]
DHCP=no
Address=192.168.0.16/24
Gateway=192.168.0.1
DNS=8.8.8.8

systemd-networkd is running:

root@bluehost-debian:~# systemctl status systemd-networkd.service
● systemd-networkd.service - Network Service
   Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled)
   Active: active (running) since Do 2016-09-01 21:10:54 UTC; 12min ago
     Docs: man:systemd-networkd.service(8)
 Main PID: 69 (systemd-network)
   Status: "Processing requests..."
   CGroup: /machine.slice/machine-bluecloud.scope/system.slice/systemd-networkd.service
           └─69 /lib/systemd/systemd-networkd

Sep 01 21:10:54 bluehost-debian systemd-networkd[69]: host0           : link configured
Sep 01 21:10:54 bluehost-debian systemd[1]: Started Network Service.
Sep 01 21:10:55 bluehost-debian systemd-networkd[69]: host0           : gained carrier
Sep 01 21:10:58 bluehost-debian systemd-networkd[69]: host0           : DHCPv4 address 192.168.0.143/24 via 192.168.0.1
Sep 01 21:10:58 bluehost-debian systemd-networkd[69]: host0           : link configured

udev tells me that my value for the Name field should be ok. Why is it ignored?

udevadm info /sys/class/net/host0
P: /devices/virtual/net/host0
E: DEVPATH=/devices/virtual/net/host0
E: IFINDEX=2
E: INTERFACE=host0
E: SUBSYSTEM=net

Otherwise the network works ok. Tried /etc/network/interfaces but this did not work in startup but only with ifup... (allow-hotplug host0 ...)

I'm a little stuck so help is appreciated.

  • 1
    Ok... in the container I updated systemd to latest from jessie-backports which got me networkctl. This showed me the file currently used for network configuration. which was not mine. rename my file to 00-host.network and that did the trick... read something about a bug with network in the container until 217... debian had 215 and in backports is 230. – Christian T Sep 2 '16 at 16:47
1

Now I want to configure the container IP to a specific address and created a /etc/systemd/network/host.network file which seems to be ignored as the container gets its IP via DHCP.

Ok... in the container I updated systemd to latest from jessie-backports which got me networkctl. This showed me the file currently used for network configuration. which was not mine. rename my file to 00-host.network and that did the trick...

Well done.

To be clear, the problem was that host.network sorts last. You needed to provide a file with a name that sorted before the default 80-host0.network in /lib/systemd/network/, or which had the same filename (or mask it by creating a file with the same name, pointing to /dev/null).

read something about a bug with network in the container until 217... debian had 215 and in backports is 230.

Alternative: /etc/network/interfaces

Tried /etc/network/interfaces but this did not work in startup but only with ifup... (allow-hotplug host0 ...)

/etc/network/interfaces worked fine for me (with DHCP). However I worried that allow-hotplug might not work inside the container, so I had used auto host0 instead. This should be safe as host0 is created very early on by nspawn.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.