A tool to build and maintain /etc/hosts along-side hosts list sources
Find a file
2014-08-05 13:21:27 -04:00
buildhosts Initial commit with functional behaviour, manpage, README and license 2014-08-05 13:21:27 -04:00
buildhosts.1 Initial commit with functional behaviour, manpage, README and license 2014-08-05 13:21:27 -04:00
LICENSE Initial commit with functional behaviour, manpage, README and license 2014-08-05 13:21:27 -04:00
README.md Initial commit with functional behaviour, manpage, README and license 2014-08-05 13:21:27 -04:00

buildhosts

Build and maintain /etc/hosts while including lists imported from local and remote hosts list sources.

Instructions

Note: All instructions should be performed as the root user, or using the sudo command to run commands with root permissions.

Enable Remote Sources

  1. The first time you run the set command, /etc/hosts will be moved to /etc/hosts.core, and the file /etc/hosts.sources will be created using the default sources list. The /etc/hosts file will then be generated by combining /etc/hosts.core and the resulting contents of the downloaded sources in /etc/hosts.sources.
  2. You can now open /etc/hosts.sources and remove or comment out (by adding # in front) any sources you don't wish to use, as well as add new ones. Sources can remote (ie: http://adaway.org/hosts.txt) as well as local (ie: file:///etc/hosts.d/mylist.txt).
  3. If you want to make any changes to the contents of what used to be /etc/hosts, you should now make them to /etc/hosts.core, and you'll need to rerun the set command to have them applied.
  4. Once you're done customizing your configuration, run the set command again and the /etc/hosts file will be regenerated using the current list of sources and your up-to-date /etc/hosts.core file.

Disable Remote Sources

  1. To disable the configured hosts lists, run the unset command and /etc/hosts.core will be moved back to /etc/hosts.
  2. The /etc/hosts.sources file will continue to exist until it's manually deleted, and it will be used again the next time remote sources are enabled.

Notes on /etc/hosts.sources

  • On each line of /etc/hosts.sources, after # is commented/skipped.
  • Colour output can be disabled by setting the variable NOCOL=1.
  • The $HOSTS_SYSTEM variable can be set to an alternative location to configure a different file to be used for /etc/hosts.
  • Similarly, the $HOSTS_CORE and $HOSTS_SOURCES variables (which default to $HOSTS_SYSTEM.core and $HOSTS_SYSTEM.sources and will automatically change when $HOSTS_SYSTEM is changed), can be set to alternative locations to configure the use of different files.

Commands

  • buildhosts set: generate /etc/hosts using /etc/hosts.core and the configured sources
  • buildhosts unset: remove lists imported from hosts list sources and restore /etc/hosts
  • buildhosts help: display the help

Credits

Written by Kevin MacMartin:

License

Released under the MIT license.