HostGator.com » Support Portal

How do I change my hosts file?

You are likely asking this because you want to see your domain name before your DNS changes propagate. Reminder: You normally need to wait 48 hours for propagation to complete.

Here is an advanced process for forcing your computer to see the site, early:

You will add the second line in this example, but be sure to use the server IP we provide you and your actual domain name.

127.0.0.1 localhost

204.11.246.1 www.example.com

Windows XP and lower Edit your hosts file on your PC.

Wait! Before reading these instructions, consider watching the video tutorial.

If you are using Windows, use "Start", "Find", "Files and Folders" to find a file in your windows directory (or WINNT\system32\drivers\etc) called "hosts". Verify that the file is not "read only" by right clicking it, and choosing it's Properties. Then open the file for editing with Notepad. There should already be an entry for "localhost". Follow that format when you insert your domain and our IP.

On Windows98 and Windows95, the order may be 'hostname' then 'IP address'. On Windows2000 and WindowsME, the order is 'IP address' then 'hostname'

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". You may also need to reboot for the change to take effect. Next time you try to go to "www.example.com", your browser will try to find that domain at the corresponding IP instead of looking up the IP through DNS.

Windows 7 or Vista Edit your hosts file on your PC.

  1. Browse to 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. Browse to "C:\Windows\System32\Drivers\etc"
  6. Change the file filter drop down box from "Text Documents (*.txt)" to "All Files (*.*)"
  7. Select "hosts" and click "Open"
  8. Make the needed changes, as shown above, and close Notepad. Save when prompted.

MAC Do this if you want to preview your site on our servers without changing DNS and you are running Mac OS X:

  1. Open the Terminal application. Start by typing Terminal on the Spotlight, or by going into Applications -> Utilities -> Terminal.
  2. Open the hosts file. Open the hosts by typing on the Terminal that you have just opened:

    sudo nano /private/etc/hosts

    Type your user password when prompted.

  3. Edit the hosts file. The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (e.g. 127.0.0.1 – localhost). Simply append your new mappings underneath the default ones. You can navigate the file using the arrow keys.
    IPGOESHERE domain.com www.domain.com
    Replace domain.com with your actual domain name. Additional domains, sub-domains or addon domains can be added at the end of the line separated by spaces.
  4. Save the hosts file. When done editing the hosts file, press control-o to save the file. Press enter on the filename prompt, and control-x to exit the editor.

UNIX On Unix-based systems, you can find the hosts file at /etc/hosts.

You will need to open the terminal (on most distributions is located at the following):

Menu > Applications > Accessories > Terminal

Follow Steps 2 through 4 above (for MAC) to edit this file.


Once you have modified your hosts file, you can flush your DNS so that you can see your new changes more quickly. Do this from the command line. Depending on your OS, there are different commands: Flush DNS


Article Comments

AB
I'm using win7..
and I did what you wrote here..
that's great.. and worked for me...
Thanks

KC
When you go to remove the line, don't forget to right click on Notepad and run as administrator again. Otherwise, you won't be able to save it.

HostGator
Thank you for your comments. Just a quick reminder that the comments on this page are not monitored by technical support staff, and that for support issues, it is best to contact us by live chat, phone or email so we can assist you right away.

Although comments are not monitored by technical support staff, they are moderated and read by technical writers. Comments will need to be approved by a moderator before appearing.

Our technical writers do read the comments periodically for the purposes of updating the articles, and do appreciate your feedback, suggestions and corrections to the articles themselves, as well as any suggestions or tips for readers of this article. However, support questions posted here are not guaranteed to be replied to in a timely manner or at all. For support issues, it is best to contact our support staff instead by live chat, email or phone.



Your comments help us keep the knowledge base updated. This is not a medium for support. If you have questions or need help, please contact us via email, phone or live chat for fast assistance.

Post Comment