You are not logged in.

#1 2019-08-07 20:51:40

taumeister
Member
Registered: 2019-01-06
Posts: 31

[solved] systemd-networkd with systemd-nspawn no ip in guest and host

Hi,

Although I read the wiki about systemd-networkd over and over again, I can't get it to have an ip address in my guest operating system (container, systemd-nspawn).

My local network interface is eth0,
As described in the Wiki, I have no IP address bound to it, neither fixed nor via DHCP.

ip_forward is '1'

brctl show

bridge name     bridge id               STP enabled     interfaces
br0             8000.d6e03aae6748       no              eth0
                                                        vb-arch

I start my arch container like this:

systemd-nspawn --boot --directory=/var/lib/machines/arch --network-bridge=br0

I have created the following files.

bridge.network

[Match]
Name=br0
[Network]
DHCP=ipv4

bridge.netdev

[NetDev]
Name=br0
Kind=bridge

bind.network

[Match]
Name=eth0
[Network]
Bridge=br0

eth0-interface.network

Match]
Name=eth0
[Network]
# DHCP=ipv4

10-eth0-rename.link

[Match]
MACAddress=00:0c:29:12:53:3d
[Link]
Description=LAN-Verbindung
Name=eth0

I have neither an IP in the host nor in the guest.

The guest tells me:

host0@if6: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 4a:dd:02:08:f2:8f brd ff:ff:ff:ff:ff:ff link-netnsid 0

The host:

vb-arch@if2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br0 state LOWERLAYERDOWN group default qlen 1000
    link/ether 62:54:42:cd:31:80 brd ff:ff:ff:ff:ff:ff link-netnsid 0

And something strange I also find the name of the network adapter...@if2 and host0@if6,
but that does not necessarily have to have something to mean.

Does anyone have any idea what's wrong?

Last edited by taumeister (2019-08-10 19:54:17)

Offline

#2 2019-08-08 19:58:19

taumeister
Member
Registered: 2019-01-06
Posts: 31

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

Wow, 500 people read that... nobody got an idea?

Offline

#3 2019-08-08 22:37:14

Omar007
Member
Registered: 2015-04-09
Posts: 368

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

At first glance, I don't really see anything jarring that should be breaking your setup so I'll go over everything in your post.

Since you're not giving much details on what setup you desire, going with what you have done so far I'm going to assume several things.
And I can't stress this enough; please verify that these assumptions do indeed apply and match reality!
1) You want the container to be a locatable device in the LAN, as if it's another device plugged directly into the same network as the host (so the host does not do NAT)
2) The host and containers will receive their IPs from the network (DHCP)
3) 'eth0' (or the device with MAC address 00:0c:29:12:53:3d) will be the physical link to the network
4) You're solely using systemd-networkd and no other networking related software is running that manages wired connections while you're attempting this.

With that in mind;

taumeister wrote:

bridge.network

[Match]
Name=br0
[Network]
DHCP=ipv4

bridge.netdev

[NetDev]
Name=br0
Kind=bridge

The bridge looks fine. You declare a device and tell it to receive its address using DHCP (limited to IPv4). No changes should be needed here.

taumeister wrote:

bind.network

[Match]
Name=eth0
[Network]
Bridge=br0

This is also good; this binds the physical link to the bridge.

taumeister wrote:

eth0-interface.network

Match]
Name=eth0
[Network]
# DHCP=ipv4

Just remove this file. It is serving no purpose. Furthermore, I'm going to assume this is a copy/paste error, otherwise this broken file is messing up systemd-networkd when it tries to load up your configuration.

taumeister wrote:

10-eth0-rename.link

[Match]
MACAddress=00:0c:29:12:53:3d
[Link]
Description=LAN-Verbindung
Name=eth0

Assuming the MAC address matches, this should be fine.


taumeister wrote:

And something strange I also find the name of the network adapter...@if2 and host0@if6,
but that does not necessarily have to have something to mean.

