Using Avahi on Ubuntu

I tried to set up Avahi on Ubuntu 18.04.1 LTS (Bionic). My main requirement was to be able to access hosts within my home LAN without having to set up a DNS server.

Great article to understand how Avahi works on linux system - Archlinux wiki entry on Avahi.

Cookbook

nsswitch setup

nsswitch.conf seems to be set up correctly in the default install.

$ grep hosts /etc/nsswitch.conf
hosts:          files mdns4_minimal [NOTFOUND=return] dns

See all local services on zeroconf

$ avahi-browse-domains -at
...
+ enp6s0 IPv4 Brother HL-XXXXXX                             Internet Printer     local
+ enp6s0 IPv4 Brother HL-XXXXXX                             PDL Printer          local
+ enp6s0 IPv4 Brother HL-XXXXXX                             UNIX Printer         local
+ enp6s0 IPv4 mynas                                         Apple TimeMachine    local
+ enp6s0 IPv4 My ecobee                                     _hap._tcp            local
+ enp6s0 IPv6 My ecobee                                     _hap._tcp            local
+ enp6s0 IPv4 Philips hue - XXXXXX                          _hap._tcp            local
+ enp6s0 IPv6 Philips hue - XXXXXX                          _hap._tcp            local
+ enp6s0 IPv4 Philips Hue - XXXXXX                          _hue._tcp            local
+ enp6s0 IPv6 Philips Hue - XXXXXX                          _hue._tcp            local
...
  • -a is for looking for all service types
  • -t is to quit after finding a complete list, and not hanging around waiting for others to pop up
  • We can use -l if we want to ignore services on the local machine.

Resolving local hosts

$ # forward
$ avahi-resolve-host-name mynas.local
mynas.local      192.168.1.212

$ # reverse
$ avahi-resolve-address 192.168.1.212
192.168.1.212   mynas.local

Firewall issues

The port used is 5353 (UDP). Firewall doesn’t seem to be active on my machine. But on remote hosts it might be.

Integration with DHCP client

Integration with the DHCP client seems to be done to run avahi-autoipd and get a link local address if DHCP times out.

# in /etc/dhcp/dhclient-exit-hooks.d/zzz_avahi-autoipd
...
case "$reason" in
...
    EXPIRE|FAIL|TIMEOUT)
        if [ -x /usr/sbin/avahi-autoipd ] ; then
            /usr/sbin/avahi-autoipd -wD $interface 2> /dev/null
        fi
        ;;
esac

On the other hand, if the DHCP client is successful in getting an IP, it runs an avahi script to kill any running avahi-autopid daemons.

# /etc/dhcp/dhclient-enter-hooks.d/avahi-autoipd
...
case "$reason" in
...
    PREINIT|BOUND|RENEW|REBIND|REBOOT|STOP|RELEASE)
        if [ -x /usr/sbin/avahi-autoipd ] && /usr/sbin/avahi-autoipd -c $interface; then
            /usr/sbin/avahi-autoipd -k $interface 2> /dev/null
        fi
        ;;

    EXPIRE|FAIL|TIMEOUT)
        # Starting avahi-autoipd is left for the exit hook
        ;;
esac

References


ubuntu  dns 
comments powered by Disqus