Difference between revisions of "Zero Configuration Networking"
(removed unneeded space)
|Line 119:||Line 119:|
Revision as of 19:27, March 4, 2014
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.
Zero Configuration Networking requires the following things to operate:
- A valid IP address, obtained either by:
- Static assignment
- Link-local Addressing (part of Zero Configuration Networking)
- A means to address other devices by name, provided either by:
- multicast DNS (mDNS -- part of Zero Configuration Networking)
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".
In order to get these sort of networking services running, some configuration is required.
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:
root # route add default dev eth0 metric 99 root # 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:
root # /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, 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.
.local Hostname Suffix
If you want to configure your Funtoo Linux system to be addressable on your LAN using a myhostname.local address, first ensure that you set your system's hostname in /etc/conf.d/hostname, and use only the non-qualified name, so don't add a .local yourself. Multicast DNS will automatically use that suffix. Here is a sample /etc/conf.d/hostname for a machine on my network that I can ping from other machines as antec.local:
The package sys-auth/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.
root # emerge -av nss-mdns
Set up multicast route:
root # route add -net 188.8.131.52 netmask 240.0.0.0 dev eth0
/etc/conf.d/netif.foo (replace foo with your actual network interface name) will set up the multicast route automatically at startup.
Now, it's necessary to modify /etc/nsswitch.conf so that your system will use multicast DNS for hostname lookup. In the example, we use the mdns_minimal and mdns words, which enable multicast DNS for IPv4 and IPv6. If you only want to enable IPv4-based multicast DNS, which is recommended for IPv4-only networks, use mdns4_minimal and mdns4 instead. This will improve hostname lookup performance.
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.
root # rc-update add avahi-daemon default root # rc
root # 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
Get a list of services on the LAN:
root # avahi-browse -ac