Zeroconf provides a simple way to network several computers without DHCP/DNS servers. It is a set of techniques to assign an IP address, provide name resolution and service discovery. It is most useful for ad-hoc networks (LAN-Party, Meeting, WLAN, Bluetooth, etc).
In this HOWTO we'll use the Avahi implementation of the protocols. We'll set up automatic IP address configuration and name resolution.
The following packages are needed:
The following use flags should be set:
- autoipd (only for net-dns/avahi, to build the avahi-autoipd program)
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. Therefore see /etc/dhcp/dhclient.conf.sample for dhclient.
sys-auth/nss-mdns provides functionality to hook into the name resolution process, so that zeroconf .local addresses are checked before using normal DNS. To enable .local name resolution, 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
Now add the relevant daemons to the runlevels:
# rc-update add avahi-daemon default
To immediately make use of Avahi do the following as root:
# /etc/init.d/net.eth0 restart # /etc/init.d/avahi-daemon start
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.
To advertise a service, create a file in /etc/avahi/services. For example, to advertise your http server, create file /etc/avahi/services/http.service with the following contents:
<service-group> <name replace-wildcards="yes">HTTP Server on %h.</name> <service> <type>_http._tcp</type> <port>80</port> </service> </service-group>
Scan for Services
To scan your network for advertised services, you can download mdns-scan from http://0pointer.de/lennart/projects/mdns-scan/.
This article is a bit short and could use some improvements:
- add info about service discovery
- different implementations (mDNSresponder,dns-sd) and their (dis)advantages
- solving problems with unicast .local domains
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.