These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX02/The Hosts File

Classnotes | UNIX02 | RecentChanges | Preferences

DNS (Domain Name Service) is the standard means by which host names get resolved into IP addresses, however, you will want at least some simple host name resolution without going through a DNS server. Your Linux system may need a simple host name resolution for start up scripts, or you may want to have a more quick lookup for certain hosts, or you may even want to redirect certain host names to other hosts. This is where the /etc/hosts file comes in.

Your hosts file is a white-space separated configuration file with three columns. The first column contains the IP, the second column contains the fully qualified domain name, and the third column contains the optional aliases.

By default, you should have at least the following in your hosts file (this is the default Red Hat hosts file):

 # Do not remove the following line, or various programs
 # that require network functionality will fail.               localhost.localdomain localhost

If you will recall, this is the looback interface that was mentionned earlier.

You may have a more complicated network, then you would have other entries in the hosts file as well. Here is an example from a ficticious Brewery company:

 # Hosts file for Virtual Brewery/Virtual Winery
 # IP            FQDN                 aliases
 #       localhost
 #      vlager vlager-if1      vstout        vale
 #      vlager-if2 vbeaujolais  vbardolino    vchianti

  • DID YOU KNOW: Microsoft actually has a UNIX networking layer inside their Windows operating systems? It was originally lifted from a BSD code base. Because of this, Microsoft Windows operating systems do have an /etc/hosts file which can be configured in the exact same way as was described here. Under Windows 95/98/Me, the file can be found here: c:\windows\hosts. Under Windows NT/2000/XP, the file can be found here: c:\winnt\system32\drivers\etc\hosts.

  • /etc/hosts is a very useful file for a number of interesting problems. In addition to providing quick lookups for specific hosts, you can use to to prevent specific hosts from resolving correctly on your host machine. Why would you want to do that? Well one use would be to point a large number of web advertisement company domain names to your local host. By doing this, you've effectively blocked those pesky web advertisements! Here is a web-site with more details:

Classnotes | UNIX02 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited April 25, 2003 11:36 pm (diff)
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.