Domain Names

ID #52

How do I edit my "hosts" file?

Applies to: Grid System

Windows

  1. Right click the Notepad application and select "Run as Administrator" to edit this system file.  If you do not have admin privildges, you will not be able to edit your hosts file.
  2. Open the hosts file at C:\Windows\System32\drivers\etc\hosts
  3. There should already be an entry for "localhost". Follow that format when you insert your domain and our IP.  For example:
    127.0.0.1       localhost
    204.11.246.1 www.example.com
  4. Then save this altered hosts file and close notepad. Make sure Windows did not silently save the file as "hosts.sam". The filename has to be "hosts".
  5. Once you have modified your hosts file, you can flush your DNS so that you can see your new changes more quickly  You can either:
    • reboot
    • open a command prompt and use the command
    ipconfig /flushdns

Next time you try to go to "www.example.com", your browser will try to find your domain at the corresponding IP instead of looking up the IP through DNS.

Mac

  1. Open Finder.
  2. In the Go menu, select "Go to Folder"
  3. Type /etc for the folder name.
  4. In the list of files that appears, you should find "hosts. Double click it to open it in a text editor.
  5. As in the windows example, the format of the file is: "204.11.246.1 www.example.com".

You will need to clear your dns cache or wait for these changes to go into effect.  You can clear your cache by rebooting or running the following command from Terminal:

lookupd -flushcache

Linux, BSD, and *NIX

On unix-based systems, as well as OS X's terminal, you can find the hosts file at /etc/hosts.  You will need to edit it with administrator or root privilidges.  Try the command:

sudo gedit /etc/hosts

Once you have modified your hosts file, you can flush your DNS so that you can see your new changes more quickly. Run the command:

sudo /etc/init.d/nscd restart

Last update: 2011-11-01 12:23
Author: FAQ Admin
Revision: 1.5

Digg it! Share on Facebook Print this record Send FAQ to a friend Show this as PDF file
Please rate this FAQ:

Average rating: 3.08 (37 Votes)

completely useless 1 2 3 4 5 most valuable

You can comment this FAQ

Comment of Anonymous:
Under Mac OS 9, the hosts file has to be named "Hosts" with a capital H.
Also, the entries in the file have to be of the form
domain_name A IP_address
example.com A 1.1.1.1

The OS 9 TCP/IP Control Panel has a "Select Hosts file" button. With the use of this button, the hosts file can have any name and be located anywhere. Also, TCP/IP will parse the hosts file for syntax when you select the file with this button.
Added at: 2006-06-22 03:22

Comment of Anonymous:
In the Mac OS 9 Hosts file, don't use leading blanks on the entry lines. A leading semicolon or a leading blank is taken as a comment line.

The Hosts file has to be a plain text file, so use SimpleText to edit it.

Whenever you change the Hosts file, it has to be reloaded into TCP/IP. The basic way is to Restart the computer, but I found the combination of these two actions also reloads the Hosts file (actually it may be that only one of them is necessary, but I didn't try that): (1) Use the Select Hosts File button in the TCP/IP Control Panel to choose the Hosts file. (2) Use the Options button in the TCP/IP Control Panel, from which you can make TCP/IP Inactive. Close the TCP/IP panel and Save when requested. Then reopen the panel, choose Options again, and make TCP/IP active again. Close and Save. In the Options, "Load Only when Needed" works.
Added at: 2006-06-22 04:35

Comment of Anonymous:
Mac OS 10.5
dscacheutil -flushcache
Added at: 2008-08-10 01:54