E-Mail:
Get our new Windows 7 eBook (PDF) for $7 with 70+ Tips. Download Now!

Can I Fake The DNS IP Lookup To Test My Web Site?

  • No Related Post

The situation is this: you have a working Web site, and you’re about to move it, or make dramatic changes to it. So, you make a copy of the Web site, at a different IP address, possibly with a different temporary domain name. You make all your changes, and then want to test it out using the correct URL - the “real” domain name. How can you do that without actually changing the Internet’s DNS entry for your domain?

It’s not hard at all.

Let’s look at the example in more detail. Say you’re the proud owner of http://example.com, and it lives on a server at IP address 1.2.3.4. You’re about to make major changes to it, so you create a new domain, http://test.example.com on a different server with a different IP address - 1.2.3.5.

After you make your changes, you want (or in come cases you may need) to test the new server at the new address, but using the “correct,” real name of the site: example.com and not test.example.com.

In other words, you would like to change example.com to point to 1.2.3.5 instead of 1.2.3.4. Ideally, though, you would not want that to be true for everyone. In fact, you want that to be true only for you… while you’re testing your new site, you want the world to continue to only see example.com at the old IP address 1.2.3.4.

Enter the “hosts” file, in Windows. This text file contains IP - to - name mappings that override DNS. In fact, if Windows finds an entry in the DNS file, the Internet DNS is never even consulted.

The hosts file lives in c:\windows\system32\drivers\etc\hosts (where “c:\windows” is your Windows directory). It’s just a text file, and each line that doesn’t begin with a “#” character is of the form:

number space name

So, for our example, we would edit this hosts file, and add the following line:

1.2.3.5 example.com

Now, on our machine only “example.com” will reference the new IP address, 1.2.3.5, instead of whatever DNS has listed.

There are a couple of caveats:

You’ll need an entry for every and any domain or subdomain you’re testing. So for example if you needed to test both “example.com” and “www.example.com”, you would create two entries.

You must remember to remove the entries from your hosts file after your testing is complete. Remember, the hosts file overrides DNS, so if the real IP address for example.com changes again sometime in the future, this machine will continue to believe it’s at whatever IP address is listed in hosts.
If this approach sounds vaguely familiar, it’s also a technique used by viruses and spyware, By placing entries into your hosts file, malware writers can redirect you to their sites, or prevent you from accessing other sites. And that brings us to a final caveat:

A properly configured anti-spyware or anti-virus program may prevent you from making changes to your hosts file. It’s safe to temporarily override these programs settings while you perform your test, but be sure to restore their real-rime protection when you’re done.

Related:
Ask Leo! - Why can I not access certain Web sites?
Ask Leo! - Is there a way to block certain URLs in IE?

What Do You Think?

 

Posted Recently

41 queries / 0.464 seconds.