[NTLUG:Discuss] Hosts using DHCP

Jack Snodgrass jack+ntlug at mylinuxguy.net
Wed Feb 26 15:14:59 CST 2003


On Wed, 2003-02-26 at 14:32, Wayne Dahl wrote:
> I've found at least part of the Samba issue.  There were no entries in
> my /etc/hosts or /etc/hosts.allow files.  All the documentation I've
> found so far about putting entries in there deal with static IP's
> because you assign an IP to a specific host in the file.  What I have
> not found is how this works when the hosts get their IP's via DHCP from
> the router.  Since the IP's are subject to change every time the
> machines are rebooted, the entries in the file could be invalid.  I have
> not found any documentation anywhere so far explaining how to get around
> this, short of assigning static IP's.  So, the question is, how does the
> hosts file work on a network where DHCP is running?
> 
> Wayne


I'm not sure what your doing or what problems your having, etc. 
As far as /etc/hosts, /etc/hosts.allow, /etc/hosts.deny, DHCP, etc
go.... Here is what I know...


/etc/hosts.allow and /etc/hosts.deny are used by TCPWrappers to 
control who can access your box. ( Not all things use this. Not
all things that can use this are enabled to do so. i.e. you 
can compile MySQL to use tcp_wrapers or to not. It's not a 'set
in stone' thing. ) 


/etc/hosts.allow and /etc/hosts.deny have 0 ( ZERO ) to do with 
the /etc/hosts file. 


The /etc/hosts file is one of the things that is used to resolve 
names to ip addresses. The /etc/hosts file is searched BEFORE 
doing a dns query.

The /etc/hosts file is ( generally ) local to the server it 
is on. If you have multiple machines on your network and 
you have a set of private addresses, you'd have to copy the 
same /etc/hosts file to each machine on the network. Each time
you made an update, if you wanted all of the machines to know
about it, you'd have to copy the updated /etc/hosts file to 
each machine. The /etc/hosts file isn't meant to be used to 
resolve a lot of names. 

There is a program called pdnsd that is pretty slick. It 
lets you use your /etc/hosts file and use that as a dns server
table. You run pdnsd as a dns server. If the entry isn't in 
your /etc/hosts file, the request is forwarded to a 'real' 
dns server that you specify. 


When you do a ping some-name, it looks to see if some-name is
in the /etc/hosts file and if it is, it use's some-name's ip 
address. If it's not, the system will do a dns query and try
and resolve the name. ( the dns servers are listed in the 
/etc/resolv.conf file ) 

Now... as far as DHCP goes, DHCP assigns an IP Address to 
a machine that requests it. When you want to access a server
by it's DHCP name, it either needs to be listed in the 
/etc/hosts file or be accessible via a dns query. If it's not 
in the /etc/hosts file and a dns won't resolve it, then you 
can only access it by it's IP Address. 

If you are running a DHCP server and not running a DNS server, 
you can put all of your IP Addresses and DHCP names in your 
/etc/hosts file. You'd have to copy that /etc/hosts file to
all machines in your network if you want all of the machines
to be able to resolve the addresses. 

Note... you can also use DHCP to assign 'static' ip addresses. 
Both of my TiVo boxes use DHCP to get their IP Addresses. I
want then to always have the same IP Addresses so I set up
the DHCP server to give them the same address each time ( based
on their MAC Address )


Hope some of that helped. 

jack








More information about the Discuss mailing list