Go Back   HostGator Peer Support Forums > General Discussion > Webhosting

Notices

Reply
 
Thread Tools
  #1  
Old 12-01-2006, 01:04 AM
GatorJesse
HostGator Guest
 
Posts: n/a
Default How-To: Edit your ''hosts'' file to preview a domain name

Do this if you want to preview your site on our servers without changing DNS.

You will need the domain name (eg: example.com, test.example.com) and the IP address of the target server. Make sure you close all open browser windows before doing this.

Common locations of the 'hosts' file:
Windows 95/98/Me: c:\windows\hosts
Windows NT/2000: c:\winnt\system32\drivers\etc\hosts
Windows XP (Home OR Pro): c:\windows\system32\drivers\etc\hosts
(you may need administrator access for Windows NT/2000/XP)
NOTE: 'hosts' is the name of the file and not another directory name.
It does not have an extension (eg: .exe, .txt, .doc, etc.)


1) Copy the location to your 'hosts' file from the respective Operating System above (copy only the bold area)
2) Open Windows Notepad (Start -> All Programs -> Accessories -> Notepad)
3) Click on the File menu and choose Open...
4) Paste that location into the File name: field and click the Open button
5) Start on a new line at the bottom of the file
6) T
ype the IP address, hit the TAB key, then type the domain*
7) Save the file and close all open browsers before attempting to browse to the domain.

*You can add more than one hostname on the same line, just make sure you have at least one space or TAB in between each one.

Example line:

Code:
192.168.0.10    example.com test.example.com www.example.com

Remember, this is only a temporary fix, so once your registrar has the updated information and DNS is fully propagated, you will need to remove any lines you added to the 'hosts' file.

NOTE: this ONLY works on the computer where you changed the 'hosts' file.
Reply With Quote
  #2  
Old 12-01-2006, 08:32 PM
chaloupe chaloupe is offline
King Croc
 
Join Date: Nov 2004
Location: Dieppe, New-Brunswick, Canada
Posts: 1,427
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

Good thing to know!
__________________
Jean Boudreau - IT for local businesses
It's all about automation!
Any data backup of your company?

Reply With Quote
  #3  
Old 12-02-2006, 05:20 AM
taylord1 taylord1 is offline
Hatchling Croc
 
Join Date: Nov 2006
Posts: 2
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

Just remember to remove it once the DNS has propagated!

I've lost count of the number of clients who have forgotten to do this and ran in to troubles later when an IP address changed, when they moved hosting once again or even when a test site moved to a live server!

A PostIt Note on the monitor is a good thing!

~Dan
Reply With Quote
  #4  
Old 04-20-2007, 04:48 AM
hbird hbird is offline
Hatchling Croc
 
Join Date: Apr 2007
Posts: 11
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

Since I'm on Linux as my main PC, I'd like to add this.


The syntax for the Linux host file is basically the same, so you would want to edit "/etc/hosts". I would use "sudo vim /etc/hosts", then add the line after the 127.0.1.1 line.

After editing the hosts, I think you need to restart the computer, but I didn't need to. Just check the site, if it doesn't work then restart.
Reply With Quote
  #5  
Old 04-20-2007, 06:08 AM
quietFinn's Avatar
quietFinn quietFinn is offline
Veteran Croc
 
Join Date: Feb 2005
Posts: 3,557
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

Quote:
Originally Posted by hbird View Post
After editing the hosts, I think you need to restart the computer, but I didn't need to. Just check the site, if it doesn't work then restart.
No, you don't need to do that (Windows).
__________________
quietFinn - netFinn Finland
"Be who you are and say what you feel because those who mind don't matter and those who matter don't mind." - Dr. Seuss
Reply With Quote
  #6  
Old 04-20-2007, 12:44 PM
Dimwhit Dimwhit is offline
Hatchling Croc
 
Join Date: Feb 2007
Posts: 41
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

I'll give the Mac OSX way. The file is edited the same way, I believe. To get to the file:

In the Finder, Go > Go to Folder
Type: /private/etc/

