Dnsmasq.raw in cluster

I have a cluster setup (with fan networks) and would like to reserve the first few ip addresses on each host for static containers (e.g. egress proxys).

dnsmasq.raw: dhcp-range can only be set once of the whole network across all hosts, which isn’t right for what I want in two different ways.

I can start the “service” containers after LXD start / restart, but this give rise to a brief period when these addresses could be allocated to another container.
Is there an “auto-start” option for containers which would allow these service containers to be started before all others?

I could probably fake it by adding something into /var/snap/lxd/common/lxd/networks/lxdfan0/dnsmasq.raw on each host, but this looks, to me, to be a fragile hack.

Can you advise, what’s the best option?

David

p.s. fanctl has a --host-reserve option for this purpose.

You can use the ipv4.dhcp.ranges network setting to specify what range of IPs dnsmasq will give our to DHCP clients.

https://linuxcontainers.org/lxd/docs/master/networks#network-bridge

You can then use the IPs outside of those ranges safely knowing they won’t be allocated via DHCP.

And/or you can create static leases for your instances by assigning them an IP using lxc config device override <instance> eth0 ipv4.address=n.n.n.n and this will create a static DHCP reservation for that IP and MAC address.

thanks @tomp. How does that interact with the fan network?

I need a different DHCP range for each host with the fan network as each host “chooses” IP addresses from a different range of the whole subnet (depending on the host).

If I specify multiple ranges for the dnsmasq dhcp-ranges, will LXD pick the right subrange for each host?
A bit clunky but OK if it works. :slight_smile:

Im not sure actually, good point. Can you try it and if it doesnt work please can you open an issue at https://github.com/lxc/lxd/issues

Thanks

The bad news:
ipv4.dhcp.ranges is not allowed in fan networks:
Error: IPv4 configuration may not be set when in 'fan' mode

The good news:

config:
  bridge.mode: fan
  fan.overlay_subnet: 240.0.0.0/8
  fan.underlay_subnet: 10.2.0.0/16
  dns.mode: managed
  raw.dnsmasq: |
    dhcp-range=240.0.215.16,240.0.215.253
    dhcp-range=240.0.213.16,240.0.213.253
    dhcp-range=240.0.214.16,240.0.214.253

worked!

I only tried 6 containers on each host, but they all were assigned addresses from the right range (which is vanishingly unlikely by random) so it works. :grinning_face_with_smiling_eyes:

1 Like