Summary
Common practice for Web developers at Dirigo Design & Development is to push the latest build of a project to a test server for our clients and internal team to view. For a client to see our progress, they must edit the .hosts file on their computer (this allows a preview of a Web site on a server).
How it works
When you view a Web site, the .hosts file is what links the site’s host name to an IP address. When a match is not found, a Domain Name System (DNS) lookup is issued by your computer.
By editing your computer’s .hosts file, this intercepts the DNS lookup and redirects your domain to another IP address. Theoretically you can redirect a call to www.google.com to another site. This all sounds pretty interesting, doesn’t it? Well think of all the fun you can have with this information when you are an undergrad and a self-proclaimed computer nerd who liked to play practical jokes on their roommate.
How to change your .hosts file
Below are detailed instructions on how to edit your computers hosts file depending on the operating system you have installed.
Microsoft Windows 7
- Click Start -> All Programs -> Accessories.
- Right click “Notepad” and select “Run as administrator”
- Click Yes on the UAC prompt.
- Click File -> Open.
- Change the file filter drop down box from “Text Documents (*.txt)” to “All Files (*.*)”.
- Browse to “C:\Windows\System32\Drivers\etc”.
- Select “hosts” and click “Open”.
- Insert the test servers IP and your domain name. For example: 100.100.100.100 mywebsite.com.
- Close Notepad. Click Save when prompted.
Microsoft Windows Vista
- Click Start -> All Programs -> Accessories.
- Right click “Notepad” and select “Run as administrator”
- Click Continue on the UAC prompt.
- Click File -> Open.
- Change the file filter drop down box from “Text Documents (*.txt)” to “All Files (*.*)”.
- Browse to “C:\Windows\System32\Drivers\etc”.
- Select “hosts” and click “Open”.
- Insert the test servers IP and your domain name. For example: 100.100.100.100 mywebsite.com.
- Close Notepad. Click Save when prompted.
Microsoft XP/2003/2000
- Browse to Start > Programs > Accessories > Notepad.
- Click File > Open.
- Browse to “C:\Windows\System32\Drivers\etc”.
- Select “All Files (*.*)” from the Files of Type drop-down menu.
- Select “hosts” and click “Open”.
- Insert the test servers IP and your domain name. For example: 100.100.100.100 mywebsite.com.
- Close Notepad. Save when prompted.
Apple OS X Lion, Snow Leopard & Leopard[v1]
- Open Terminal (Click Spotlight, or press Command+Space.
- Now type terminal.)
- Copy and paste the following code into Terminal:
- sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts
- Press Enter.
- Insert the test servers IP and your domain name.
- For example: 100.100.100.100 mywebsite.com.
(Below is an example of what the hosts file will look like.)
- Save by pressing Command+S, click Save.
- Restart your browser before attempting to view your site.
Example showing adding 100.100.100.100 mywebsite.com to hosts on Snow Leopard.[v2]
##
# 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
#DIRIGO Test Server IP and Site Name
100.100.100.100 mywebsite.com
Apple OSX 10.4.X Tiger
- Open Terminal (Click Spotlight, or press Command+Space. Now type terminal.)
- In Terminal type, ‘sudo pico /etc/hosts‘, press Enter.
- Insert the test servers IP and your domain name. For example: 100.100.100.100 mywebsite.com.
- Press Ctrl+X, then Y to save.
- Type ’sudo niload -v -m hosts . < /etc/hosts', press Enter
- Type ‘lookupd -flushcache’, press Enter.
Conclusion
And there you have it, a how-to for editing your computers .hosts file depending on various operating systems. Have fun! |