Mapping a domain name to an IP address in the HOSTS file to bypass a DNS resolver.

When I made the switch to another hosting company, I had to point my domain name (briandicroce.com) to their DNS servers. After that, I couldn’t access my site from the domain because the DNS servers associated with my ISP had the previous DNS settings of my domain name in its cache.

My first though to verify that everything was working fine with the new DNS settings was to visit my site from another computer hooked up with another ISP. So I launched a remote desktop session with my PC at work, and from there I could clearly see that my site was accessible and running well.

I pinged my domain name from that PC and received an IP different from the one I got when pinging the same domain name from my own PC hooked up with my ISP. So which IP was the right one then? I visited Network-Tools.com to get this answer. Bingo! My ISP’s DNS server was pointing my domain name to the previous (old) IP addresses. I called the technical support, but they told me that they cannot flush the cache of the DNS server for one site.

So I tried a couple of different things on my end:

  • I tried to release and renew my network adapters with these commands: ipconfig /release and ipconfig /renew.
  • I tried to flush my local DNS resolver cache: ipconfig /flushdns.

Nothing! Every time I would visit my site, I would still receive an error somewhat to a “Could not locate remote server” (I’m an Opera fan). Even after doing a tracert briandicroce.com, I could see that the route would break after a couple of hops.

Anyhow, I managed to fix my problem by modifying the local HOSTS file (see link to find the location of this file in your computer) and manually mapping my domain names (blog.briandicroce.com and briandicroce.com) to the IP addresses of my new hosting servers. Here are the steps to follow in case you’re having the same problem I did (Windows machine only):

  1. Edit the HOSTS file (no extension) with a text editor using Administrator privileges. The location of this file is in %SystemRoot%\system32\drivers\etc\ by default. Note that users of 64-bit versions of Windows Server 2003/2008, and Vista (Windows 7 excluded) cannot access the HOSTS file with a 32-bit editor.
  2. Enter the mappings of your domain names to their corresponding IP addresses. The first value should be the IP address that the domain name (second value) should point at. Make sure to separate the IP Address from the domain name with a whitespace.
  3. Save the file.

And that’s it. Now when you access your domain name, Windows will check to see if there’s an entry for it in the HOSTS file and will use its corresponding IP address, therefore bypassing your ISP’s DNS server’s resolver to direct to the site.

After a couple of days/weeks/months, you could probably remove those entries in the HOSTS file in the case that the DNS server actually flushed its cache.

This post has been viewed: 966 times. kick it on DotNetKicks.com

 

Similar posts you might be interested in reading:

Leave a comment

Powered by WP Hashcash