Avahi
avahi is a zeroconf service discovery and publishing program. A common use for it is to be able to connect to machines via yourhostname.local
within your LAN.
Installation
Kernel
Networking support --->
Networking options --->
[*] IP: multicasting
USE flags
Some packages are aware of the zeroconf USE flag pulling in avahi.
USE flags for net-dns/avahi System which facilitates service discovery on a local network
+dbus
|
Enable dbus support for anything that needs it (gpsd, gnomemeeting, etc) |
+introspection
|
Add support for GObject based introspection |
autoipd
|
Build and install the IPv4LL (RFC3927) network address configuration daemon |
bookmarks
|
Install the avahi-bookmarks application (requires dev-python/twisted) |
doc
|
Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally |
gdbm
|
Add support for sys-libs/gdbm (GNU database libraries) |
gtk
|
Use gtk3 for the avahi utilities to build the avahi-ui-gtk3 library |
howl-compat
|
Enable compat libraries for howl |
ipv6
|
Add support for IP version 6 |
mdnsresponder-compat
|
Enable compat libraries for mDNSResponder |
mono
|
Build Mono bindings to support dotnet type stuff |
nls
|
Add Native Language Support (using gettext - GNU locale utilities) |
python
|
Add optional support/bindings for the Python language |
qt5
|
Add support for the Qt 5 application and UI framework |
selinux
|
!!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur |
systemd
|
Enable use of systemd-specific libraries and features like socket activation or session tracking |
test
|
Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently) |
Server
root #
emerge --ask net-dns/avahi
Client
root #
emerge --ask sys-auth/nss-mdns
Configuration
Server Services
systemd
Enable the server to start whenever systemd thinks it is appropriate:
root #
systemctl enable avahi-daemon.service
If you want to use it right away, also start the service:
root #
systemctl start avahi-daemon.service
OpenRC
Be sure to add the service to the default runlevel for the server daemon to start on system boot. Do so with the rc-update command:
root #
rc-update add avahi-daemon default
Start the service (without restarting) with the rc-service command:
root #
rc-service avahi-daemon start
Client Files
Add the appropriate mdns into the hosts line in /etc/nsswitch.conf, An example line looks like:
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
Once this is installed it should be possible to ping the hostname of the machine appending .local
. For example:
user $
ping yourhostname.local
Service Discovery
To configure Avahi to advertise zeroconf services to clients, add configurations in /etc/avahi/services
. For example, this snippet in /etc/avahi/services/smb.service
which will make SMB services discoverable
<?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_smb._tcp</type> <port>445</port> </service> <service> <type>_device-info._tcp</type> <port>0</port> <txt-record>model=RackMac</txt-record> </service> </service-group>
Troubleshooting
Check avahi-daemon is running and listen for 5353 UDP:
root #
ss -ltunp | grep 5353
Output:
udp UNCONN 0 0 0.0.0.0:5353 0.0.0.0:* users:(("avahi-daemon",pid=4072,fd=13)) udp UNCONN 0 0 *:5353 *:* users:(("avahi-daemon",pid=4072,fd=14))
Commands like host(1) and dig(1) don't use nsswitch.conf(5), so they can't be used for Avahi diagnostics. Instead, use getent(1). For example:
user $
getent hosts gentoo-desktop.local
Output when mdns_minimal in /etc/nsswitch.conf:
fe80::bbbd:5967:6af8:9d27 gentoo-desktop.local