TL;DR: How can I get myhost.local
to resolve to my wifi interface rather than the Docker virtual network?
My desktop system's hostname is "myhost" (from /etc/hostname
etc), running Ubuntu 18.04.
The ip a
command tells me that my wifi ip address is 192.168.0.6
, and my rarely-used docker-network ip address is 172.17.0.1
.
I like to use mdns/Avahi to access my desktop, via "myhost.local", e.g. when connecting to local jupyter notebooks from other hosts on my home LAN.
For some reason, mdns is assigning two addresses to myhost.local
:
$ host myhost.local
myhost.local has address 192.168.0.6
myhost.local has address 172.17.0.1
myhost.local has IPv6 address fe80::46da:e48:c3c0:112
Jupyter notebook is running with ip=192.168.0.6
When I ping myhost.local
, or connect to http://myhost.local:8888/
it worked a few months ago, but now it tries the 172.17.0.1 address, which doesn't work for jupyter.
This seems related to the unanswered question at the Docker Community Forum: Docker network interface interferes with mDNS address.
Update: to answer a question, this is the hosts file. I think it comes from the default way that Ubuntu sets up the hosts file, so localhost
is not actually the same as myhost
, but I might have tweaked it.
$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 myhost
Bonus Update
user10489
correctly notes that other hosts will resolve myhost.local
via mdns just fine. And my underlying problem was that I wanted to know what ip address to configure in my jupyter notebook
to make it available over my wireless LAN. It's just that we don't see an easy way to use mdns on the local machine to get that answer.
The resolution to that underlying problem is this, to just figure out which ip address I have on a given interface (here illustrated with Ubuntu's awkwardly-named first wireless network name):
dev=wlp3s0
ip=$(ip -br -o a show $dev | (read interface status ip ip6; echo ${ip%/*}))
jupyter notebook --no-browser --ip=$ip
Reading the man page for the avahi daemon conf file (/etc/avahi/avahi-daemon.conf) it looks like you can specify interfaces that you explicitly want to deny:
So maybe try adding the line "deny-interfaces=docker0" to that file (always backup the original!), and then reloading with "avahi-daemon --reload". Change "docker0" to whatever your docker interface is called, though I think that's the default.
https://linux.die.net/man/5/avahi-daemon.conf
http://manpages.ubuntu.com/manpages/bionic/man8/avahi-daemon.8.html
There are multiple name resolution mechanisms active here by default:
This is the default order, and mdns usually tries to resolve *.local
But also consider that this is the case separately for two machines -- the local and the remote machine.
So, if you want myhost.local to resolve to a specific interface without disabling mdns on other interfaces, you should be able to just put an override in /etc/hosts. However, this only affects the local machine.
Remote machines will resolve myhost.local with whatever mdns broadcasts they hear. So if they are on your docker network, and your lan (as your local machine would be), they would get all those addresses from mdns. If they're only on one of those networks, they should see only the address that corresponds to that network.
So perhaps the solution is not to change configuration, but change what host you are using to ask the question.