I don't know about you, but I'm forever editing my local hosts file, when developing apps and sites. Hopefully, you already know that you can create your own custom, virtual domains, that can point to any IP address.
So for example, I've started building a new site and want to be able to access my local copy of the site via a domain, rather than local IP or via localhost. So all I gotta do is open up the one true text editor and edit my /etc/hosts file. The location of this file will vary depending on your OS, but on a Mac, /etc/hosts is where you will find it.
The contents of the file should look something like this:
##
# 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
Usually I would add a new line at the bottom of this file, with my domain and the IP I want to point it to:
127.0.0.1 myfunkydomain.dev
The domain can be absolutely anything you want, as long as it is a valid domain format. I usually end mine with .dev, so I know I use for development.
Enter the Ghost!
I found an even easier and funkier way to add and edit my local hosts. Ghost is a Ruby gem (of course) that makes it really quick and easy to add, edit, list and remove local host names. To add a new domain, just run this from your command line:
$ ghost add mynewfunkydevsite.dev
=> [Adding] mynewfunkydevsite.dev -> 127.0.0.1
And the domain mynewfunkydevsite.dev is instantly ready and waiting to serve your needs. By default it will point to your local IP: 127.0.0.1, but if you want to point it to a different IP, just add it on the end:
$ ghost add mynewfunkydevsite.dev 123.123.123.123
=> [Adding] mynewfunkydevsite.dev -> 123.123.123.123
Here are the other commands:
$ ghost list
Listing 2 host(s):
mydevsite.local -> 127.0.0.1
staging-server.local -> 67.207.136.164
$ ghost delete mydevsite.local
[Deleting] mydevsite.local
$ ghost delete_matching test
[Deleting] test2.local
[Deleting] test.local
$ ghost list
Listing 1 host(s):
staging-server.local -> 67.207.136.164
$ ghost modify staging-server.local 64.233.167.99
[Modifying] staging-server.local -> 64.233.167.99
$ ghost list
Listing 1 host(s):
staging-server.local -> 64.233.167.99
$ ghost export > some_file
$ ghost empty
[Emptying] Done.
$ ghost list
Listing 0 host(s):
$ ghost import some_file
[Adding] staging-server.local -> 64.233.167.99
$ ghost list
Listing 1 host(s):
staging-server.local -> 64.233.167.99
Give it a go. Your [developer] life depends on it!
