Skip to content

Independent notes on FreeBSD · published since 1999

The FreeBSD 'zine Features, news and community notes for FreeBSD

Issue 6 · July 2000

Reader written notes on FreeBSD, from the command line to the server room.

Open the current issue

February 1999 · Featured article

/etc/hosts

A How to

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. 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

On the web

Further reading from the FreeBSD community and the projects named in this article.

Issue contents

Issue 2 · Feb 1999

Email

Email with a Dynamic IP Dial up Account

By Oben O. Candemir

Setting up mail on a FreeBSD box can be one of the most challenging parts of configuring a stand alone workstation. If you are like the majority of...

Read the article

Issue 2 · Feb 1999

PGP

Secure your Email

By Oben O. Candemir

Privacy in our modern age has become a thing that requires an expenditure of effort to gain. Everywhere, we are watched, listened to, and monitored....

Read the article

Issue 2 · Feb 1999

Apache

A Virtual Hosting How to

By Jim Mock

This article is somewhat of a continuation of my article in Issue #1 on setting up Apache. Virtual Hosts!?!? What are they? The term Virtual Host...

Read the article