A command line tool for managing hosts files.
The tool relies on the hosts file being formatted a particular way to denote its sections. See this example. Sections are indicated via comments like this:
# <work>
0.0.0.0 facebook.com
0.0.0.0 www.facebook.com
# </work>
Sections may be nested inside other sections.
This formatting was inspired by the organization used in the hosts files maintained by Dan Pollock. Hosts files provided on that site should be usable with this script.
hosts is installable via pip.
pip install https://github.com/dhaffner/hosts.git
After that, type hosts -h
to verify that the install completed successfully.
For a full list of options, run:
hosts -h
hosts -i /etc/hosts sections
hosts enable work
Use .
to refer to sections that are nested.
hosts enable work.distractions
hosts disable spam-sites
hosts show ad-sites
hosts backup ~/.hosts/
This command copies a given file to /etc/hosts
, so it must be run with root priveleges.
sudo hosts install ~/.hosts/hosts-1392231273
hosts backup ~/.hosts/
hosts disable work > ~/.hosts/hosts-work
sudo hosts install ~/.hosts/hosts-work
- Add/remove a given mapping (IP, hostname) to a section of hosts file
- Show mappings involving a given IP or hostname
- Optionally install new hosts file after enable/disable/etc action