19

If I'm using Ubuntu or Linux Mint (the only two flavours I've tried and know work for sure), I can run something like this:

wayne@myhost$ ssh wayne@otherhost.local

And the name is automagically resolved to whatever the IP of otherhost is on my local network.

I've decided to start branching out into other distros, and I've got Arch running on my laptop - but if I try using the previous command I get Could not resolve hostname otherhost.local: Name or service not known

What does it take to get this sort of automatic name resolution(?) to take place?

1
  • 5
    You have to install avahi as well as nss-mdns - for more details have a look at the arch wiki Jul 23, 2012 at 14:20

3 Answers 3

20

Wayne's own answer is quite old by now. Arch has since switched to using systemd instead of init scripts. The Arch wiki's Avahi page has been updated and contains details on why the steps below are needed. In short: Avahi is a zeroconf tool, meaning itself needs no configuration to work once installed on all machines your LAN, but you must configure the rest of your software so it actuall asks Avahi for the information.

Run these as root, or prepend with sudo where appropriate, in a terminal and replace nano with the editor of your choice.

  1. pacman -S avahi nss-mdns Installs the Avahi services daemon and the Multicast DNS resolver.
  2. nano /etc/nsswitch.conf This file tells the C library how to obtain name-service information.
  3. Change the line hosts: files dns myhostname to hosts: files mdns_minimal [NOTFOUND=return] dns myhostname, save and exit.
  4. systemctl start avahi-daemon Starts the Avahi service manually since we're already booted.look for errors)
  5. systemctl enable avahi-daemon Enables the Avahi service on boot.

I just performed these steps on an Arch laptop and there was no need to restart any other services or the wifi interface to have my other machines discover it within a few seconds, and have my laptop discover their services.

Since I can't comment on ggg's answer yet, I'd just like to point out here that there is no need to do this in a startup script -- that's what enabling the service in systemd is for. Do it once and forget about it.

1
  • 5
    You can even combine steps 4 and 5: systemctl enable avahi-daemon --now. It starts and enables the service immediately instead of waiting for the next startup. Jul 24, 2017 at 13:18
11

Thanks to the pointer to the Arch Wiki article on Avahi from Ulrich Dangel, this is what I did:

  1. Install avahi and nss-mdns $ sudo pacman -S avahi nss-mdns
  2. Add /etc/rc.d/avahi-daemon start to the end of rc.local
  3. Since I'm running dhcpcd, in /etc/dhcpcd.conf I commented out the noipv4ll line.
  4. I also ran $ sudo /usr/sbin/avahi-autopid -D wlan0. Since I don't like restarting, I'm not sure if step 3 was necessary.
  5. In /etc/nsswitch.conf I set the line to read hosts: files mdns4_minimal dns mdns4.
  6. Then I ran $ sudo /etc/rc.d/dbus restart to restart dbus.

After that, simply doing ssh wayne@other.local just worked.

2
  • 1
    Regarding your second point: You might as well just add "avahi-daemon" to the DAEMONS line in /etc/rc.conf
    – Wieland
    Jul 23, 2012 at 16:31
  • I thought about that, but the wiki indicated that some people had issues with it starting too quick in rc.conf and failing as a result, and that placing it where I did was a fix. Jul 24, 2012 at 2:25
3

I do not think we need avahi-daemon running to use .local. Here's is what I have for in my startup script. This is much simpler compared to the Arch Wiki's method.

systemctl enable avahi-daemon
avahi-set-host-name $(hostname)
systemctl disable avahi-daemon

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .