Linux name resolution: /etc/hosts

Name resolution means translating a string such as 'gateway.enterprise.net' into an IP address such as 194.72.194.1. If your machine is not connected to the Internet, you only need to know addresses for machines on your local network (if any).

These addresses must be stored in /etc/hosts, which looks like this:

#
# hosts		This file describes a number of hostname-to-address
#		mappings for the TCP/IP subsystem.  It is mostly
#		used at boot time, when no name servers are running.
#		On small systems, this file can be used instead of a
#		"named" name server.  Just add the names, addresses
#		and any aliases to this file...
#
# By the way, Arnt Gulbrandsen  says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1	localhost

# Machines on the local network
193.195.30.7	elsie.lfix.co.uk elsie
193.195.30.1 	linda.lfix.co.uk linda			# This machine
193.195.30.3 	sarah.lfix.co.uk sarah
193.195.30.26	zebulun	 	louise.lfix.co.uk louise

# End of hosts.
 
The format of the file is
IP_number Node_name Alias....
You can have as many aliases as you want.

If you have no other machines, you need only the loopback entry, which is usually called 'localhost'. You can give your machine a name if you like, using another IP number. (If you don't have one assigned to you, use 10.0.0.1, which is reserved for use in private networks.)



Up to Linux PPP page

Last updated on 31st October 1996 by Oliver Elphick