You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Go to file
Chris Bednarski 400e163b66 Implement -n inside MaybeSaveHostFile 9 years ago
cmd/hostess Change name so it's more clear that it does double duty 9 years ago
.gitignore Fixed gox builds 9 years ago
.travis.yml Added travis ci 9 years ago
LICENSE Initial commit 10 years ago
Makefile Updated readme, now do make && make install 9 years ago
README.md 0/1 failure cases are clever, but inconsistent, so let's not do that. 9 years ago
commands.go Implement -n inside MaybeSaveHostFile 9 years ago
hostfile.go Save will actually write to disk now 9 years ago
hostfile_test.go Add a trailing newline to the test case 9 years ago
hostlist.go Enable and disable return true / false if they did something 9 years ago
hostlist_test.go Expanded tests for remove to test the full API 9 years ago
hostname.go Fixed a sort bug and added some more tests 9 years ago
hostname_test.go Added tests for hostname formatting 9 years ago

README.md

hostess

An idempotent command-line utility for managing your /etc/hosts file.

Using Hostess

Download and Install

Download a precompiled release from GitHub.

Usage

hostess add domain ip   # Add or replace a hosts entry for this domain pointing to this IP
hostess aff domain ip   # Add or replace a hosts entry in an off state
hostess del domain      # (alias rm) Remove a domain from your hosts file
hostess has domain      # exit code 0 if the domain is in your hostfile, 1 otherwise
hostess off domain      # Disable a domain (but don't remove it completely), exit 1 if entry is missing
hostess on domain       # Re-enable a domain that was disabled, exit 1 if entry is missing
hostess list            # (alias ls) List domains, target ips, and on/off status
hostess fix             # Rewrite your hosts file; use -n to dry run
hostess dump            # Dump your hostfile as json
hostess apply           # Add entries from a json file

Flags

-n   # Dry run. Show what will happen but don't do it; output to stdout
-f   # Forcibly rewrite the hostfile, even if there are errors or conflicts
-4   # Limit operation to ipv4 entries
-6   # Limit operation to ipv6 entries

hostess may mangle your hosts file. In general it will probably look like this, with domains pointing at the same IP grouped together and disabled domains commented out.

127.0.0.1 localhost hostname2 hostname3
127.0.1.1 machine.name
# 10.10.20.30 some.host

IPv4 and IPv6

Your hosts file can contain overlapping entries where the same hostname points to both an IPv4 and IPv6 IP. In this case, hostess commands will apply to both entries. Typically you won't have this kind of overlap and the default behavior is OK. However, if you need to be more granular you can use -4 or -6 to limit operations to entries associated with that type of IP.

Disclaimer

hostess uses readme-driven-development and may not actually do any of the things listed above. When in doubt, pass the -n flag to try hostess without changing your system.

Developing Hostess

Configuration

By default, hostess will read / write to /etc/hosts. You can use the HOSTESS_PATH environment variable to provide an alternate path (for testing).

Building from Source

To build from source you'll need to have go 1.4+

Install with go get

go get github.com/cbednarski/hostess/cmd/hostess

Install from source

git clone https://github.com/cbednarski/hostess
cd hostess
make
make install