Hosts

From Applepedia

Jump to: navigation, search

/etc/hosts is a flat file that "contains information regarding the known hosts on the network." This file is often used to avoid having to set up dns names for local network address, or to override dns info for whatever reason.

From the manual:

For each host a single line should be present with the following information:
	Internet address
	Official host name
	Aliases

Your host file looks like this by default:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost 

You can add a line that looks like this:

192.168.0.5 	fileserver.example.com	damnimcool.local

and you can enter fileserver.example.com or damnimcool.local to get to the address 192.168.0.5. Note: this does not mean you can use these on any other computer, these are local to the system.

lookupd

There is a hidden gotcha with the /etc/hosts file, in that the daemon that serves hosts info (and many other things) may not look to it first. However it is easy to fix, there is a system of flat files to configure lookupd in /etc/lookupd/
If /etc/lookupd does not exist create it:

cd /etc
sudo mkdir lookupd

Then create a file called hosts there:

cd /etc/lookupd
sudo echo LookupOrder FFAgent CacheAgent NIAgent DNSAgent DSAgent > hosts

That line is pretty self explanatory: FF is flat file, for info on the others see man lookupd. You can put cache first and it will work fine, but if you are trying to override a dns name, the cache will hold it until the ttl expires, so it can be confusing. Flat files are very efficient, unless you are doing many hits a second, dont worry about it.
Finally you have to restart lookupd:

sudo killall -HUP lookupd
Personal tools