Avahi
From Gentoo Linux Wiki
The purpose of this article is to give provide information on how to setup the avahi daemon, clients and services. This provide the share service for Apple's network service discovery method "Bonjour" and other systems using Zeroconf/Avahi.
Contents |
[edit] Installation
There are three USE flags around for Avahi/Bonjour support, some apps even use two of them. These are,
- avahi - Enables avahi support.
- zeroconf - Enables zeroconf support.
- bonjour - Enables bonjour support.
It it possible to enable them all globally in /etc/make.conf, but if you do this make sure you enable the howl-compat and mdnsresponder-compat compatibility USE flags on net-dns/avahi.
These USE flags are used by net-dns/avahi,
- dbus - Enable support for the D-BUS system message bus. This is needed for applications to publish their services automatically, i.e net-print/cups.
- autoipd - Enable the IPv4LL (RFC3927) network address configuration daemon.
- howl-compat - Enable howl compatibility layer.
- mdnsresponder-compat - Enable mDNSResponder compatibility layer.
- qt3 - Enable x11-libs/qt-3* bindings.
- qt4 - Enable x11-libs/qt-4* bindings.
- gtk - Enable x11-libs/gtk+ bindings.
- mono - Enable dev-lang/mono bindings.
- python - Enable dev-lang/python bindings.
Once you've set your USE flags, emerge avahi,
Add the avahi-daemon to the default runlevel,
[edit] Testing
If the daemon is installed and running, you can test its function on the local machine by running,
If you see something like the following, all is good,
+ eth1 IPv4 localhorst SSH-Fernzugriff local + eth1 IPv4 SFTP File Transfer on localhorst SFTP File Transfer local
Avahi also installs a graphical frontend (if build with any of the gtk, qt3 or qt4 USE flags) which you should be able to select from your menues. It is called "Avahi Zeroconf Browser". You can also start it from the commandline with:
[edit] Services
Some services requires a service description(/etc/avahi/services/), others can automatically publish their services through Avahi using the D-BUS message bus.
[edit] Apache
Sharing local homepages is absolutely easy. Emerge the dnssd mod,
add APACHE2_OPTS="${APACHE2_OPTS} -D DNSSD" to /etc/conf.d/apache2
...
APACHE2_OPTS="${APACHE2_OPTS} -D DNSSD"
Restart the apache server,
[edit] Cups
Zeroconf isn’t enabled by default so you have to browse the CUPS admin page and enable it.
- Open http://localhost:631/admin if you’re running it on localhost and enable the “Share published printers connected to this system” option. “Change Settings” will restart CUPS and your printer should be instantly visible to zeroconf-aware applications in the local network.
[edit] distcc
Make sure you first enabled the avahi USE flag for sys-devel/distcc. Edit your distcc hosts file to include zeroconf hosts,
... #Include avahi/zeroconf hosts +zeroconf
[edit] NTP
See NTP#Zeroconf.
[edit] MPD
Edit /etc/mpd.conf and enable Zeroconf support as shown below,
... ########################### ZEROCONF ########################### # # If yes, service information will be published with Zeroconf. # zeroconf_enabled "yes" # # The service name to publish. This name should be unique on # your local network. # zeroconf_name "local domain music player daemon" # ################################################################
[edit] Pidgin
Pidgin has the bonjour USE flag which enables it to communicate to other Instant Messenger in the LAN without a server. Just compile it with that flag, go to the "Accounts" menu, click add and choose "Bonjour" from the list of services. Type in a name you like to use and you are ready.
[edit] Custom Services
These are services that Avahi publishes based on what it finds in /etc/avahi/services.
[edit] FTP
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">FTP File Sharing on %h</name>
<service>
<type>_ftp._tcp</type>
<port>21</port>
</service>
</service-group>
[edit] Samba
Avahi can be used for a faster discovery of Samba shares.
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">Samba Shares on %h</name>
<service>
<type>_smb._tcp</type>
<port>139</port>
</service>
</service-group>
[edit] Webinterfaces
It is possible to Broadcast Bookmarks of your Webinterfaces on your local Network with the help of Avahi. For that you need to create an static Avahi Servicefile with the following Content. This may be used for non-Apache web-servers.
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name>MythWeb</name> ## Name of the Bookmark
<service>
<type>_http._tcp</type>
<port>80</port>
<txt-record>path=/mythweb</txt-record> ## Path
</service>
</service-group>Now restart Avahi and check the Bookmark Menu under Safari or Epiphany. There you will see how automatically they will appear, when those Services are available.
[edit] NFS
Apples's "Finder" is able to autodetect NFS Shares in the Network by using ZeroConf. For that we will use an static Avahi servicefile with the following content:
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">Music</name> ## Name
<service>
<type>_nfs._tcp</type>
<port>2049</port>
<txt-record>path=/media/someshare</txt-record> ## path to shared Folder
</service>
</service-group>
Now restart Avahi and see how those Shares get mounted with Finder.
A workaround is posted at http://www.macosxhints.com/article.php?story=20071116042238744
[edit] iPhoto
iPhoto uses dpap at port 8770. Once this is set up, one can browse shared photos via iPhoto or Front Row on a Mac, or from an Apple TV. Don't forget to enable the jpeg USE flag on media-libs/imlib2.
Then, install the DPAP server using CPAN,
Create the DPAP server script(/etc/dpap_srv),
use POE;
use Net::DPAP::Server;
my $server = Net::DPAP::Server->new(
path => '/my/photo/album',
port => 8770,
name => "My holiday snaps",
);
$poe_kernel->run;
Add the Avahi service file,
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_dpap._tcp</type>
<port>8770</port>
</service>
</service-group>
Restart the Avahi daemon,
And finaly, start the DPAP server,
[edit] Autoipd
Gentoo's /etc/conf/net can use autoipd as a module, which comes quite handy on LANs without DHCP running. The following packages are needed:
- net-dns/avahi
- sys-auth/nss-mdns
The following use USE flags should be set:
- avahi
- dbus
- autoipd (only for net-dns/avahi, to build the avahi-autoipd program)
[edit] Configuration
There is not much configuration needed but as the documentation is sparse you need to know where to look. First edit /etc/conf.d/net (replace eth0 with your interface):
modules=( "autoipd" ) config_eth0=( "autoipd" ) # If you want to try DHCP before getting an IP address with avahi use the following (useful for laptops in different environments): config_eth0=( "dhcp" ) fallback_eth0=( "autoipd" )
If you use the second configuration you may want to reduce the timeout for the DHCP client. Therefor see /etc/dhcp/dhclient.conf.sample for dhclient.
Now you need to edit the file /etc/nsswitch.conf: Change the following:
#hosts: files dns hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
or, if you also want IPv6 support, to
hosts: files mdns_minimal [NOTFOUND=return] dns mdns
[edit] Finalizing
To immediately make use of Avahi do the following as root: Code:
Now you should have a 169.254.* IP address (try ifconfig). Try to ping <yourhostname>.local to see if name resolution for the .local domain works.
[edit] Troubleshooting
[edit] Uninstalling
Make sure to change your /etc/nsswitch.conf back to the default values, if you ever uninstall sys-auth/nss-mdns!
... hosts: files dns ...
[edit] Browsing Services
- Make sure you use domain=local in /etc/avahi, NOT your real unicast dns domain!
- If firewalled, open port 5353 (UDP)
- Make sure you use the right network interface on machines with multiple network cards.
[edit] External Links
- http://avahi.org
- http://www.zeroconf.org
- http://www.apple.com/macosx/features/bonjour
- http://www.oreilly.com/catalog/bonjour
- http://www.dns-sd.org/ServiceTypes.html
- http://blog.venthur.de/2007/08/17/howto-setup-a-print-server-for-windows-and-others-using-cups-and-zeroconf
- http://mpd.wikia.com/wiki/Hack:avahi_mpd.service
- http://forums.gentoo.org/viewtopic-p-5387132.html (autoipd howto, thanks tobr!)
- http://code.google.com/p/distcc/issues/detail?id=34 (distcc patch for ipv6)