Find the hosts file and edit. (Wouldn't be a bad idea to back up the file first.)
Reply With Quote
  #7  
Old 04-20-2007, 11:40 PM
GatorJesse
HostGator Guest
 
Posts: n/a
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

The 'hosts' file is a system file that is read each time the system does any DNS queries. It will check 'hosts' first, if what it's looking for is found it will use it and will not attempt to check with DNS; if not found in the 'hosts' file it will then check DNS.

A reboot (for any OS) is not required. If you didn't see the change in your browser then, most likely, you did not close all browser windows after making the change. Just close all open browsers and try again.
Reply With Quote
  #8  
Old 07-06-2007, 03:30 PM
tucan tucan is offline
Hatchling Croc
 
Join Date: Apr 2004
Location: Sacramento
Posts: 12
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

Quote:
Originally Posted by quietFinn View Post
No, you don't need to do that (Windows).
A restart is not necessary but its the simplest step you can take.

Or

1. Close out all existing IE windows.
2. In the command prompt type, netstat

Adding a host file entry is very nice trick in development if the domain name has yet to propagate to the server holding your account.
Reply With Quote
  #9  
Old 07-06-2007, 03:57 PM
Break the Silence's Avatar
Break the Silence Break the Silence is offline
Junior Croc
 
Join Date: May 2007
Posts: 154
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

Quote:
Originally Posted by GatorJesse View Post
The 'hosts' file is a system file that is read each time the system does any DNS queries. It will check 'hosts' first, if what it's looking for is found it will use it and will not attempt to check with DNS; if not found in the 'hosts' file it will then check DNS.
A lot of people use this same technique for ad blocking as well...

Simply edit the host file with the name of the offending server, add a non-existent ip and presto chango - no more annoying ads.
Reply With Quote
  #10  
Old 07-06-2007, 04:15 PM
gwyneth's Avatar
gwyneth gwyneth is offline
Supreme Croc
 
Join Date: Sep 2006
Location: up north
Posts: 6,843
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

Quote:
Originally Posted by Break the Silence View Post
A lot of people use this same technique for ad blocking as well...

Simply edit the host file with the name of the offending server, add a non-existent ip and presto chango - no more annoying ads.
This isn't so necessary with Firefox and its ad blocker extensions, but a very good way to do it if you insist on running IE when connected.

Several Windows utility sites have "pre-stocked" hosts files, with known nuisances already provided. I believe this site has one, with more detailed instructions for implementing it:

AXCEL216 / MDGx MAX Speed WinDOwS Tricks + Secrets
Reply With Quote
  #11  
Old 07-06-2007, 04:59 PM
gtgeorge's Avatar
gtgeorge gtgeorge is offline
Emperor Croc
 
Join Date: Mar 2005
Posts: 2,223
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

Quote:
Originally Posted by Break the Silence View Post
A lot of people use this same technique for ad blocking as well...

Simply edit the host file with the name of the offending server, add a non-existent ip and presto chango - no more annoying ads.
It also comes in handy for those pesky email trackers that use a transparent gif etc.
__________________
best regards,
George
Reply With Quote
  #12  
Old 07-06-2007, 05:05 PM
ghpk ghpk is offline
King Croc
 
Join Date: Nov 2006
Posts: 1,245
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

hi,
if iam not mistaken on Vista its at C:\Windows\System32\drivers\etc

see ya,
Reply With Quote
  #13  
Old 07-07-2007, 10:53 PM
Break the Silence's Avatar
Break the Silence Break the Silence is offline
Junior Croc
 
Join Date: May 2007
Posts: 154
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

Quote:
Originally Posted by gwyneth View Post
This isn't so necessary with Firefox and its ad blocker extensions, but a very good way to do it if you insist on running IE when connected.
Exactly...

I still run both, although I only use IE on my old systems as required for certain educational app's. As for the Firefox extensions, they really are quite handy, especially Adblock Plus - which just so happens to be my personal favorite.
Reply With Quote
  #14  
Old 04-07-2008, 03:04 AM
ideashop's Avatar
ideashop ideashop is offline
Hatchling Croc
 
Join Date: Mar 2008
Posts: 1
Default Re: How-To: Edit your ''hosts'' file to preview a domain name

One thing to note: if you're running Vista, editing the Hosts file is not as simple as in XP. Vista will tell you that you don't have permission to edit it.
Here's what to do:
  1. Open Notepad with Administrative privileges by clicking Start, All Programs, Accessories, and then right-click Notepad and select to open as Administrator.
  2. Now that Notepad is open with Administrative privileges, you'll need to open the hosts file from this instance of Notepad. Click "Ctrl-O" and browse to (C:\Windows\System32\drivers\etc) in Notepad and open the hosts file.
Now you may edit and save the hosts file.
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 03:08 AM.