Installing mDNS resolver in Bash on Windows Subsystem for Linux

5,709

You have two options:

  1. Install the libnss-mdns package which will change your system's resolver to query .local. domains via mDNS. Note that most builds of this do not honour local on the resolver search path (see the comments on this answer) so you will need to look up MacbookPro.local rather than just MacbookPro.

  2. Install the avahi-utils package and use the avahi-resolve program to do the lookups. You may also find the other tools in this package to be an easier way of looking up services and the like.

Share:
5,709

Related videos on Youtube

Wasabi Fan
Author by

Wasabi Fan

Updated on September 18, 2022

Comments

  • Wasabi Fan
    Wasabi Fan almost 2 years

    I am trying to connect to a PC over mDNS from a Bash script running on Windows. While I am able to ping the PC through its mDNS .local address in CMD, doing the same in an Ubuntu/Bash window fails due to a hostname resolution issue.

    When I try to install avahi-daemon, it seems to fail to start the service, and as a result I can't resolve mDNS names.

    $ sudo apt-get install avahi-daemon
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
      libfreetype6 os-prober
    Use 'apt-get autoremove' to remove them.
    The following extra packages will be installed:
      libavahi-common-data libavahi-common3 libavahi-core7 libdaemon0 libnss-mdns
    Suggested packages:
      avahi-autoipd
    The following NEW packages will be installed:
      avahi-daemon libavahi-common-data libavahi-common3 libavahi-core7 libdaemon0
      libnss-mdns
    0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
    Need to get 220 kB of archives.
    After this operation, 1,094 kB of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main libavahi-common-data amd64 0.6.31-4ubuntu1 [21.2 kB]
    Get:2 http://archive.ubuntu.com/ubuntu/ trusty/main libavahi-common3 amd64 0.6.31-4ubuntu1 [21.7 kB]
    Get:3 http://archive.ubuntu.com/ubuntu/ trusty/main libavahi-core7 amd64 0.6.31-4ubuntu1 [80.9 kB]
    Get:4 http://archive.ubuntu.com/ubuntu/ trusty/main libdaemon0 amd64 0.14-2ubuntu1 [16.4 kB]
    Get:5 http://archive.ubuntu.com/ubuntu/ trusty/main avahi-daemon amd64 0.6.31-4ubuntu1 [58.7 kB]
    Get:6 http://archive.ubuntu.com/ubuntu/ trusty/main libnss-mdns amd64 0.10-6 [21.4 kB]
    Fetched 220 kB in 1s (159 kB/s)
    Selecting previously unselected package libavahi-common-data:amd64.
    (Reading database ... 24998 files and directories currently installed.)
    Preparing to unpack .../libavahi-common-data_0.6.31-4ubuntu1_amd64.deb ...
    Unpacking libavahi-common-data:amd64 (0.6.31-4ubuntu1) ...
    Selecting previously unselected package libavahi-common3:amd64.
    Preparing to unpack .../libavahi-common3_0.6.31-4ubuntu1_amd64.deb ...
    Unpacking libavahi-common3:amd64 (0.6.31-4ubuntu1) ...
    Selecting previously unselected package libavahi-core7:amd64.
    Preparing to unpack .../libavahi-core7_0.6.31-4ubuntu1_amd64.deb ...
    Unpacking libavahi-core7:amd64 (0.6.31-4ubuntu1) ...
    Selecting previously unselected package libdaemon0.
    Preparing to unpack .../libdaemon0_0.14-2ubuntu1_amd64.deb ...
    Unpacking libdaemon0 (0.14-2ubuntu1) ...
    Selecting previously unselected package avahi-daemon.
    Preparing to unpack .../avahi-daemon_0.6.31-4ubuntu1_amd64.deb ...
    Unpacking avahi-daemon (0.6.31-4ubuntu1) ...
    Selecting previously unselected package libnss-mdns:amd64.
    Preparing to unpack .../libnss-mdns_0.10-6_amd64.deb ...
    Unpacking libnss-mdns:amd64 (0.10-6) ...
    Processing triggers for ureadahead (0.100.0-16) ...
    Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
    Setting up libavahi-common-data:amd64 (0.6.31-4ubuntu1) ...
    Setting up libavahi-common3:amd64 (0.6.31-4ubuntu1) ...
    Setting up libavahi-core7:amd64 (0.6.31-4ubuntu1) ...
    Setting up libdaemon0 (0.14-2ubuntu1) ...
    Setting up avahi-daemon (0.6.31-4ubuntu1) ...
    runlevel:/var/run/utmp: No such file or directory
    invoke-rc.d: policy-rc.d denied execution of force-reload.
    runlevel:/var/run/utmp: No such file or directory
    invoke-rc.d: policy-rc.d denied execution of start.
    Processing triggers for ureadahead (0.100.0-16) ...
    Setting up libnss-mdns:amd64 (0.10-6) ...
    First installation detected...
    Checking NSS setup...
    Processing triggers for libc-bin (2.19-0ubuntu6.7) ...
    $ ping my-other-pc.local
    ping: unknown host my-other-pc.local
    

    What do I need to do to be able to resolve mDNS names? Is there an alternative to installing Avahi that works, or is there something else that I need to do to make this package function?