Web Development & Execution
Jessie Lacey
by Jessie Lacey
share this
?fl
« Back to the Blog

How to edit your hosts file on Mac and Windows

11/29/2011
How to edit your hosts file on Mac and Windows

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, 8, 8.1 & 10

  1. Click Start -> All Programs -> Accessories.
  2. Right click “Notepad” and select “Run as administrator”
  3. Click Yes on the UAC prompt.
  4. Click File -> Open.
  5. Change the file filter drop down box from “Text Documents (*.txt)” to “All Files (*.*)”.
  6. Browse to “C:\Windows\System32\Drivers\etc”.
  7. Select “hosts” and click “Open”.
  8. Insert the test servers IP and your domain name. For example: 100.100.100.100 mywebsite.com.
  9. Close Notepad. Click Save when prompted.

Microsoft Windows Vista

  1. Click Start -> All Programs -> Accessories.
  2. Right click “Notepad” and select “Run as administrator”
  3. Click Continue on the UAC prompt.
  4. Click File -> Open.
  5. Change the file filter drop down box from “Text Documents (*.txt)” to “All Files (*.*)”.
  6. Browse to “C:\Windows\System32\Drivers\etc”.
  7. Select “hosts” and click “Open”.
  8. Insert the test servers IP and your domain name. For example: 100.100.100.100 mywebsite.com.
  9. Close Notepad. Click Save when prompted.

Microsoft XP/2003/2000

  1. Browse to Start > Programs > Accessories > Notepad.
  2. Click File > Open.
  3. Browse to “C:\Windows\System32\Drivers\etc”.
  4. Select “All Files (*.*)” from the Files of Type drop-down menu.
  5. Select “hosts” and click “Open”.
  6. Insert the test servers IP and your domain name. For example: 100.100.100.100 mywebsite.com.
  7. Close Notepad. Save when prompted.

Apple OS X Lion, Snow Leopard & Leopard

  1. Open Terminal (Click Spotlight, or press Command+Space.
  2. Now type terminal.)
  3. Copy and paste the following code into Terminal:
    1. sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts
    2. Press Enter.
    3. Insert the test servers IP and your domain name.
      1. For example: 100.100.100.100 mywebsite.com.

Below is an example of what the hosts file will look like.

  1. Save by pressing Command+S, click Save.
  2. Restart your browser before attempting to view your site.

Example showing adding 100.100.100.100 mywebsite.com to hosts on Snow Leopard.

##

# 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

  1. Open Terminal (Click Spotlight, or press Command+Space. Now type terminal.)
  2. In Terminal type, ‘sudo pico /etc/hosts‘, press Enter.
  3. Insert the test servers IP and your domain name. For example: 100.100.100.100 mywebsite.com.
  4. Press Ctrl+X, then Y to save.
  5. Type ’sudo niload -v -m hosts . < /etc/hosts', press Enter
  6. Type ‘lookupd -flushcache’, press Enter.

Thanks!

Thank you for contacting us!

We'll be in touch!

Back Home ×