Avahi and DNS
I was playing around with Avahi and DNS and decided that since it was so much fun, I should share my experience.
I already had Avahi set up. Avahi is a Zeroconf (aka Bonjour, Rendezvous) implentiation. Zeroconf allows you to find services on a network. Previously I just used Avahi for finding iTunes shares (with Rhythmbox) and publishing my services (ssh, http, ipp, rsync, etc.).
Previously I noticed, with
avahi-discover, that my workstation was published (because public-workstation is enabled by default). I had no idea how to use it though. Looking through Planet GStreamer for the first time I found a post describing how to use this other tid-bit of information.
Getting Automatic Local Hostnames
Up to this point, I had been setting hostnames in
/etc/hosts for computers on my network. My network maintains fairly stable IPs, so this was not a big issue. But with Avahi, this can be automatic! I
emerged nss-mdns and added mdns (most people probably want mdns4 instead) to
/etc/nsswitch.conf the hosts line (now looks like "hosts: files dns mdns").
DNS Caching and Local Domain Setting
At this point, I could go to my machine via mastermind.local, and the ersoft server via wife.local. As I removed wife and mastermind from my hosts file, I realized that dns lookups were much slower when gotten from avahi. Comcast's DNS servers are unbearably slow, so I figured this would be a good time to set up a DNS cache.
I found a post for DNS caching for Ubuntu. Since I already had dnsmasq, I uncommented the listen-address line in
/etc/dnsmasq.conf and set it equal to 127.0.0.1 ("listen-address=127.0.0.1"). Then I ran
rc-update add dnsmasq default and
To configure your system to use this cache you need to modify
/etc/dhcp/dhclient.conf. It is very possible that you are missing this file. If you are, just
The file is the same place that you can set your default domain name. Setting the domain name allows you to connect to a host via
hostname as opposed to
hostname.domainname. In my case, without the default domain name set, I would have to connect to
mastermind.local to get to my laptop. For most people, their domain name would be local as well. I my dhclient.conf now looks like:
prepend domain-name-servers 127.0.0.1; supersede domain-name local;
If you were previously using dhcpcd in Gentoo, you will want to change
/etc/conf.d/net to use dhclient. You can achieve this by:
modules=( "dhclient" )
You will need to restart your network device before it will be using the new configuration. If you want to test to see if everything is working,
dig is a useful command. It is part of
bind-tools. Give dig the argument of the host you want to lookup. It will give you a lot of good DNS information, including "Query time." The query time from the cache should be 0-1 milliseconds.