WSL: Can't resolve ".local" (mDNS) hosnames

I have an existing stock Ubuntu server on my network. Let’s say its hostname is “my-server”. (The following should work with a stock Mac as well; not sure about Windows servers?)

If I open up a regular Command Prompt, I can do the following:

C:\Users\me>ping my-server.local

Pinging my-server [10.0.0.1] with 32 bytes of data:
Reply from 10.0.0.1: bytes=32 time=3ms TTL=64
Reply from 10.0.0.1: bytes=32 time=1ms TTL=64
Reply from 10.0.0.1: bytes=32 time=1ms TTL=64
Reply from 10.0.0.1: bytes=32 time=1ms TTL=64

Ping statistics for 10.10.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 3ms, Average = 1ms

But from Bash-on-Windows:

bash-on-windows$ ping my-server.local
ping: unknown host my-server.local

For comparison, from a real Ubuntu machine on the same network, I can do:

real-linux$ ping my-server.local
PING my-server.local (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.206 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=0.138 ms
64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=0.130 ms
(...)

Granted, ping wouldn’t work even if it could resolve the name due to #18 , but other tools like curl or ssh would work if appropriate services were running on the server. I’m just trying to post a minimal reproducer.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 14
  • Comments: 39 (5 by maintainers)

Most upvoted comments

This is still an issue, please reopen.

I am able to use cmd.exe to ping a .local but not WSL.

gives an example of the behaviour on native linux and then an example on WSL on native linux and then an example on WSL. note that the two systems behave differently despite the same software being installed.

On Native Linux mDNS services are normally provided by Avahi. As you assured me, your request is for mDNS name resolution to work on WSL, not the Avahi mDNS service. It is not the same software installed. One is Avahi. One is the Windows 10 mDNS service.

There is also a dependency on dbus working

There are no known outstanding issues with dbus in WSL. If you find any problems with dbus, please feel encouraged to open a new issue describing the diverge.

Are you really saying this bug was closed because no one can demonstrate mDNS resolution fails in WSL but does not fail under Windows 10?

I am really saying: that if it doesn’t work, that would be a great new issue submission. But it would need a repro with a concise set of CLI repro steps on both the win32 side and the WSL side that identified a diverge in behaviour in WSL versus say a Real Linux Ubuntu in a VM connected to the same mDNS service on Windows.

Oooh, I just hit this one. It was quite a head-scratcher! I’m curious as to whether there’s been any progress on this 😮

It also refutes Microsoft’s position that “it is impossible to do mDNS in WSL because the WinNT side does mDNS” - if PowerShell can do mDNS, then they should be able to replicate that functionality as a resolver. I am reminded that Microsoft has a long history of favoritism. I mean, it’s not surprising that they want you to use WinNT instead of WSL, but they should at least stop saying they’re “a Linux Company” or that they support Linux. WSL is a toy, meant to demonstrate the functionality of their hypervisor (which, admittedly, is pretty cool if you want to run WinNT). They clearly have no interest in making a useful product. As much as I groan every time I have to slog through the AWS console, I’m happy to stick with AWS if this is how they support Linux.

no. mDNS already works on Windows 10. in fact, my work around is to use cmd.exe to do the resolution with a command like ping -4 whatever.local and then copy the ip address into a bash window.

i assure you, my request is for mDNS name resolution to work on WSL.

the title of this issue is “can’t resolve ‘.local’ (mDNS) hostnames” and not “can i listen on port 5353.”

i’m asking if we’ll ever be able to resolve .local (mDNS) hostnames.

@scivision - I looked into this a bit. As explained previously, there were two blocking issues.

  1. Lack of SO_REUSEPORT in WSL (and in Windows in general).
  2. Lack of SO_PASSCRED on NETLINK sockets.

After stubbing (1) (because there is no support from Windows networking stack), implementing (2) and few other minor changes, it seems like avahi-daemon is happy.

:~# service dbus start
 * Starting system message bus dbus                                    [ OK ]
:~# service avahi-daemon start
 * Starting Avahi mDNS/DNS-SD Daemon avahi-daemon                      [ OK ]
:~# avahi-resolve-address 192.168.0.52
192.168.0.52    xxxxx.corp.microsoft.com
:~#

I will get the PR out and try to get this in time for Fall Creators Update.

If you look at the avahi-daemon logs (with this change), it still complains about IP_ADD(DROP)_MEMBERSHIP, but that can be taken up as a separate issue. It appears to be functional otherwise, in my limited testing.

This should be fixed in 16273

I really think this issue should be reopened. It would be great if WSL handled mDNS out of the box, or if one simply had to apt install avahi-daemon; sudo service avahi-daemon start Being able to resolve “.local” network names without copying->pasting ip addresses should be possible.

edit: I’m still seeing this issue on build 17134.286, any assistance is appreciated.

On one of the latest builds:

$ apt-get install -y avahi-daemon
$ /etc/init.d/dbus start
$ /usr/sbin/avahi-daemon

Process 588 died: No such process; trying to remove PID file. (/var/run/avahi-daemon//pid)
Found user 'avahi' (UID 112) and group 'avahi' (GID 116).
Successfully dropped root privileges.
avahi-daemon 0.6.32-rc starting up.
Successfully called chroot().
Successfully dropped remaining capabilities.
No service file found in /etc/avahi/services.
*** WARNING: Detected another IPv4 mDNS stack running on this host. This makes mDNS unreliable and is thus not recommended. ***
SO_REUSEPORT failed: Protocol not available
*** WARNING: Detected another IPv6 mDNS stack running on this host. This makes mDNS unreliable and is thus not recommended. ***
SO_REUSEPORT failed: Protocol not available
netlink.c: SO_PASSCRED: Invalid argument
on: starting up: iface-linux.c:380: avahi_interface_monitor_sync: Assertion `m' failed.
Aborted (core dumped)

From the output above, we can see few blocking issues here. Those would be; support for the socket option SO_REUSEPORT and SO_PASSCRED for netlink sockets. Support for SO_REUSEPORT requires some work from the core Windows networking team and the WSL team is working with them on that. SO_PASSCRED for netlink sockets seems entirely in control of WSL and should be trivial. No ETA for either of them yet.

To get .local mDNS hostnames working on WSL 1, I ran the following:

sudo apt update
sudo apt install avahi-daemon
sudo service dbus start
sudo service avahi-daemon start

If I leave out sudo service dbus start then I see:

Starting Avahi mDNS/DNS-SD Daemon avahi-daemon                 [fail]

For me this is only working over IPv4, and not over IPv6.

Lack of Avahi support in WSL makes it difficult to use WSL/WIndows PCs in teaching labs with increasingly ubiquitous Raspberry PI and the like in engineering education.

Btw., is this issue also on WSL 2?

avahi-daemon is okay on WSL2 ref #4210 (message). I’ve been using it myself recently. Whether something like that would (or even should) get rolled into WSL-brand /init I don’t know. I suspect (but can’t prove) the longer term answer is going to be some kind of support for systemd.

This issue ended up dupe #376 and fixed in 16273, because that was the first (but not the only) blocker on avahi-daemon at the time. Also ref #3365.

It’s understandable why avahi does not work out-of-the-box, but this doesn’t mean that the issue is resolved. The issue presented in the first entry could be solved without avahi, e.g. by adding the mDNS entries to /etc/hosts by WSL, or providing the mapping in any other way.

Manually translating hostname to IP will not work if TLS is involved and certificate is issued for the .local domain name. Likewise, SSH may complain.

If not by default, does anyone know if there is a (linux-side) service that can be installed, that interfaces WinNT side to query mDNS resolution?

@ma2shita That works, but it’s not a workaround when I’m trying to use Ansible to provision machines, for example.

hovis@Lucca:/mnt/c/Users/hovis$ ping andromeda.local
ping: andromeda.local: Name or service not known
hovis@Lucca:/mnt/c/Users/hovis$ powershell.exe "Resolve-DnsName andromeda.local"

Name                                           Type   TTL   Section    IPAddress
----                                           ----   ---   -------    ---------
Andromeda.local                                AAAA   120   Answer     fe80::b711:58ca:4722:ceda
Andromeda.local                                A      120   Answer     10.0.0.69

How about trying this?

$ powershell.exe "Resolve-DnsName raspberrypi.local"

powershell.exe can be invoked from bash on WSL. STDOUT is returned to bash so it can be piped. (e.g. grep, jq (with ConvertTo-JSON in PowerShell))

$ powershell.exe "Resolve-DnsName raspberrypi.local | ConvertTo-Json" | jq -r .IPAddress

@sunilmut This is still not working in Version 10.0.17763 Build 17763

i assure you, my request is for mDNS name resolution to work on WSL.

And I assure you, if it doesn’t work, that would be a great new issue submission. But it would need a repro with a concise set of CLI repro steps on both the win32 side and the WSL side that identified a diverge in behaviour in WSL versus say a Real Linux Ubuntu in a VM connected to the same mDNS service on Windows.

Which no one (that I am aware of) has looked into.