## Setting up the /etc/hosts file ## Robert 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. 127.0.0.1 localhost.freebsdzine.org localhost There it leaves us. While this particular line is correct it neglects to add the very much needed second line: 127.0.0.1 localhost.freebsdzine.org. Now, everybody likes to call their computer something other than localhost, so they give it a name. Well 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: 172.16.0.1 mycomputer.freebsdzine.org mycomputer 172.16.0.1 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: 127.0.0.1 mycomputer.freebsdzine.org mycomputer 127.0.0.1 mycomputer.freebsdzine.org. Then we need to add any other machines on the local network: 172.16.0.2 hiscomputer.freebsdzine.org hiscomputer 172.16.0.2 hiscomputer.freebsdzine.org. They say an example is worth a thousand words so here we go: 127.0.0.1 localhost.freebsdzine.org localhost 127.0.0.1 localhost.freebsdzine.org. 127.0.0.1 me.freebsdzine.org me 127.0.0.1 me.freebsdzine.org. 172.16.0.1 mycomputer.freebsdzine.org mycomputer 172.16.0.1 mycomputer.freebsdzine.org. 172.16.0.2 hiscomputer.freebsdzine.org hiscomputer 172.16.0.2 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 hosts # If that doesn't work, then try the /etc/hosts file bind # 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 $Id: hosts.txt,v 1.1 2000/02/16 08:07:42 jim Exp $