As a web developer,I have to move sites around frequently. Sometimes this can be tricky accessing both websites before/after the move has occurred.
One case is trying to get to the “old site” after it has been moved. This can be accomplished using a special file on a Mac (and all *nix based systems) named /etc/hosts.
You will need to know the old IP address of the website. This can often be obtained if you know the OLD DNS Servers.
1. Launch the terminal application from Applications -> Utilities ->Terminal
This will open up terminal and place you at a command prompt.
2. From here, you want to give the commands in bold (without the $ sign): $ nslookup
This will take you to a > prompt.
3. From here, enter the word server – followed by the name of your OLD dns server
> server ns1.oldisp.com
Default server: ns1.oldisp.com
4. This will return you to the > prompt, and then enter your URL
5. This will return the IP address your old hosting company has for the website.
6. Back to the > prompt, type exit
Now to make the /etc/host entries.
1. (Re)-Launch the terminal application from Applications -> Terminal
2. You need to open /etc/hosts as the system administrator. This is done using the sudo command:
$ sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts
3. You should be prompted for your password – this should be the same password you use to login and/or authenticate to OSX to install updates/software:
You then may see something like :
2009-09-30 11:31:10.322 TextEdit[30732:c0b] *** CFMessagePort:
bootstrap_register(): failed 1100 (0x44c) ‘Permission denied’, port =
0x4403, name = ‘com.apple.TextEdit.
As long as Textedit is open, you will notice the terminal window seems unresponsive.
4. You should see a texteditor window with the contents of /etc/hosts :
In TextEdit, you will want to add a line line shown in the image (using the IP address and real domain name)
Save and quit Textedit, which should return the terminal window back to the $ prompt.
On OSX 10.5, these changes seem to take effect immediately. If you are running 10.4 – there may be a few other commands to give .. see here for further instructions
When you are all done and you need to restore your access back to the “live” site, simply reverse these directions, removing the line from the /etc/hosts file. You can also comment the line out by placing a # in front of it.