3

I would like to create a nspawn container connected to the network via macvlan and dhcp. All documentation I have found were very instructive but did not offer a step by step procedure for this setup.

What I did so far was to create the container (debian base) using debootstrap including systemd-container:

debootstrap --arch=armhf --include=systemd-container stretch /var/lib/machines/raspbian-09 http://archive.raspbian.org/raspbian 

Native host network

running:

systemd-nspawn -b -M raspbian-09 

or

machinectl raspbian-09 

with the unit file /etc/systemd/nspawn/raspbian-09.nspawn containing:

[Exec] Boot=true PrivateUsers=no [Network] Private=no VirtualEthernet=no 

In both cases, the network connection is fine.

Macvlan

For the macvlan, I either run the command:

systemd-nspawn -b -M raspbian-09 --network-macvlan=eth0 

or

machinectl raspbian-09 

with the unit file /etc/systemd/nspawn/raspbian-09.nspawn containing:

[Exec] Boot=true PrivateUsers=no [Network] MACVLAN=eth0 

In both cases, the connection to the network does not work.

Within the container, I can see that an interface mv-eth0 is created:

# networkctl IDX LINK TYPE OPERATIONAL SETUP 1 lo loopback carrier unmanaged 2 mv-eth0 ether degraded configuring 

however, there is no ipv4 address:

# ip a mv-eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet6 xxxx::xxxx:xxxx:xxxx:xxxx/64 scope link valid_lft forever preferred_lft forever 

What other configurations on the host and container should be made?

1 Answer 1

1

One possible solution is the following:

All the following actions are to be done in the container.

Check if your container is using systemd-networkd, you can check if that is the case by running the following command

systemctl status systemd-networkd 

If the service is not enabled and not running, you will need to enable and start it

systemctl enable systemd-networkd systemctl start systemd-networkd 

You may also need to enable and start the systemd-resolved service, if it is not enabled and started.

systemctl enable systemd-resolved systemctl start systemd-resolved 

If you need a dynamic ipv4 address created for you on your macvlan interface, you can then create the network setup file /etc/systemd/network/mveth0.network, with the following contents

[Match] Name=mv-eth0 [Network] DHCP=ipv4 

If you need to set a static ipv4 address for the macvlan interface. For example if you have a gateway address 192.168.1.1, and need to set the ipv4 address to 192.168.1.14/24, you can then use the following content for the network setup file /etc/systemd/network/mveth0.network.

[Match] Name=mv-eth0 [Network] IPForward=yes Address=192.168.1.14/24 Gateway=192.168.1.1 # DNS= ? 

After creating the file you will need to restart the systemd-networkd service

systemctl restart systemd-networkd 

You may need to use sudo in your case to run the commands

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.