DNS entry for the host in bridge network?

hello there :slight_smile:

i’m new here, so first of all congrats to everyone for the job you’re doing on lxc/lxd, it’s really a breeze to use and it made my life so much simpler !

then onto my question : since every container i create on my bridge network has a dns entry corresponding to its name, i wanted to know if the host also had a dns entry ? if not, would it be possible to implement it ?
i know it can be accessed through x.x.x.1 but that means i have to compute its address somehow, it would be easier if it had its own dns entry don’t you think ?

thank you !

The ability for the host to understand hostnames like mycontainer.lxd is not LXD functionality, therefore it is not included in the LXD packages. Is it something outside of the responsibility of LXD itself.

It is a good feature though, and have a look at this older post,

Thank you, but what I mean is to access the host from the containers.
I already managed to access the containers from the host by creating a new domain.

For example, if I have a “wildfly” container and a “postgresql” container, I can easily access them by their name from the other container thanks to the dns server on the bridge network. What I’d like to do is accessing the host like this, from the containers, through a special name or something…

i’m kinda new to linux networking though, maybe there’s already this kind of entry, since the host’s ip and the dns server’s ip are the same…

The purpose of a container is not to be able to affect/access the host.
If you managed to find a way for a container to access the host from a container, that would have been a serious bug.

I suppose what you are saying, is that you may happen to have a good reason to need to access the host from the container.
In that case, you would need (on the host) to bind any network services on the lxdbr0 interface. From the container, you can access through the IP address of the bridge.

Example:

On the host: nc -l 10.52.252.1 8080 # keep this running in a terminal
On the container: echo “hello, there” | nc 10.52.252.1 8080

indeed that’s what i’m already doing, with netcat just like you showed, for healthcheck purpose actually
(i’d like to minimze the use of “lxc exec” as much as possible)
but i’d like to be able to access without the ip, just with the “hostname”, since it’s possible to have a random network address range for the bridge
it’s a “nice to have” feature really, i can very well manage without it, i was just curious if it could be done

Those mycontainer1.lxd, mycontainer2.lxd, etc are handled by the dnsmasq process that LXD is spawning.
Therefore, you just need to get LXD’s dnsmasq to recognize this additional new (static) hostname.

Let’s assume the IP address is 10.52.252.1.

  1. Append the following to /etc/hosts of the host.

10.52.252.1 lxdserver

  1. Run the following on the host.

sudo killall -SIGHUP dnsmasq

(this one will make all dnsmasq’s to reread their configuration files, which probably does not hurt. Else, pick the correct dnsmasq for LXD to send the SIGHUP signal that makes it to just reread the configs).

That’s it. From inside the container, you can

# ping lxdserver
PING lxdserver (10.52.252.1) 56(84) bytes of data.
64 bytes from lxdserver (10.52.252.1): icmp_seq=1 ttl=64 time=0.063 ms
...

thank you very much !
i’ll try that :slight_smile: