whisk / etchosts

Analyze and merge /etc/hosts files from different servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

etchosts

Build Status

Analyze and merge /etc/hosts files from different servers with ease.

Synopsis

> 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

Usage

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

Samples

Analyze addresses

> 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

Analyze names

> 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

Generate

> 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

TODO

* 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

About

Analyze and merge /etc/hosts files from different servers

License:MIT License


Languages

Language:Ruby 100.0%