Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On my lan, all my etc/hosts are identical, except of course the first lines localhost.localdomain localhost 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?


share|improve this question
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? 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
+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/ localhost host1.lan/ localhost host2.lan/" /etc/hosts
share|improve this answer

Your Answer


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.