How to Edit Hosts File in Mac OS X 10.5 Leopard

What you do is open Terminal, which is found in Applications > Utilities. Then type the following:

sudo nano /etc/hosts

Terminal will then ask you for your password, because you have invoked the security privileges of the superuser. Type your password in. Nano will then open. I know you can use VI but for such a simple task, I prefer nano.

Next you will be presented with:

##
# 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

Just a few things to note. A hash, #, is a comment. Don’t mess with those first 4, unless you know what you are doing.

Move the cursor down in nano using the arrow keys. Now you can type in an IP address of the staging server and have it appear to be on the production server domain name. Our theoretical staging server is on IP address 111.111.111.111 and our production server is on IP 11.111.111.112, with the domain www.production.com

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost
111.111.111.111       www.production.com

Now save. This is done by hitting ctrl+o or ^o. Hit enter to name it hosts, then hit ^x to exit nano. In order for this to work the cache needs to be flushed. There is a new command for this in 10.5 Leopard.

dscacheutil -flushcache

Now you can go to your staging server via your production domain name. Handy. Just be careful though. Don’t accidentally make edits to production, or think you’re making edits on production but you’re making them to staging.

Leave a Comment