I don’t seem able to use or resolve .local (mDNS) hostnames from within the default Home Assistant Docker container.
Network mode is set to host. On the host system I can resolve .local hostnames for devices on my network. If I try to use any of those .local hostnames from within the container, it fails.
I’ve been googling a bunch to try understand what the problem is and how to fix it but I’ve mostly found explanations for how to make mDNS work without network mode host or how to announce the docker container itself with a mDNS entry, neither of which I am interested in.
I just want to be able to use myservicehost.local from within the Home Assistant container.
Any thoughts / advice / pointers?
Thanks!
Context: My router “melted” today and I had to completely patch up my network to at least function with basic capability until I was able to replace and reconfigure a new router. This caused me to loose many services and having to update many configurations based on them now pointing at the wrong IP addresses. As a takeaway from this I want to make an effort to more heavily rely on mDNS as a more flexible way to address and discover hosts across my network.
No, right now, I am using my internet provider plastic cable modem as router and DHCP server (also see “Context” above). It does not provide DNS itself at all.
When my main network router broke (which WAS running a DNS server, but mostly for caching purposes), notably, hosts and services that are addressing each other with mDNS where the only parts of my smart home that resumed working without requiring any reconfiguration. Everything else that was using either DNS names resolved by the router or IP addresses across multiple VLANs and subnets directly, required fixing of configurations in numerous different locations.
My temporary router is not capable of routing between VLANs (which means, currently I have most of my critical devices swarming a single large IP network) or able do static IP address assignments. If I was mostly using mDNS host names however, none of this would matter and most services would just resume working even with an entirely completely changed network and topology.
But even if my temporary router could do these things, it would still require lots of manual configuration and re-setting up, at least as long as I cannot import my old routers configuration into my temporary (which in this case I cannot). Had I more heavily used mDNS, due to it’s distributed nature, most of my network/smart home would have just “healed” itself. And as I mentioned above, the things that are using mDNS did so.
While I appreciate your input I really would like to know how I can get mDNS working inside the Docker container. I believe Home Assistant itself already uses zeroconf/mDNS for service discovery, but I assume not through the core OS mechanisms, which do not seem to be working correctly: docker exec -it home-assistant /bin/ping myhost.local will lead to a bad address error whereas ping myhost.local on the same shell on the Docker host will resolve the address correctly.
Re-reading this, there might be a misconception, here.
For mDNS to work, the “server” (myservicehost.local) must be actively supporting it. I.e. it must be advertising its IP address by use of the mDNS protocol.
If it doesn’t, mDNS will not work, HA container or not.
Thanks for pointing this out. As I mentioned, from outside of the container (i.e. the host system) I do not have any issues resolving the mDNS names, only within the container.
I think I’ve fix this issue for me. If you use Adguard or some other non-conventional DNS server, this might be similar to your situation too.
Summary:
Having something like avahi-browse -ar do discovery and spit out a list of found devices and their hostname+IP address, is completely separate from a tool like ping or curl or whatever that completes mostly standard DNS resolution to figure out the IP address to conga-drums.local. Either if the container isn’t setup to look up mDNS first before calling a DNS server (which neither HA or the ESPHome containers do) or your DNS server doesn’t know about any .local hostnames, regardless of if stuff in that container can find out about devices via avahi-browse -ar, none of the other components part of that service will be able to resolve the IP address and talk with them.
My fix was to spin dnsmasq back up on a different port than 53 with only offering up resolution for .local domains, and then add that to the “Upstream DNS servers” list in Adguard (for specific domains). Once that was done all of my containers could resolve conga-drums.local.
I’m going to paste this around to a few other related threads, because I burnt a whole day trying to figure this out. Hope this helps some of you.