Moving from LXD to LXC: host DNS resolver and proxy protocol

Hi. On a new homelab (Debian based) I decided to use LXC instead of LXD (or Incus). I cannot find solutions for these items in manpages of LXC:

  1. Are domains available in LXC i.e. in LXD all containers get <container_name>.lxd domains. Can I get something like this in LXC?
  2. How to define host dns resolver (Nginx, resolver directive: how-to? - #9 by Druid). In LXD it could have been achieved with lxc network set lxdbr0 raw.dnsmasq="address=/gateway.lxd/"
  3. Is it possible to achieve something similar like proxy_protocol from LXD but in LXC (How to get real client ip when using lxd to forward port 80 - #4 by simos)

As I understand Incus will support all of that but I am wondering can it be achieved with LXC and some other Linux tools available? And just to mentioned it will work on a single machine, no need for a cluster. I would appreciate if you can recommend some guides or articles.

It’s a fair bit more manual with LXC. There is a systemd job called lxc-net which runs the lxcbr0 bridge and you can edit /etc/default/lxc-net to have that dnsmasq daemon include some of your own config, but you won’t get LXC to automatically add static leases or the like.

You may be able to configure a domain in dnsmasq and let it generate DNS records for you through DHCP requests, dnsmasq is pretty flexible.

Thanks, I found a few articles/guides in a similar direction. And your answer tells me that I should try to implement it that way in LXC.
Also, Happy New Year.

One more question. Are environment variables for lxc-net from this file officially supported:
Are they supposed to be used by LXC users? Why I am asking. I cannot find them in any of man pages. Or am I missing it?

Yeah, all of those LXC_ env variables should be safe to use.

Exact behavior may vary a bit between distros. I seem to remember ubuntu shipping with a very comprehensive /etc/default/lxc-net which listed them all, whereas other distros (like my local Debian) don’t really do that.

Just for historical reasons I am going to post my findings for my questions here.
Automatic domains for lxc containers can be done with editing /etc/default/lxc-net in case of Debian 12 and adding this line LXC_DOMAIN="lxc". At minimum it allows lxc containers to access each other using <container_name>.lxc hostname.

1 Like

I wasn’t able to find a solution to port-forward connection from host to container with dynamic IP. But I could do it for a container with a static ip using lxc.hook.start and lxc.hook.stop hooks and iptables.
I was thinking to use but ip is not assigned to a container at this stage. I tried to use lxc-info in lxc.hook.start hook. But in this case lxc-start hangs.