Avahi

From Gentoo Linux Wiki

Jump to: navigation, search

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,

emerge -av net-dns/avahi

Add the avahi-daemon to the default runlevel,

rc-update add avahi-daemon default

[edit] Testing

If the daemon is installed and running, you can test its function on the local machine by running,

avahi-browse -a

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:

avahi-discover

[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,

emerge www-apache/mod_dnssd

add APACHE2_OPTS="${APACHE2_OPTS} -D DNSSD" to /etc/conf.d/apache2

File: /etc/conf.d/apache2
...
APACHE2_OPTS="${APACHE2_OPTS} -D DNSSD"

Restart the apache server,

/etc/init.d/apache2 restart

[edit] Cups

Note: You will need to enable the mDNSResponder-compat USE flag in order for net-print/cups to build with Avahi support.

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

Note: distcc up to version 3.1-r1 does not support IPv6. Avahi will need to be reemerged without IPv6 support.

Make sure you first enabled the avahi USE flag for sys-devel/distcc. Edit your distcc hosts file to include zeroconf hosts,

File: /etc/distcc/hosts
...
#Include avahi/zeroconf hosts
+zeroconf

[edit] NTP

See NTP#Zeroconf.

[edit] MPD

Edit /etc/mpd.conf and enable Zeroconf support as shown below,

File: /etc/mpd.conf
...
########################### 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

File: /etc/avahi/services/ftp.service
<?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.

Note: This is only necessary for older versions of samba. The 3.3.x and higher builds in ~arch can be built with avahi support and will handle this without the new file
File: /etc/avahi/services/smb.service
<?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.

Note: Apache does this with the mod-dnssd mudule, see above! I think mixing both methods will lead to disaster.
File: /etc/avahi/services/http.service
<?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:

File: /etc/avahi/services/nfs_someshare.service
<?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.

Note: This Function seems to be now broken in Mac OS X 10.5.

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.

emerge Image-Imlib2

Then, install the DPAP server using CPAN,

perl -MCPAN -e 'install Net::DPAP::Server'

Create the DPAP server script(/etc/dpap_srv),

File: /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,

File: /etc/avahi/services/dpap.service
<?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,

/etc/init.d/avahi-daemon restart

And finaly, start the DPAP server,

perl /etc/dpap_srv

[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):

File: /etc/conf.d/net
 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:

File: /etc/nsswitch.conf
#hosts:       files dns 
hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4 

or, if you also want IPv6 support, to

File: /etc/nsswitch.conf
 hosts:          files mdns_minimal [NOTFOUND=return] dns mdns 

[edit] Finalizing

To immediately make use of Avahi do the following as root: Code:

/etc/init.d/net.eth0 restart /etc/init.d/avahi-daemon restart

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!

File: /etc/nsswitch.conf
...
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

Personal tools