creating /etc/hosts

Pascal J.Bourguignon pjb at
Sun Nov 23 14:29:41 PST 2003

llista writes:
> Hi,
> I'm going to create this file but i have a doubth.
> I'm using an ADSL line with a router configured like if i was a only one 
> net computer  ( in spanish this configuration is called  MULTIPUESTO).
> I mean that i have a gateway with a static IP (that is my router) and my 
> computer have an DCHP assigned IP adresss  (192.168.1.x).
> When i intalled linux , all net configuretion was automatically 
> downloaded by linux itself from the router.
> So.. my question is...  
> Must I create hots file (in net card version) or is there anyelse way to 
> get it from the router...
> Can i follow the kind of configuration that is teached in book or with 
> my configuration, I have to consider some more things...
> Sorry if my english and my net level isn't good enough but i trying to 
> improve.  :)

If the  IP address is  allocated by the  DHCP server (in  the router),
then it can be different each time it's allocated. The D in DHCP means
Dynamical, and that means that it can change.

/etc/hosts,  like DNS,  is  merely  a mean  to  make a  correspondance
between IP addresses and human readable names.

If your  DHCP server allocates  addresses in the range to, then  you can  put names to  these addresses,  but note
that the  name will change  accordingly when the adresse  allocated to
your computer changes.

You could  put the following lines  in the /etc/hosts of  each of your
computers: uno.mi-red dos.mi-red tres.mi-red quatro.mi-red
# etc

then you'll be able to refer them  by name.  But while you keep a DHCP
configuration, the computer  named uno.mi-red can be one  or the other
of your LAN.

What I would do is:

1- check the configuration  of the router.  You may  keep a DHCP range
   for when you want to connect a laptop or "visitor" computer on your
   LAN, but make it smaller than the whole subnet.

2- have a range of your LAN addresses reserved for fixed adresses that
   you'll allocate statically to your computers.

3- either run  a DNS on your  LAN, or copy the same  /etc/hosts on all
   your computers with the mapping name <-> fixed IP you want.

So you may  call each of your resident computers  with fixed names and
fixed addresses  192.168.1.x, and still have  "visitor" computers with
dynamically allocated addresses 192.168.1.y.

Living free in Alaska or in Siberia, a grizzli's life expectancy is 35 years,
but no more than 8 years in captivity. 

More information about the lfs-support mailing list