I’m trying to reach devices on the local network on which the resin device (Raspberry PI 3) is running by using its hostname, i.e. “DeviceName.local”.
If I ping the device via its IP address, it can be reached, however using the hostname does not work. Using “hostname.${dns-suffix}” where dns-suffix is the suffix specified by the router (which would change whenever the router is changed), works as well.
Is it possible to access devices via hostname in the local network from inside the container? The IP addresses of these devices might change.
Hi, as much as I understand, even on the local network you cannot ping a device just by the hostname, if your local machine doesn’t know what IP address that hostname corresponds to. The router-provided DNS suffix, and the avahi-provided .local helps to bridge that, because the device that pings knows who to ask what the IP is…
Under normal circumstances for example the hostname -d command can be used to discover the current dns suffix, but that doesn’t seem to have access to that information inside docker by default. Also, the /etc/resolv.conf file can (probably should?) contain the dns suffix for example as a line as search $(dns-suffix). I think that information might not be set up in the resin case completely…
This is definitely a legitimate use case, and will ask the team for further information…
I added avahi (based on this example) and can now view some of my devices at their .local hostname. I can’t find my philips-hue even though I have another raspberry pi running raspbian on the same network where I can do API calls to the philips-hue hostname. Any ideas on this?
Communication to local devices using their hostname certainly doesn’t work on Resin out of the box. I couldn’t get it to work with only the information that swgn provided. I’d love a standalone example of this that could be used to show what’s required to make it work.
I appreciate you sharing that example. I put everything important from that example in my project but avahi-browse -a does not list the device (it doesn’t list that device on my mac for avahi-browse either BTW). I’m trying to communicate with a philips hue gateway. On my mac (on the same network), I can do ping philips-hue and I get a response:
PING philips-hue.home (192.168.1.16): 56 data bytes
64 bytes from 192.168.1.16: icmp_seq=0 ttl=255 time=4.211 ms
On the resin device, if I do the same ping philips-hue (after installing iputils-ping), I get: ping: unknown host philips-hue.
Clearly I don’t understand the networking side of this issue in detail, but if the mac can resolve the hostname, I would assume that I could do the same in resin. Do you have any other ideas of how I can do this? Thanks for the help so far.
I think the issue is, that the router sets the .home for the local network’s domain name. Thus avahi (and avahi config, probably both on your Mac and on resinOS) is looking for it’s default .local ending. Check /etc/avahi/avahi-daemon.conf and the domain-name= setting (the default is domain-name=local). I think this is the missing piece, but hard to check not being on your own network.
That domain name is broadcast by the router as well, though, so a normal ping should be able to resolve philips-hue to philips-hue.home, possibly, but not sure… Maybe this info is something that can further your investigation?
I changed the line in /etc/avahi/avahi-daemon.conf to read domain-name=home but I still can’t ping it by hostname.
Can you ping any local devices on your network by hostname? I found that the iPhone app Fing is good for discovering hostnames on the network. No matter which device I try, I always receive unknown host.
After researching this some more, I don’t think avahi is really going to solve my problem. As mentioned in the second post in this series, I think I actually want to change resolv.conf. On my mac, my /etc/resolv.conf lists
domain home
nameserver 192.168.1.1
which explains how it can resolve the hostname. I don’t think it’s using avahi/bonjour.
No, in my situation I don’t think avahi will work. In my last post, I asked about resolv.conf, which might be the way forward, but I need some help from Resin.
Hi! Any updates here? We have the same issue in our company network. The resin host got 2 DNS servers via DHCP plus one ?preconfigured? in ResinOS with IP 8.8.8.8. So 3 DNS servers in total. Sometimes the resolution of our internal names fail. How can we permanently edit the resolv.conf or get rid of the 8.8.8.8?
Hi Ilias,
thanks for your fast response. I already read the network section in the documentation and tried to configure the DNS via dbus. Modifying the image is only plan B.
I’m guessing Resin automatically adds Google’s DNS, but we will need clarification from them. Surprisingly, my file only lists nameserver 172.17.0.1, which I didn’t add either… Seems to be a Docker feature.
Would you mind sharing your script that adds the nameservers to resolv.conf? I see there’s an example on the networking page, but it doesn’t seem to cover the DNS specifically.
Hello again,
so I was informed that you can configure the behavior of resinOS by setting the “dnsServers” property in the config.json file in the boot partition. So you will need to add "dnsServers": "XX.XX.XX.XX YY.YY.YY.YY" (space separated) in the config.json.