2015-05-21 03:31:05 +00:00
__ __
/ /_ ____ _____ / /______
/ __ \/ __ \/ ___/ __ / ___/
/ / / / /_/ (__ ) /_(__ )
/_/ /_/\____/____/\__/____/
2015-03-17 00:05:46 +00:00
# Hosts
2019-01-01 01:47:32 +00:00
`hosts` is a command line program for managing [hosts file ](https://en.m.wikipedia.org/wiki/Hosts_\(file\ )) entries.
2018-08-14 17:48:55 +00:00
2018-08-14 18:24:51 +00:00
`hosts` works with existing hosts files and entries, making it easier to add, remove, comment, and search hosts file entries using simple, memorable commands.
2015-03-17 00:05:46 +00:00
2015-03-19 01:35:45 +00:00
## Installation
### Homebrew
2015-05-20 23:44:24 +00:00
To install with [Homebrew ](http://brew.sh/ ):
2015-03-19 01:35:45 +00:00
2015-11-25 00:15:45 +00:00
```bash
brew tap alphabetum/taps & & brew install alphabetum/taps/hosts
```
2015-03-19 01:35:45 +00:00
2015-05-20 23:44:24 +00:00
### bpkg
To install with [bpkg ](http://www.bpkg.io/ ):
2015-11-25 00:15:45 +00:00
```bash
bpkg install alphabetum/hosts
```
2015-05-20 23:44:24 +00:00
### Manual
To install manually, simply add the `hosts` script to your `$PATH` . If
you already have a `~/bin` directory, you can use the following command:
2015-11-25 00:15:45 +00:00
```bash
curl -L https://raw.github.com/alphabetum/hosts/master/hosts \
-o ~/bin/hosts & & chmod +x ~/bin/hosts
```
2015-05-20 23:44:24 +00:00
2018-05-15 17:06:02 +00:00
A package for Arch users is also [available in the AUR ](https://aur.archlinux.org/packages/hosts/ ).
2015-03-17 00:05:46 +00:00
## Usage
2015-11-25 00:15:45 +00:00
```text
Usage:
2017-03-02 04:18:26 +00:00
hosts [< search string > ]
2016-01-27 04:25:16 +00:00
hosts add < ip > < hostname > [< comment > ]
2017-03-01 21:43:10 +00:00
hosts block < hostname >
2016-01-27 04:25:16 +00:00
hosts disable (< ip > | < hostname > | < search string > )
2015-11-25 00:15:45 +00:00
hosts disabled
2016-01-16 00:52:41 +00:00
hosts edit
2016-01-27 04:25:16 +00:00
hosts enable (< ip > | < hostname > | < search string > )
2015-11-25 00:15:45 +00:00
hosts enabled
hosts file
2016-01-16 00:52:41 +00:00
hosts list [enabled | disabled | < search string > ]
2017-03-01 20:46:27 +00:00
hosts search < search string >
2017-03-01 21:45:19 +00:00
hosts show (< ip > | < hostname > | < search string > )
2016-01-27 04:25:16 +00:00
hosts remove (< ip > | < hostname > | < search string > ) [--force]
2017-03-01 21:43:10 +00:00
hosts unblock < hostname >
2017-03-02 00:00:08 +00:00
hosts --auto-sudo
hosts -h | --help
hosts --version
Options:
--auto-sudo Run write commands with `sudo` automatically.
-h --help Display this help information.
--version Display version information.
Help:
hosts help [< command > ]
2015-11-25 00:15:45 +00:00
```
2015-03-17 00:19:17 +00:00
2015-03-17 03:13:19 +00:00
For full usage, run:
2015-11-25 00:15:45 +00:00
```text
hosts help
```
2015-03-17 03:13:19 +00:00
2015-03-19 01:23:59 +00:00
For help with a particular command, try:
2015-03-17 03:13:19 +00:00
2015-11-25 00:15:45 +00:00
```text
hosts help < command name >
```
2015-03-17 03:13:19 +00:00
2015-03-19 21:43:32 +00:00
## Commands
2017-04-06 17:48:04 +00:00
### `hosts`
2017-03-02 04:18:26 +00:00
```text
Usage:
hosts [< search string > ]
Description:
List the existing IP / hostname pairs, optionally limited to a specified
state. When provided with a seach string, all matching enabled records will
be printed.
Alias for `hosts list`
```
2017-04-06 17:48:04 +00:00
### `hosts add`
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
```text
Usage:
hosts add < ip > < hostname > [< comment > ]
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
Description:
Add a given IP address and hostname pair, along with an optional comment.
```
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
### `hosts block`
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
```text
Usage:
hosts block < hostname >
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
Description:
Block a given hostname by adding new entries assigning it to `127.0.0.1`
for IPv4 and both `fe80::1%lo0` and `::1` for IPv6.
```
2015-03-19 21:43:32 +00:00
2017-12-31 17:02:09 +00:00
#### Blocklists
- [jmdugan/blocklists ](https://github.com/jmdugan/blocklists )
- [notracking/hosts-blocklists ](https://github.com/notracking/hosts-blocklists )
2017-03-01 22:02:17 +00:00
### `hosts commands`
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
```text
Usage:
hosts commands [--raw]
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
Options:
--raw Display the command list without formatting.
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
Description:
Display the list of available commands.
```
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
### `hosts disable`
2015-03-20 23:44:43 +00:00
2017-03-01 22:02:17 +00:00
```text
Usage:
hosts disable (< ip > | < hostname > | < search string > )
2015-03-20 23:44:43 +00:00
2017-03-01 22:02:17 +00:00
Description:
Disable one or more records based on a given ip address, hostname, or
search string.
```
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
### `hosts disabled`
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
```text
Usage:
hosts disabled
2015-03-20 23:44:43 +00:00
2017-03-01 22:02:17 +00:00
Description:
List all disabled records. This is an alias for `hosts list disabled` .
```
2015-03-20 23:44:43 +00:00
2017-03-01 22:02:17 +00:00
### `hosts edit`
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
```text
Usage:
hosts edit
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
Description:
Open the /etc/hosts file in your $EDITOR.
```
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
### `hosts enable`
2015-03-19 21:43:32 +00:00
2017-03-01 22:02:17 +00:00
```text
Usage:
hosts enable (< ip > | < hostname > | < search string > )
2017-03-01 20:46:27 +00:00
2017-03-01 22:02:17 +00:00
Description:
Enable one or more disabled records based on a given ip address, hostname,
or search string.
```
2017-03-01 20:46:27 +00:00
2017-03-01 22:02:17 +00:00
### `hosts enabled`
2017-03-01 21:43:10 +00:00
2017-03-01 22:02:17 +00:00
```text
Usage:
hosts enabled
2017-03-01 21:43:10 +00:00
2017-03-01 22:02:17 +00:00
Description:
List all enabled records. This is an alias for `hosts list enabled` .
```
2017-03-01 21:43:10 +00:00
2017-03-01 22:02:17 +00:00
### `hosts file`
```text
Usage:
hosts file
Description:
Print the entire contents of the /etc/hosts file.
```
### `hosts help`
```text
Usage:
hosts help [< command > ]
Description:
Display help information for hosts or a specified command.
```
### `hosts list`
```text
Usage:
hosts list [enabled | disabled | < search string > ]
Description:
List the existing IP / hostname pairs, optionally limited to a specified
state. When provided with a seach string, all matching enabled records will
be printed.
```
### `hosts remove`
```text
Usage:
hosts remove (< ip > | < hostname > | < search string > ) [--force]
hosts remove < ip > < hostname >
Options:
--force Skip the confirmation prompt.
Description:
Remove one or more records based on a given IP address, hostname, or search
string. If an IP and hostname are both provided, only records matching the
IP and hostname pair will be removed.
```
### `hosts search`
```text
Usage:
hosts search < search string >
Description:
Search entries for < search string > .
```
### `hosts show`
```text
Usage:
hosts show (< ip > | < hostname > | < search string > )
Description:
Print entries matching a given IP address, hostname, or search string.
```
### `hosts unblock`
```text
Usage:
hosts unblock < hostname >
Description:
Unblock a given hostname by removing its entries from the hosts file.
```
### `hosts version`
```text
Usage:
hosts (version | --version)
Description:
Display the current program version.
```
2017-03-01 21:43:10 +00:00
2017-03-02 00:00:08 +00:00
## Options
### `--auto-sudo`
When specified, all write operations that require `sudo` will automatically
2017-03-02 00:26:58 +00:00
rerun the command using `sudo` when the current user does not have write
permissions for the hosts file.
2017-03-02 00:00:08 +00:00
To have this option always enabled, add the following line to your shell
configuration (`.bashrc`, `.zshrc` , or similar):
```bash
alias hosts="hosts --auto-sudo"
```
### `-h` `--help`
Display help information.
### `--version`
Display version information.
2017-03-01 20:15:16 +00:00
## Tests
To run the test suite, install [Bats ](https://github.com/sstephenson/bats ) and
run `bats test` in the project root directory.
2015-03-17 00:19:17 +00:00
## Acknowledgements
2017-03-02 00:21:18 +00:00
- https://gist.github.com/nddrylliog/1368532
- https://gist.github.com/dfeyer/1369760
- https://github.com/macmade/host-manager
2017-12-31 17:02:09 +00:00