Analyze and merge /etc/hosts files from different servers with ease.
> etchosts.rb etc_hosts_from_server_A etc_hosts_from_server_A
# Sample /etc/hosts compiled from 2 files by etchosts.rb
# real
213.180.193.3 node-1
81.177.123.98 node-2 node-2.example.com
# private
192.168.0.1 master-1 # WARN: multiple addresses
192.168.0.2 master-1
etchosts.rb is designed to analyze and merge /etc/hosts files obtained from different servers. If you got stuck in situation when there are conflicting or obsolete address hostname
mappings in /etc/hosts across your network, etchosts.rb is the right tool.
What to do:
- copy /etc/hosts from your servers
- run etchosts.rb: ./etchosts.rb hostfile1 hostfile2 ...
- use output to resolve conflicts manually and create a single hosts file what fits all your servers
It is recommended to start using DNS to avoid such issues.
For manipulations on a single /etc/hosts file see: https://github.com/bjeanes/ghost or https://github.com/aef/hosts
> etchosts.rb -a addr etc_hosts_from_server_A etc_hosts_from_server_A
xxx.xxx.xxx.xxx found on all hosts. Entry: office
xxx.xxx.xxx.xxx found on all hosts. Multiple entries: v-1-1, cnv-v-1-1
xxx.xxx.xxx.xxx found on 1 host: hosts1. Multiple entries: bl, bl1
> etchosts.rb -a names etc_hosts_from_server_A etc_hosts_from_server_A
office found on all hosts. Entry: xxx.xxx.xxx.xxx
cnv-v-1-1 found on all hosts. Entry: xxx.xxx.xxx.xxx
v-1-1 found on all hosts. Entry: xxx.xxx.xxx.xxx
bl1 found on 1 host. Multiple entries: xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx
> etchosts.rb -a gen etc_hosts_from_server_A etc_hosts_from_server_A
# loopback interfaces skipped
# ipv6 skipped
# real
xxx.xxx.xxx.xxx office
xxx.xxx.xxx.xxx v-1-1 cnv-v-1-1
# private
192.168.1.1 bl1
192.168.1.2 bl1
* more informative warnings
* tests!
* option: skip conflicts
* option: same name with private and real addr are not conflicted
* option: sort sample /etc/hosts by hostnames (first hostname)
* option: only beautify, no analyze