1

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!

3 Answers 3

21

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?

3
  • 1
    beat me to it ob all three points by 5 seconds. two dns servers are not really necessary for a LAN, though
    – user1686
    Oct 30, 2009 at 14:02
  • 4
    +1 DNS. Use the right tools to solve the problem. Oct 30, 2009 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, 2009 at 19:35
1

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.

1
  • 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. May 6, 2010 at 21:33
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .