How can I connect to `hostname.local` machines when running HA under HassOS / HassIO?

Hi, when running HA under Raspbian or Ubuntu I have no problem connecting to hostname.local computers on my LAN but when running it under HassOS/HassIO I get nslookup: can;t resolve (null): Name does not resolve when trying to nslookup hostname.local.

I can normally use IP addresses for most thing but my MQTT broker is using TLS and only allows connections using a hostname, not an IP address, so I need some way to resolve mDNS hostnames in home assistant.

Any help / advice / pointers in the right direction would be appreciated, thanks.

Do you see a hostname when you go to the hassio panel>system tab?

Do you see a hostname when you go to the hassio panel>system tab?

Hi, yes it’s hassio, I’ve just left it at default, I should have included more info in my original post. Here’s the info from my system tab:

Host system

Hostname hassio
System HassOS 1.12
Deployment production

Hass.io supervisor

Version 139
Latest version 139

I’m not installed any extra addons yet, as I’m just trying to get Home Assistant to talk to my MQTT broker first. I’m running it on a Raspberry Pi 3, good PSU, good quality SD card, etc.

I can access the Raspberry Pi fine using another machine on the network using it’s hostname: ssh [email protected] -p 22222

It’s when I try to connect the other way, from the HA docker container to another machine on my network with a *.local hostname I get connection error.

To use my MQTT example, if I set my configuration.yaml to access using the hostname:

mqtt:
  broker: mqtt_broker.local
  port: 8883
  keepalive: 60
  certificate: cert.crt

I get a connection failed error in my Home Assistant log, and the MQTT broker doesn’t even log a connection attempt.

If I set my configuration.yaml to access using the IP address:

mqtt:
  broker: 192.168.1.99
  port: 8883
  keepalive: 60
  certificate: cert.crt

Then it does actually try and connect to my MQTT broker as it logs a connection attempt, but then the auth fails as my MQTT broker only allows connections to the hostname mqtt_broker.local

I’d like to fix this if possible, as I was able to connect to my MQTT broker without issue when running Home Assistant under VirtualEnv on Raspbian but under HassIO / HassOS it just will not connect.

If you’re using the inbuilt MQTT broker you can remove the whole mqtt: section from config yaml

If using a different broker, does it require a username and password?

I’m not using the internal MQTT broker, I’m using an external MQTT broker that running on another computer on my LAN.

It does require a username and password, I have it set in my configuration.yaml, here’s my complete MQTT server section:

mqtt:
  broker: mqtt_broker.local
  port: 8883
  keepalive: 60
  certificate: cert.crt
  username: !secret mqtt_username
  password: !secret mqtt_password
  birth_message:
    topic: "tele/hass_io/LWT"
    payload: "Online"
    qos: 1
    retain: false
  will_message:
    topic: "tele/hass_io/LWT"
    payload: "Offline"
    qos: 1
    retain: false

I’ve checked secrets.yaml is present and correct, I’m using the same yaml files that I backed up when I moved over from VirtualEnv to HassOS

is the ssl certificate address correct?

docs say /home/user/.homeassistant/server.crt
but it might be /config/cert.crt in your case…

Yes I have cert.crt in the /config/ folder.

The Configuration validation feature checks pass also, I’ve found if the cert.ca is in the wrong place then it will fail the checks.

Here’s the error I’m getting in my HA logfile:

(MainThread) [homeassistant.components.mqtt] Failed to connect due to exception: [Errno 110] Operation timed out

I suggest you try /config/cert.crt see if it validates. I had an issue with a command_line sensor because of this. The docs seemingly are incomplete for hassio users in some cases.

Ok thanks, I’ve changed the yaml and so it now have the full path:

  certificate: /config/cert.crt

I’m now waiting for it to reboot.

It does seem the docs have to cater to many setups, most people are probabliy using the built in MQTT broker addon so that explains why it’s the most documented. :slight_smile:

Ok, it’s rebooted, still getting a constant homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected. error

It seems to be a mDNS issue, I can find the IP address on Raspbian:

$ nslookup mqtt_broker.local
Server:     192.168.1.1
Address:    192.168.1.99

