1.1.7 • Published 4 years ago

hostnames v1.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

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.

  1. Open your terminal
  2. Run whoami and press enter (that’s the username you need in step 4)
  3. Run sudo bash -c 'export EDITOR=vim; visudo'
  4. Append username ALL=(ALL) NOPASSWD: /usr/local/lib/node_modules/hostnames/bin/hostnames_commit at the end of the file
  5. Hit shift+z twice to save and exit

Debug mode

Enable debug mode by setting DEBUG environment variable to true.

DEBUG=true hostnames

Contributors

Sun Knudsen

Licence

MIT

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

6 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago