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 187298f216 Change format switch from 'linux' to 'unix' to match the readme 4 years ago
hostess Change format switch from 'linux' to 'unix' to match the readme 4 years ago
testdata Added test for issue #39 4 years ago
.appveyor.yml Add appveyor config, changelog, README TLC, and update TravisCI Go to 1.14 4 years ago
.gitignore Ignore .DS_Store files 4 years ago
.travis.yml Minor update on travis config 4 years ago
CHANGELOG.md Added changes to the changelog 4 years ago
LICENSE Added contributor section 4 years ago
Makefile Fix argument parsing for CLI 4 years ago
README.md Removed -4 and -6 from CLI (these are still usable in the lib) 4 years ago
commands.go Update to fmt -n (preview) behavior 4 years ago
commands_test.go Update to fmt -n (preview) behavior 4 years ago
go.mod Started major refactor for 0.5.0 4 years ago
main.go Fix panic when hostess is called with no arguments 4 years ago
main_test.go Fix panic when hostess is called with no arguments 4 years ago

README.md

hostess Linux Build Status Windows Build Status GoDoc

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

hostess add local.example.com 127.0.0.1
hostess add staging.example.com 10.0.2.16

Why? Because you edit /etc/hosts for development, testing, and debugging. Because sometimes DNS doesn't work in production. And because editing /etc/hosts by hand is a pain. Put hostess in your Makefile or deploy scripts and call it a day.

* And C:\Windows\System32\drivers\etc\hosts on Windows.

Note: 0.4.0 has backwards incompatible changes in the API and CLI. See CHANGELOG.md for details.

Installation

Download a precompiled release from GitHub, or build from source (with a recent version of Go):

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

Usage

Run hostess or hostess -h to see a full list of commands.

Note The hosts file is protected. On unixes you will need to use sudo or run the hostess command as root. On Windows, you will need to run hostess from an elevated prompt (right click and Run as administrator).

Format

On unixes, hostess follows the format specified by man hosts, with one line per IP address:

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

On Windows, hostess writes each hostname on its own line.

127.0.0.1 localhost
127.0.0.1 hostname2
127.0.0.1 hostname3

Configuration

hostess may be configured via environment variables.

  • HOSTESS_FMT may be set to windows or unix to override platform detection for the hosts file format. See Behavior, above, for details

  • HOSTESS_PATH may be set to override platform detection for the location of the hosts file. By default this is C:\Windows\System32\drivers\etc\hosts on Windows and /etc/hosts everywhere else.

IPv4 and IPv6

It's possible for your hosts file to include overlapping entries for IPv4 and IPv6. This is an uncommon case so the CLI ignores this distinction. The hostess library includes logic that differentiates between these cases.

Contributing

I hope my software is useful, readable, fun to use, and helps you learn something new. I maintain this software in my spare time. I rarely merge PRs because I am both lazy and a snob. Bug reports, fixes, questions, and comments are welcome but expect a delayed response. No refunds. 👻