Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

On my lan, all my etc/hosts are identical, except of course the first lines

 127.0.0.1 localhost.localdomain localhost
 192.168.0.1 thismachine.thisdomain thismachine

Is there a simple way (I'm not speaking about DNS) to share the rest of the file, so adding a machine or changing an IP wouldn't be a big deal?

Thx!

share|improve this question

3 Answers 3

up vote 21 down vote accepted

You really would be better off setting up a pair of nameservers if you can. I've never really seen a situation where you couldn't replace a cumbersome hosts file situation with a couple of DNS servers (Really, they are easy to setup and run).

However, to answer your question, you can use something like either puppet or cfengine to keep these in sync.

Another question though... I'm not sure why the first few lines need to change?

127.0.0.1 always points to the local machine and would always be localhost.localdomain localhost

The private IP of the machine will be the same hostname on the machine as it is on every other machine?

share|improve this answer
    
beat me to it ob all three points by 5 seconds. two dns servers are not really necessary for a LAN, though –  hop Oct 30 '09 at 14:02
3  
+1 DNS. Use the right tools to solve the problem. –  David Mackintosh Oct 30 '09 at 14:03
    
Had this setup in my job for the first few months. Was blamed on the dns not working across the vpn connection. Whoever set it up didn't think specifying the dns servers were necessary for vpn connections :) –  Ryaner Oct 30 '09 at 19:35

I use puppet to solve this problem. DNS is great, but you either need to set up redundant servers to avoid a central point of failure, or you can just add entries to a hosts file (or both). DNS also has the problem of network latency, which may or may not be important in your situation.

share|improve this answer
    
Puppet is definitely a good tool, if the OP sticks to a hosts file. I think the need for DNS redundancy depends a lot on the size of your LAN though. SMB's can definitely get away with running a single BIND server, if they have proper monitoring in place. –  Martijn Heemels May 6 '10 at 21:33

Use the following script after copying /etc/hosts from the master server:

sudo sed -i "s/127.0.0.1 localhost host1.lan/127.0.0.1 localhost host2.lan/" /etc/hosts
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.