[techtalk] localhost, etc.

Samantha Jo Moore sjmoore at TheTahoeGroup.com
Sat Oct 16 22:03:52 EST 1999


OK, quick tutorial on /etc/hosts and localhost...

/etc/hosts

Now a days, connectivity is a big issue.  Computers aren't worth a dime
if they can't connect to one another.  Connectivity protocols are varied
but the most reliable, and the one the internet is based on is TCP/IP 
(Transfer Control Protocol/Internet Protocol).  Under this protocol every
computer in the network (the internet, or your local area network) must
be identified with a unique number which is called an "IP address".  These
numbers are hard to remember, so it is our human nature to refer to computers
by names instead of numbers.  Well, some translation has to occur between the
human prefered names and the computer needed IP addresses.  One of the ways
to do this translation (because there are many) is the use of the /etc/hosts
file.

The /etc/hosts file is like a dictionary of host names and IP addresses.  
This file is local to every host.  That means that if you have a network with 
10 computers, each one must have a copy of the /etc/hosts file.  The 
maintenance and synchronization of such files can be a daunting task, and 
evem worse when the network grows larger.

To relieve such maintenance nightmare a supplemental system to name computers
was created and it is are called DNS (Domain Name System).  So... when a 
computer looks for a name in /etc/hosts and it doesn't find it, it consults
DNS to find the IP address that corresponds to that name.  It is beyond the
scope of this writeup to describe DNS, so I wont.


localhost

Before networking was available for unix the /etc/hosts file was not needed.
As new software was developed which REQUIRED certain networking features, like
X-Windows, and others, a computer needed to identify itself to itself.  The way
to resolve this was to have a standard name "localhost" be the way to identify
the local computer to itself.  Also as a standard the IP address that was 
designated for this local computer is 127.0.0.1.  

Now, why is this necessary?  Lets use the example of X-windows.  The way this
GUI mechanism works in Linux/unix is as follows:  A program called the "X server"
takes control of the display.  Nothing can be displayed there by any other
program except the X server.  For other programs to display stuff in a window, 
they have to open a TCP/IP connection to the X server and send it the stuff to
be displayed.  If the program is running on the same computer as the X server,
it finds the X server by searching /etc/hosts for the "localhost".

In your case, where you installed MySQL, it seems that the admin tool talks
to the database server via a TCP/IP connection.  Since both are running on 
the same host, guess what is the name the admin tool uses to find the IP 
address of the host where the database server runs on?  Yes, "localhost".

Hope this helps.

Samantha Jo Moore
CTO - The Tahoe Group, Inc.
http://www.thetahoegroup.com
sjmoore at thetahoegroup.com


************
techtalk at linuxchix.org   http://www.linuxchix.org




More information about the Techtalk mailing list