But if I try it from the HA container:

$ docker container exec homeassistant nslookup mqtt_broker.local
nslookup: can't resolve '(null)': Name does not resolve

Name:      mqtt_broker.local
Address 1: 92.242.132.16

So it looks like it’s resolving to the wrong IP address, one outside my LAN, which would explain why I’m getting connection errors.

Set up your DNS properly and all will work.

He’s trying to use mDNS which is a ZeroConf system. I guess you didn’t catch the .local extension to the hostnames he’s been posting?

@Codec303 Is Avahai installed in the HA container? That’s required to resolve mDNS hostnames.

Set up your DNS properly and all will work.

Avahi is a good call, it may be worth checking if any ports are blocked on the firewall or router as I think it’s on a different port to DNS.

Set up your DNS properly and all will work.

Hi, can you please expand on how I can do this?

I’m using a standard hassOS install, and the DNS is fine on my LAN as I can access *.local addresses from Raspbian but not HassOS.

DNS outside my LAN resolve OK:

$ docker container exec homeassistant nslookup google.com
nslookup: can't resolve '(null)': Name does not resolve
Name:      google.com
Address 1: 216.58.204.46 lhr25s12-in-f14.1e100.net
Address 2: 2a00:1450:4009:80d::200e lhr25s12-in-x0e.1e100.net

even tho the nslookup: can't resolve '(null)': Name does not resolve does look a little odd.

@Codec303 Is Avahai installed in the HA container? That’s required to resolve mDNS hostnames.

Hi, thanks it does seem that there are Avahi files already in the HA container:

~ # docker container exec homeassistant find / | grep -i avahi
/usr/lib/libavahi-common.so.3.5.3
/usr/lib/libavahi-client.so.3
/usr/lib/libavahi-client.so.3.2.9
/usr/lib/libavahi-common.so.3

However on Raspbian Avahi is run as a service on startup, so I’ll have to check if the HA container is going the same thing.

It may be that the service is installed and not enabled.

Avahi is a good call, it may be worth checking if any ports are blocked on the firewall or router as I think it’s on a different port to DNS.

Thanks I’ll check my settings but AFAIK nothing to blocked on my internal LAN

Ok just a quick update, it seems I need Avahi and Nss-mdns installed in each container I need to access .local hostnames but it’s not straight forward as Avahi doesn’t allow multiple instances on a single system with the default settings, something do to with dbus.

If anyone else wants to do the same thing you need to change the rlimit setting, I’ve not got it working yet but other have, so it is possible.

He’s suggesting you set up a local DNS server and everything will work as you expect.

I have never relied on zeroconf/mdns/avahi in my network. Too many devices don’t support it so you’re still stuck with half of it working. I prefer a proper DNS that resolves my local network as a DNS server is intended to do

pi-hole makes a great DNS/DHCP server.

He’s suggesting you set up a local DNS server and everything will work as you expect.

I see, thanks for the clarification. I’ll look into setting up a local DNS server, or maybe some sort of mDNS to DNS gateway.

I have never relied on zeroconf/mdns/avahi in my network. Too many devices don’t support it so you’re still stuck with half of it working. I prefer a proper DNS that resolves my local network as a DNS server is intended to do

If you can manage without mDNS tho then the standard HassIO setup will work out the the box.

With the VirtualEnv install of HA everything on my network was working great, my Tasmota flash Sonoff’s use it for MQTT broker discovery with TLS without issue, and I’m also using it for homekit2mqtt which works really well, but I’m going to use HA eventually for HomeKit things.

Without mDNS most of my stuff would just stop working, and I really like the way HassIO works, it’s just a shame mDNS seem to be broken.

pi-hole makes a great DNS/DHCP server.

Thank you, I’ll have a look into pi-hole.

For now I’ve gone back to Raspbian, and now have HA installed in both VirtualEnv and also HassIO under docker, that way I can swap between them with services and can see what is and isn’t working with each method.

Under Raspbian and HassIO under docker I still get MQTT connection errors, so this seems more of a HassIO issue rather than a HassOS issue.