hostnames v1.1.7
Hostnames
Say goodbye to manually editing /etc/hosts each time you wish to point hostnames to localhost.
Using hostnames
, you can list, add, enable, disable and remove hostnames using the command line.
Best of all (this is why hostnames
was developed), you can enable hostnames temporality. They will be automatically disabled at SIGINT (when you hit ctrl+c).
Getting started
For demonstration purposes, let’s say your /etc/hosts
file looks like this (the sample):
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
# 127.0.0.1 lickstats.com www.lickstats.com # lickstats-website
# 127.0.0.1 c2montreal.com www.c2montreal.com # c2montreal-website
Let’s introduce some terminology: # IP hostname hostname # label
NOTICE: hostnames
only works with /etc/hosts
entries that have labels.
Installation
npm install hostnames -g
Usage
List hostnames
hostnames list
Example output using sample:
hostnames list
┌─────────┬────────────────────┬─────────────────┬───────────────────────────────────┐
│ Enabled │ Label │ IP │ Hostnames │
├─────────┼────────────────────┼─────────────────┼───────────────────────────────────┤
│ yes │ │ 127.0.0.1 │ localhost │
│ yes │ │ 255.255.255.255 │ broadcasthost │
│ yes │ │ ::1 │ localhost │
│ yes │ │ fe80::1%lo0 │ localhost │
│ no │ lickstats-website │ 127.0.0.1 │ lickstats.com www.lickstats.com │
│ no │ c2montreal-website │ 127.0.0.1 │ c2montreal.com www.c2montreal.com │
└─────────┴────────────────────┴─────────────────┴───────────────────────────────────┘
Add hostname (interactive CLI)
hostnames add
Enable hostname(s)
hostnames enable [labels]
NOTICE: Multiple hostnames can be enabled, disabled or removed simultaneously using comma-separated labels (example: lickstats-website,c2montreal-website
).
Example output using sample:
hostnames enable lickstats-website
┌─────────┬───────────────────┬───────────┬─────────────────────────────────┐
│ Enabled │ Label │ IP │ Hostnames │
├─────────┼───────────────────┼───────────┼─────────────────────────────────┤
│ yes │ lickstats-website │ 127.0.0.1 │ lickstats.com www.lickstats.com │
└─────────┴───────────────────┴───────────┴─────────────────────────────────┘
Enable hostname(s) temporarily
The hostname will be automatically disabled at SIGINT (when you hit ctrl+c).
hostnames enable -t [labels]
hostnames enable -t lickstats-website
┌─────────┬───────────────────┬───────────┬─────────────────────────────────┐
│ Enabled │ Label │ IP │ Hostnames │
├─────────┼───────────────────┼───────────┼─────────────────────────────────┤
│ yes │ lickstats-website │ 127.0.0.1 │ lickstats.com www.lickstats.com │
└─────────┴───────────────────┴───────────┴─────────────────────────────────┘
^C
┌─────────┬───────────────────┬───────────┬─────────────────────────────────┐
│ Enabled │ Label │ IP │ Hostnames │
├─────────┼───────────────────┼───────────┼─────────────────────────────────┤
│ no │ lickstats-website │ 127.0.0.1 │ lickstats.com www.lickstats.com │
└─────────┴───────────────────┴───────────┴─────────────────────────────────┘
Disable hostname(s)
hostnames disable [labels]
Example output using sample:
hostnames disable lickstats-website
┌─────────┬───────────────────┬───────────┬─────────────────────────────────┐
│ Enabled │ Label │ IP │ Hostnames │
├─────────┼───────────────────┼───────────┼─────────────────────────────────┤
│ no │ lickstats-website │ 127.0.0.1 │ lickstats.com www.lickstats.com │
└─────────┴───────────────────┴───────────┴─────────────────────────────────┘
Remove hostname(s)
hostnames remove [labels]
Tired of entering your password when using hostnames
?
WARNING: If you are not confortable using vi
, it might be a good idea to stick with entering your password.
- Open your terminal
- Run
whoami
and press enter (that’s the username you need in step 4) - Run
sudo bash -c 'export EDITOR=vim; visudo'
- Append
username ALL=(ALL) NOPASSWD: /usr/local/lib/node_modules/hostnames/bin/hostnames_commit
at the end of the file - Hit shift+z twice to save and exit
Debug mode
Enable debug mode by setting DEBUG
environment variable to true.
DEBUG=true hostnames
Contributors
Licence
MIT
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago