The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Zero Configuration Networking
Zero Configuration Networking, also called Zeroconf or Bonjour (Apple's trademark for their Zero Configuration Networking implementation) is a suite of related technologies that allow networked devices to interoperate on a local network without requiring explicit configuration.
Requirements
Zero Configuration Networking requires the following things to operate:
- A valid IP address, obtained either by:
- Static assignment
- DHCP
- Link-local Addressing (part of Zero Configuration Networking)
- A means to address other devices by name, provided either by:
- DNS
- multicast DNS (mDNS -- part of Zero Configuration Networking)
Service Discovery
On top of this, Zero Configuration Networking also provides a means to discover what services are available on each device. This is something that is provided exclusively by Zero Configuration Networking and is called Zeroconf Service Discovery.
Configuration
In order to get these sort of networking services running, some configuration needs to happen initially.
Link-local Addresses
It's only necessary to use link-local addressing if you have no other means of obtaining a valid IP address on your LAN. Typically, this is the case if you are setting up a small or ad-hoc network where no DHCP server has been configured.
To use link-local addressing, first set up the proper routes:
route add default dev eth0 metric 99 route add -net 169.254.0.0 netmask 255.255.0.0 dev eth0 metric 99
Then, use avahi-autoipd to discover a valid link-local IP address:
/usr/sbin/avahi-autoipd --daemonize --syslog --wait eth0
Once a valid link-local IP address is found, eth0 will now have a 169.254.x.x address that can be used to communicate on the local LAN.
As an alternative, you can have dhcpcd built with USE="zeroconf"
, and it will provide a link local address if no DHCP server is found.
Multicast DNS
Multicast DNS, or mDNS, is a means by which individual machines can broadcast their DNS information to machines on the local LAN so that a DNS server is not required to address local devices by name. The ".local" domain is typically used for multicast DNS, so your laptop might be addressable by pinging "mylaptop.local", for example. mDNS is not necessary if you have some other means of addressing machines by name, such as unicast (regular) DNS. But many LANs do not have their own DNS server configured, in which case mDNS can be very handy.
Receiving mDNS
The ebuild "nss-mdns" provides the necessary functionality for your Funtoo/Gentoo Linux machine to receive mDNS broadcasts, so that it can do things like ping mybox.local, or ssh mylaptop.local.
From the nss-mdns home page:
nss-mdns is a plugin for the GNU Name Service Switch (NSS) functionality of the GNU C Library (glibc) providing host name resolution via Multicast DNS (aka Zeroconf, aka Apple Rendezvous, aka Apple Bonjour), effectively allowing name resolution by common Unix/Linux programs in the ad-hoc mDNS domain .local.
nss-mdns provides client functionality only, which means that you have to run a mDNS responder daemon seperately from nss-mdns if you want to register the local host name via mDNS. I recommend Avahi.
nss-mdns is very lightweight (9 KByte stripped binary .so compiled with -DNDEBUG=1 -Os on i386, gcc 4.0), has no dependencies besides the glibc and requires only minimal configuration.
By default nss-mdns tries to contact a running avahi-daemon for resolving host names and addresses and making use of its superior record cacheing. Optionally nss-mdns can be compiled with a mini mDNS stack that can be used to resolve host names without a local Avahi installation. Both Avahi support and this mini mDNS stack are optional, however at least one of them needs to be enabled. If both are enabled a connection to Avahi is tried first, and if that fails the mini mDNS stack is used.
emerge nss-mdns
Set up multicast route:
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
Note: Adding multicast="yes"
in /etc/conf.d/netif.foo
(replace foo with your actual network interface name) will set up the multicast route automatically at startup.
/etc/nsswitch.conf:
hosts: files mdns_minimal [NOTFOUND=return] dns mdns
Sending Multicast DNS
Avahi-daemon handles the task of sending multicast DNS broadcasts, as well as service discovery broadcasts, on your local LAN. If you want other devices to be able to reach your Funtoo/Gentoo Linux machine via multicast DNS, and Zeroconf Service Discovery, you'll want to enable avahi-daemon. This will also improve the efficiency of performing multicast DNS lookups locally.
rc-update add avahi-daemon default rc
Test:
ninja1 ~ # ping daniel-pc.local PING daniel-pc.local (10.0.1.11) 56(84) bytes of data. 64 bytes from Daniel-PC.local (10.0.1.11): icmp_req=1 ttl=128 time=3.73 ms 64 bytes from Daniel-PC.local (10.0.1.11): icmp_req=2 ttl=128 time=0.905 ms 64 bytes from Daniel-PC.local (10.0.1.11): icmp_req=3 ttl=128 time=0.922 ms 64 bytes from Daniel-PC.local (10.0.1.11): icmp_req=4 ttl=128 time=0.827 ms
Service Discovery
Get a list of services on the LAN:
ninja1 ~ # avahi-browse -ac