[ Current Issue Home | Issue #2 Home | FAQ ]��

The FreeBSD 'zine
Featured Articles: /etc/hosts
## A How-to
## Rob Garrett <>

This is one of the more common stumbling blocks for new users. While the FreeBSD installation generally does a fairly good job of configuring things for you it still leaves a few things that need to be tweaked a little to make your system run a bit more smoothly. The first time I came across this problem was using cvsup. I kept getting this strange message about not being able to get my own hostname, then a little later I tried to setup fetchmail, and it gave me an error gethostbyname failed.. so began my journey into the hosts file.

The man page for hosts doesn't help a whole lot, and the format it specifies isn't what sysinstall generates for ethernet cards, but for some reason when generating the localhost line it does follow the man page. The line it creates looks like this.	localhost.freebsdzine.org localhost

There it leaves us. While this particular line is correct it neglects to add the very much needed second line:	localhost.freebsdzine.org.

Now, everybody likes to call their computer something other than localhost, so they give it a name. Guess what? We need more lines for that. However, if we have a Network Interface Card we will assign the IP that we gave it to our name:	mycomputer.freebsdzine.org mycomputer	mycomputer.freebsdzine.org.

Sysinstall generally creates both of those for you when you configure a network card, but what if we don't have a network card? We can always do something like this:	mycomputer.freebsdzine.org mycomputer	mycomputer.freebsdzine.org.

Then we need to add any other machines on the local network:	hiscomputer.freebsdzine.org hiscomputer	hiscomputer.freebsdzine.org.

They say an example is worth a thousand words so here we go:	localhost.freebsdzine.org	localhost	localhost.freebsdzine.org.	me.freebsdzine.org		me	me.freebsdzine.org.	mycomputer.freebsdzine.org	mycomputer	mycomputer.freebsdzine.org.	hiscomputer.freebsdzine.org	hiscomputer	hiscomputer.freebsdzine.org.

After editing our hosts file, we can then go edit /etc/host.conf. We want to check the hosts file before we try named, so we want to have hosts before bind like so:

	# Default is to use the nameserver first
	# If that doesn't work, then try the /etc/hosts file
	# If you have YP/NIS configured, uncomment the next line
	# nis

That's pretty much all there is to it. I hope this clears up any questions you may've had about the hosts file.

- Rob

Return to Issue #2

Contact: <>
Last modified: $Date: 1999/06/26 05:24:30 $
Copyright � 2023, The FreeBSD 'zine
All rights reserved.