What command are you using to list these? It also doesn't seem like this is covering the full list. Please supply the full outputs.
And tbh, these suggest some other program is manipulating interfaces (breaking assumption #4).

Also, make sure to restart the systemd-networkd service after making changes.

taumeister wrote:

Wow, 500 people read that... nobody got an idea?

Don't do that. If people have an idea, they will answer. Don't go bumping your post


EDIT: Also, make sure the permissions for those files are correct. They either need to be owned by systemd-network and/or world readable (e.g. 644).

Last edited by Omar007 (2019-08-08 22:49:30)

Offline

#4 2019-08-08 23:23:45

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

I have no experience with nspawn networking, but this looks good according to the wiki and https://www.freedesktop.org/software/sy … spawn.html

I think you just have to start systemd-networkd in the container or manually assign an IP or use some other dhcp client.

Edit: Or do you mean your br0 has no ip either? systemd-network is enabled, started and reloaded as Omar007 said?

Last edited by progandy (2019-08-08 23:33:20)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#5 2019-08-09 09:10:24

taumeister
Member
Registered: 2019-01-06
Posts: 31

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

Hi Omar and hi Progandy, thanks for your answers.

omar wrote:

Since you're not giving much details on what setup you desire, going with what you have done so far I'm going to assume several things.
And I can't stress this enough; please verify that these assumptions do indeed apply and match reality!
1) You want the container to be a locatable device in the LAN, as if it's another device plugged directly into the same network as the host (so the host does not do NAT)
2) The host and containers will receive their IPs from the network (DHCP)
3) 'eth0' (or the device with MAC address 00:0c:29:12:53:3d) will be the physical link to the network
4) You're solely using systemd-networkd and no other networking related software is running that manages wired connections while you're attempting this.

Basically I want to achieve that my containers can be addressed with their own IP address in my own subnet.
I don't care if I use systemd or netctl or whatever for the network administration. But like in the manual I used systemd-networkd.
I proceeded according to these instructions.
https://ramsdenj.com/2016/09/23/contain … spawn.html

1. Yes.
2. As I said, I want the container to have its own IP. I don't care if it gets it via DHCP or via an assignment.DHCP is ok for me.
3. Yes, this is my physical network adpater.
4. Ehm...now that you ask...network manager's activated.That could also be a problem, of course, right?
5.

taumeister wrote:
eth0-interface.network

Match]
Name=eth0
[Network]
# DHCP=ipv4
Just remove this file. It is serving no purpose. Furthermore, I'm going to assume this is a copy/paste error, otherwise this broken file is messing up systemd-networkd when it tries to load up your configuration.

The missing bracket is of course only a copy-and-paste error.
This file is to configure my renamed network adapter (ens33). (10-eth0-rename.link)
Previously this network adapter was configured with DHCP, but since I understood that a bridge can only be connected to an interface that has no IP address, I commented it out.

6. And of course, whenever I make any changes, I restart the corresponding services. In this case, of course, systemd-networkd.
7.

taumeister wrote:
And something strange I also find the name of the network adapter...@if2 and host0@if6,
but that does not necessarily have to have something to mean.

What command are you using to list these? It also doesn't seem like this is covering the full list. Please supply the full outputs.
And tbh, these suggest some other program is manipulating interfaces (breaking assumption #4).

I use ip a or ip link

progandy wrote:

I think you just have to start systemd-networkd in the container or manually assign an IP or use some other dhcp client.

Edit: Or do you mean your br0 has no ip either? systemd-network is enabled, started and reloaded as Omar007 said?

I have already tried to connect the interface connected via the bridge inside the container via
ip link set interfacename up and get an address via dhcpd, but I don't get one.
What I haven't tested yet is to simply give me a fixed IP inside the container.
According to the instructions I showed above, this didn't seem necessary either.

Offline

#6 2019-08-09 10:16:52

Omar007
Member
Registered: 2015-04-09
Posts: 368

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

Ok so from what you're saying it seems you have to much stuff running managing the network. Pick one and kill/disable the others.
If you pick systemd-networkd we can continue on this path (and it'll probably just work at that point), otherwise we'll have to create a configuration for the one you choose instead.

From this single post it sounds like you currently have systemd-networkd, NetworkManager and dhcpcd running all at the same time.
(you wrote dhcpd but that would be the server application to give out IP addresses to clients, not to receive one, so I'm assuming that's another typo. The sentence is a bit conflicting; '... and get an address ..., but don't get one' xD)

Last edited by Omar007 (2019-08-09 10:23:28)

Offline

#7 2019-08-09 10:59:01

taumeister
Member
Registered: 2019-01-06
Posts: 31

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

Ok Omar, I will  give it a try when I´m back home.
I will disable all other stuff that is managing my network and will restart with systemd-networkd.

I come from Germany and to be able to answer quickly, I kick it all through deepl.com translators.
Sorry, if there are some mistakes.
And also, who thinks of such sick and similar sounding names all the time...dhcpcd and dhcpd.
This is as sick as downloading networkmanager, but activating NetworkManager and adding network-manager-applet. No matter that is offtopic.
So I'll let you know when I have my system clean and then we start again with systemd-networkd.
Thanks for your help anyway.

Offline

#8 2019-08-09 15:57:54

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

taumeister wrote:

And also, who thinks of such sick and similar sounding names all the time...dhcpcd and dhcpd.

In their defence, the 'dhcp' stands for Dynamic Host Control Protocol.  The 'c' in the client program stands for client. The 'd' in both cases means daemon.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#9 2019-08-09 20:10:32

taumeister
Member
Registered: 2019-01-06
Posts: 31

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

let's try it again.

I created a new machine without networkmanager, without netctl but only with systemd-networkd.
No other network manager interferes.

I have created a minimal installation to /var/lib/machines/arch with pacstrap and can start it. Since I share the host network, I can also access the internet. So this works fine.
But, as a reminder, I want to have a separate IP address for this container on the same network as my host.

To the network:
I first activated and started systemd-resolved and set a link to /etc/resolv.conf as described in the instructions on this page.
https://ramsdenj.com/2016/09/23/contain … spawn.html

Then I configured my network with systemd-networkd.
Here I created 5 files

10-ens33-interface.network

[Match]
Name=ens33
[Network]
DHCP=ipv4

bridge.netdev

[NetDev]
Name=br0
Kind=bridge

bridge.network

[Match]
Name=br0
[Network]
DHCP=ipv4

bind.network

[Match]
Name=ens33
[Network]
Bridge=br0

vethernet.network

[Match]
Name=host0
[Network]
DHCP=ipv4

Starting the container

systemd-nspawn -b -D /var/lib/machines/arch --network-bridge=br0

This is the output of 'ifconfig' on the host

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::d4e0:3aff:feae:6748  prefixlen 64  scopeid 0x20<link>
        ether d6:e0:3a:ae:67:48  txqueuelen 1000  (Ethernet)
        RX packets 59  bytes 6925 (6.7 KiB)
        RX errors 0  dropped 13  overruns 0  frame 0
        TX packets 42  bytes 7166 (6.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.5.142  netmask 255.255.255.0  broadcast 192.168.5.255
        inet6 fe80::20c:29ff:fe12:533d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:12:53:3d  txqueuelen 1000  (Ethernet)
        RX packets 2610  bytes 823694 (804.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 136  bytes 11183 (10.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vb-arch: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::6054:42ff:fecd:3180  prefixlen 64  scopeid 0x20<link>
        ether 62:54:42:cd:31:80  txqueuelen 1000  (Ethernet)
        RX packets 25  bytes 3279 (3.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 31  bytes 4188 (4.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

And this is the output in the container

[root@arch ~]# ifconfig
host0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::48dd:2ff:fe08:f28f  prefixlen 64  scopeid 0x20<link>
        ether 4a:dd:02:08:f2:8f  txqueuelen 1000  (Ethernet)
        RX packets 23  bytes 2836 (2.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1926 (1.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Unfortunately no network access.

When I start dhcpcd in the container, I get an apipa

[root@arch ~]# dhcpcd 
dev: loaded udev
no valid interfaces found
no interfaces have a carrier
forked to background, child pid 49
[root@arch ~]# ifconfig
host0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 169.254.218.248  netmask 255.255.0.0  broadcast 169.254.255.255
        inet6 fe80::48dd:2ff:fe08:f28f  prefixlen 64  scopeid 0x20<link>
        ether 4a:dd:02:08:f2:8f  txqueuelen 1000  (Ethernet)
        RX packets 35  bytes 4748 (4.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30  bytes 3913 (3.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I almost thought it wouldn't make any difference and we were back at the same point.
Do you have any idea what we can do now?
I would really appreciate your help.

Last edited by taumeister (2019-08-09 20:11:49)

Offline

#10 2019-08-09 21:46:45

taumeister
Member
Registered: 2019-01-06
Posts: 31

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

EDIT:
Okay, I tried the bridge-utils and brctl.
First I deleted all files in /etc/systemd/network, except my network adapter 10-ens33-interface.network.

systemctl restart blablabla...host restart blabla

Then

brctl addbr br0
brctl addif br0 ens33
ip link set dev br0 up
# brctl show                                                      
bridge name     bridge id               STP enabled     interfaces
br0             8000.d20cc5f16b71       no              ens33
                                                        vb-arch

Now my container gets an ip address which is one higher than my host and the container can be connected to the internet and can be reached from outside.
However...my host is no longer available.

My God, this can't really be such a witchcraft thing, can it?

Offline

#11 2019-08-10 01:08:26

taumeister
Member
Registered: 2019-01-06
Posts: 31

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

Okay, I got it.
I did it both with the
bridge-utils & systemd-networkd as well as with NetworkManager.

I'll write it down again tomorrow, but there's one crucial point.
The moment you bind the created bridge to your host interface, it must be without IP address.


https://superuser.com/questions/153559/how-can-i-clear-the-ip-address-of-ethernet-interface-without-cycling-the-interfa
ip addr del 10.22.30.44/16 dev eth0 or
ip addr flush dev eth0

And on the other side in the container, there has to be systemd-networkd oder NetworkManager activated.

Offline

#12 2019-08-10 09:26:14

Omar007
Member
Registered: 2015-04-09
Posts: 368

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

If you're adding information and no one has posted in between, just edit your last post instead of adding new ones.


Well, yea, of course that is happening. That's because you're telling systemd-networkd to do so.
With the files from 3 posts earlier I'd say you should do the following to get it to work (again, do not use anything else to manage the network when setting this up!!):

1) Delete 10-ens33-interface.network
    This file is breaking the host setup
2) Delete vethernet.network
    Or rather, move to the container instead! It's pointless to have this file on the host. From what I can tell by the container ifconfig output, you'd want this inside your container instead. Assuming you're using (or going to use) systemd-networkd inside the container as well.

There is no need to use use bridge-utils nor NetworkManager if you set it up correctly. Until you do so, don't go pulling in a bunch of other stuff in an attempt to get it to work. It'll just make your whole setup a lot more complex and troublesome to fix and maintain.
And yea, of course the container/VM/whatever needs some network configuration. How else would it know how to connect and access things over the link you gave it? See also point #2 above.

Last edited by Omar007 (2019-08-10 09:45:33)

Offline

#13 2019-08-10 10:15:31

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

Omar007 wrote:

2) Delete vethernet.network
    Or rather, move to the container instead! It's pointless to have this file on the host. From what I can tell by the container ifconfig output, you'd want this inside your container instead. Assuming you're using (or going to use) systemd-networkd inside the container as well.

Just delete it, the container already should have /usr/lib/systemd/network/80-container-host0.network by default if systemd-networkd is installed and running.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#14 2019-08-10 13:20:26

taumeister
Member
Registered: 2019-01-06
Posts: 31

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

Okay, I get what you two mean, and I'm about to test it.
However, the manual from the website
https://ramsdenj.com/2016/09/23/contain … spawn.html
is actually total crap, because that's what it says. Anyway, that doesn't have to be right. And I think it's logical to have the configuration file for the client or the container in the container and not on the host. I should have thought of that myself.

But if I also delete the configuration file for my real physical network adapter on the host, how do I explain networkd which IP address I want to have.
In this case it was DHCP, but what if I want a fixed address?
I thought that I needed this file to configure my network adapter?

Offline

#15 2019-08-10 15:41:39

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

When you create a bridge that contains the network adapter, then you configure DHCP or a static IP for the bridge instead of the network adapter.

The guide you linked doesn't say anything wrong about the bridge configuration. It wants the following:
Host:

  • delete all network config

  • create /etc/systemd/network/bridge.netdev (create br0)

  • create /etc/systemd/network/bridge.network (set dhcp or ip for br0)

  • create /etc/systemd/network/ethernet.network (make network adapter part of br0)

Container:
Do nothing for DHCP. Only for static IP, mask the 80-container-host0.network and create your own vethernet.network

Last edited by progandy (2019-08-10 15:48:55)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#16 2019-08-10 18:14:55

taumeister
Member
Registered: 2019-01-06
Posts: 31

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

Okay, guys, that worked well.
I did it just like that now and it worked right away.
I also had to 
ip link set ens33 down
ip link set <bridge> up
edit the network adapters.

I would have expected, however, that on the host, now only the bridge is available and has an IP, but it is now the case that both the normal network adapter and the bridge have an IP address.
Both work and I can ssh to the host of the network adapter ens33 and also to the bridge...?
After I copied a configuration file to /etc/systemd/network into the container and deactivated the 80-container...the network in the container worked as desired.

I now have a DHCP address on the network adapter ens33 [local], a fixed address on the bridge and a fixed address in the container.
Looks like it's okay now, doesn't it?

EDIT: No, its working as expected. ens33 is up but no ip, br0 is up with fixed ip and container has fixed ip.
Perfekt.

Guys, thank you so much for taking so long.
You really helped me a lot.

Last edited by taumeister (2019-08-10 18:44:15)

Offline

#17 2019-08-13 13:37:42

t.ask
Member
Registered: 2013-01-14
Posts: 11

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

taumeister wrote:

Okay, guys, that worked well.

Now that you have the solution, can you please post all the files and locations separated by host and container as reference? This helps others configuring it the same way, thanks.

Offline

#18 2019-08-13 17:45:45

taumeister
Member
Registered: 2019-01-06
Posts: 31

Re: [solved] systemd-networkd with systemd-nspawn no ip in guest and host

systemd-nspawn-HOST

cat <<< '[NetDev]
Name=br0
Kind=bridge' > /etc/systemd/network/br0.netdev
 
cat <<< '[Match]
Name=br0
[Network]
Address=192.168.5.253/24
Gateway=192.168.5.254
DNS=192.168.5.254
DNS=8.8.8.8' > /etc/systemd/network/br0.network
 
cat <<< '[Match]
Name=enp4s0
[Network]
Bridge=br0' > /etc/systemd/network/ethernet.network

# systemctl enable --now systemd-networkd

CLIENT / CONTAINER

ln -sf /dev/null /etc/systemd/network/80-container-host0.network

cat <<< '[Match]
Name=host0
[Network]
Address=192.168.5.100/24
Gateway=192.168.5.254
DNS=192.168.5.254
DNS=8.8.8.8' > /etc/systemd/network/host0.network

# systemctl enable --now systemd-networkd

Last edited by taumeister (2019-08-13 17:46:25)

Offline

Board footer

Powered by FluxBB