Skip to content
/ 127 Public

127 is a tool for mapping hostnames to random loopback addresses

License

Notifications You must be signed in to change notification settings

lende/127

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

127

127 is a tool for mapping easy-to-remember hostnames to random loopback addresses.

The tool reads and modifies the standard hosts file on your system. There is also a Go API available. Tested on Linux, but may work on other Unix-like systems.

Installation

To install the latest version from source:

git clone https://github.com/lende/127.git
cd 127; make && sudo make install

You may also download a binary release.

Usage and options

$ 127 -h
127 is a tool for mapping hostnames to random loopback addresses.

Usage: 127 [option ...] [hostname]
Print IP mapped to hostname, assigning a random IP if no mapping exists.

Options:
  -e    echo hostname
  -f string
        path to hosts file (default "/etc/hosts")
  -u    unmap hostname
  -v    print version

Examples

A simple demonstration

# Map example.test to a random loopback address:
$ sudo 127 example.test
127.2.221.30

# Running the command again simply returns the same IP address:
$ 127 example.test
127.2.221.30

# Ping the new host to check that it worked:
$ ping example.test
PING example.test (127.2.221.30) 56(84) bytes of data.
64 bytes from example.test (127.2.221.30): icmp_seq=1 ttl=64 time=0.042 ms

# Delete the mapping by specifying the -d flag:
$ 127 -u example.test
127.2.221.30
$ ping example.test
ping: example.test: Name or service not known

# Running the command without any arguments simply returns a random IP:
$ 127
127.167.166.218

Testing a third party service

Let's say you want to try out ownCloud. Simply run:

sudo docker run --rm -p `sudo 127 owncloud.test`:80:80 owncloud:latest

... and your ownCloud instance should be available at http:https://owncloud.test.