You are not logged in.

#1 2023-01-02 20:19:09

jernst
Member
From: Silicon Valley
Registered: 2014-03-04
Posts: 296
Website

Stable IPs/DNS on virtual network of systemd-nspawn containers

I'm trying to run a number of communicating systemd-nspawn containers for development purposes.  systemd-nspawn has the handy "--network-zone" flag that automatically sets up a virtual bridge. I'm trying to figure out how to get them all stable IP addresses, and a local DNS setup that doesn't require too much ongoing maintenance.

Ideally I would:
* systemd-nspawn -M server1 ... --network-zone develop
* systemd-nspawn -M server2 ... --network-zone develop
* systemd-nspawn -M server3 ... --network-zone develop

where now any serverN can find the other servers as serverM.example.com.

What I managed to do:
* Give each serverN a stable static IP, by overriding DHCP from /usr/lib/systemd/network/80-container-host0.network with a static IP inside the container

What I've failed to do:
* Those static-IP containers cannot communicate with the outside world
* I tried to define a .network file for [Match] vz-develop and give it a static IP, but that doesn't do anything (I'm sure I'm doing this wrong)
* It would be so much nicer if the host handed out stable IP addresses via DHCP in any case.

And secondly, is there a better way to deal with hostnames than adding those static IPs into /etc/host of all containers? Because right now, I run the containers, find out what their IP addresses are, then edit all /etc/hosts and then start my various daemons. (Terrible) I am aware of systemd mapping container names to their IP addresses, but for my purposes, I need fully-qualified names, e.g. server1.example.com, not server1 only.

If anybody has a working setup like this, how does it look like?

Last edited by jernst (2023-01-02 20:21:51)

Offline

#2 2023-01-02 23:09:29

jernst
Member
From: Silicon Valley
Registered: 2014-03-04
Posts: 296
Website

Re: Stable IPs/DNS on virtual network of systemd-nspawn containers

I found that the last byte of the IP addresses allocated to the container appear to be stable across container restarts. And same for the second byte that's apparently allocated to the network associated with the "--network-zone" bridge. Whether that is true or not, I don't know, but it looks like it.

Offline

Board footer

Powered by FluxBB