A tool to build and maintain /etc/hosts along-side hosts list sources
Find a file
2014-08-17 23:18:44 -04:00
buildhosts Change set/unset to build/revert and improve output 2014-08-17 23:18:44 -04:00
buildhosts.1 Change set/unset to build/revert and improve output 2014-08-17 23:18:44 -04:00
LICENSE Initial commit with functional behaviour, manpage, README and license 2014-08-05 13:21:27 -04:00
p2p-to-hosts Shortened help and added p2p to hosts conversion script 2014-08-08 11:39:38 -04:00
README.md Change set/unset to build/revert and improve output 2014-08-17 23:18:44 -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.

Enable Remote Sources

  1. The first time you run the build 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 build command to have them applied.
  4. Once you're done customizing your configuration, run the build 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 revert command and /etc/hosts.core will be moved back to /etc/hosts.
  • 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 build: generate /etc/hosts using /etc/hosts.core and the configured sources
  • buildhosts revert: remove lists imported from hosts list sources and restore /etc/hosts
  • buildhosts help: display the help

Extra

  • The p2p-to-hosts script included in this repo can be used to convert blocklists in p2p format to hosts format (usable with this package).

Credits

Written by Kevin MacMartin:

License

Released under the MIT license.