I have 2 linux server A and B which share common directory. I have to create symbolic link for /etc/hosts file for each server with one common file . when ever I update that common file which is shared by both server they are able to know what changes in file and update /etc/hosts automatically . Is it possible using symbolic link or any other option ?
Instead of having a symlink to a (remote) hosts file, better to update the local copy with the remote one's information. That way in case of network outage, or the "master" host is down, you still have the local /etc/hosts file.
You should, in each local /etc/hosts file, a "structure" to separate local and global informations.
exemple of local /etc/hosts file :
And you could replace the rest of the file (everyuthing after the "# before: local after:global ...." line) with the "global" information, taken either from a remote file dedicated to host the "validated" global information (ex: remotehost:/etc/hosts_global_informations.master) file, or retrieved ONLY from from the "global part" of the master /etc/hosts file (ex: remotehost:/etc/hosts) .
The specific to retrieve those infos are various, depending on what's available to you.
An example: in your shell you could do it manually as such: (this assume that all the /etc/hosts file contains the same separator, which is a line matching the "zesep" regexp:
And then replace /etc/hosts with /etc/newlocalhosts ONCE YOU ARE SURE that the new one is correct (beware: check that the ssh was ok, for example, as it could fail if the network fails!). If it is correct you could:
Using traditional symbolic links, this isn't possible. You're looking for some sort of configuration management software like Puppet or cfengine to push out /etc/hosts when you update it.