<div dir="ltr">Hello,<div class="gmail_quote"><div dir="ltr"><div><br></div><div>I was
recently tasked with moving existing network configuration for a machine
and some nspawn containers from iupdown to networkd.<br></div><div><br></div><div>The situation looks as follows:</div><div><br></div><div>A
single VPS has 3 IPs. One 37.x.x.x/22, and two 91.x.x.x/32. The 37-ip
is to be routed to the main server, whereas the two 91-ips should be
routed directly to nspawn containers running on the server. The server
uses systemd 247 and the container uses systemd 252, both Debian.<br></div><div><br></div><div>I created a bridge netdev like so:</div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">[NetDev]</span></div><div><span style="font-family:monospace">Name=br0</span></div><div><span style="font-family:monospace">Type=bridge</span></div><div><span style="font-family:monospace"># Matches physical network card<br></span></div><div><span style="font-family:monospace">MACAddress=AA:BB:CC:DD:EE:FF</span></div><div><br></div><div>Bound the physical ethernet to it like so:</div><div><br></div><div><span style="font-family:monospace">[Match]</span></div><div><span style="font-family:monospace">Name=ens3</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">[Network]</span></div><div><span style="font-family:monospace">Bridge=br0</span></div><div><br></div><div>And set up the main IP for the bridge like so:</div><div><br></div><div><span style="font-family:monospace">[Match]</span></div><div><span style="font-family:monospace">Name=br0</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">[Network]</span></div><div><span style="font-family:monospace">DNS=...</span></div><div><span style="font-family:monospace">DNS=...</span></div><div><span style="font-family:monospace">Address=37.x.x.x/22</span></div><div><span style="font-family:monospace">Gateway=37.x.x.1</span></div><div><br></div><div>The nspawn containers are added to the bridge via</div><div><br></div><div><span style="font-family:monospace">[Network]</span></div><div><span style="font-family:monospace">Bridge=br0</span></div><div><br></div><div>Up
until this point everything works. However, configuring networking
between the host and containers proved quite difficult and I'm unsure
whether I'm doing something wrong or networkd is.</div><div><br></div><div>What I tried was the following, inside the container:</div><div><br></div><div><span style="font-family:monospace">[Match]</span></div><div><span style="font-family:monospace">Virtualization=container</span></div><div><span style="font-family:monospace">Name=host0</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">[Address]</span></div><div><span style="font-family:monospace">Address=91.x.x.x/32</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">[Route]</span></div><div><span style="font-family:monospace">Gateway=37.x.x.x</span></div><div><span style="font-family:monospace">GatewayOnLink=true</span></div><div><br></div><div>However,
this did not create any usable routes to the host, nor did it throw any
errors in the journal. Pinging the host does not work.</div><div><br></div><div>Manually creating the routes with ip route did work:</div><div><br></div><div><span style="font-family:monospace">ip r add 37.x.x.x dev host0 onlink</span></div><div><span style="font-family:monospace">ip r add default dev host0 via 37.x.x.x</span></div><div><br></div><div>I tried a variety of different combinations of options in the .network file, Scope, Type, etc...</div><div><br></div><div>The only thing that successfully created any routes was the following:</div><div><br></div><div><span style="font-family:monospace">[Match]</span></div><div><span style="font-family:monospace">Virtualization=container</span></div><div><span style="font-family:monospace">Name=host0</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">[Address]</span></div><div><span style="font-family:monospace">Address=91.x.x.x/32</span></div><div><span style="font-family:monospace">Peer=37.x.x.x/32</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">[Network]</span></div><div><span style="font-family:monospace">Gateway=37.x.x.x</span></div><div><br></div><div>This
strikes me as odd because nowhere in the documentation, nor in any
online searching could I find this described as necessary (beyond the
manpage mentioning that Peer= exists)</div><div><br></div><div>On the
host side, I thought the bridge device, acting on Layer 2, would
automatically figure out routes to the containers (via ARP), or that
nspawn and networkd would interact in some way to add routes. However,
this didn't seem to happen, so I also had to add the following to the
bridge's .network file:</div><div><br></div><div><span style="font-family:monospace">[Route]</span></div><div><span style="font-family:monospace">Source=37.x.x.x<br></span></div><div><span style="font-family:monospace">Destination=91.x.x.A</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">[Route]</span></div><div><span style="font-family:monospace">Source=37.x.x.x<br></span></div><div><span style="font-family:monospace">Destination=91.x.x.B</span></div><div><br></div><div>With
all of this, everything works fine now. However, since the routes, both
host-to-container and container-to-host, differ somewhat from the old
(also working) setup, and some of the steps necessary I could not find
described anywhere, I am left wondering if I fundamentally misunderstand
something about how Linux networking works, or if perhaps networkd is
behaving oddly because of the IP addresses being considered in different
networks.</div><div><br></div><div>I would love to find a conclusive
answer to this, especially because I want to make sure I understood the
fundamental concepts involved correctly.</div></div>
</div></div>