Technology in terms you understand. Sign up for the Confident Computing newsletter for weekly solutions to make your life easier. Click here and get The Ask Leo! Guide to Staying Safe on the Internet — FREE Edition as my thank you for subscribing!

Can I fake the DNS ip lookup to test my website?

Question: Can I fake the DNS ip lookup to test my website?

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.

Become a Patron of Ask Leo! and go ad-free!

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

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

In other words, you would like to change to point to instead of 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 at the old IP address

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, then 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:

Now, on our machine only “” will reference the new IP address,, 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 “” and “”, 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 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.

Do this

Subscribe to Confident Computing! Less frustration and more confidence, solutions, answers, and tips in your inbox every week.

I'll see you there!

15 comments on “Can I fake the DNS ip lookup to test my website?”

  1. Good trick. I supose it will work well if you have a your own server with a static IP address, but probably will be dificult if your domain is hosted in a shared machine. Any idea for this?

  2. Definetly works for static IPs. Don’t understand how a machine being shared or not (in any of several definiteions of ‘sharing’) makes a difference though.

  3. Quote:

    Remember, the hosts file overrides DNS, so if the real IP address for changes again sometime in the future, this machine will continue to believe it’s at whatever IP address is listed in hosts.


    This is not true, all over the microsoft website it is said that the DNS is read FIRST and the HOSTS file read SECOND. This is a problem for me because I am trying to give a different IP for a hostname and I am unable to because the hostname is first resolved via DNS so Windows does not bother checking HOSTS.

  4. I can’t seem to redirect an IP to an IP in the hosts file. I have a desktop application which references an IP that is no longer valid and I don’t have the source code. I want to fake the PC into thinking that the old IP is referring to the new IP.

    Say my old IP is and my new IP is, I want the host file to say something like this:

    This doesn’t work though, any ideas?

    Hash: SHA1

    What you’re trying to do isn’t possible. An IP address can’t
    be mapped to another IP address in that way. The hosts file
    is all about mapping *names* to addresses.

    I don’t know of a solution for your application, short of
    trying to patch the binary.


    Version: GnuPG v1.4.7 (MingW32)


  6. Hi, I would like to know how to do the remotely from hometo office with dynamic IP address. Using RealVNC free edition.

  7. Karl wrote: (quote) This is not true, all over the microsoft website it is said that the DNS is read FIRST and the HOSTS file read SECOND. (end quote)

    Never mind the documentation – a 2 minute test shows that the hosts file overrides your DNS server. Try putting or whatever other host name you like in your hosts file with a redirection to some other IP, and then do a NSLOOKUP on that host name. You will see that it goes to the IP you specified in the hosts file, not what your DNS server says. What is confusing though is that even though it got the answer from the Hosts file, NSLOOKUP will say that it got the answer from your DNS server – but it is lying.

  8. hi,
    The above article is nice.It gave an details of changing DNS entry for our domain.I collected the ip details from this ip-details.It’s having the details of finding the ip address location,domain host search also is there.It is really useful for me.

  9. Hi, I have uploaded my site on two servers. I want to use one as a primary server and the second like a backup in case the first goes off-line. I’m experimenting with the name servers, but it seems to choose servers randomly. I set ns1 & ns2 to first server and ns3 & ns4 to second. Any suggestions?

  10. How can one override a DNS mapping only for a particular TCP port? Continuing with your example, let’s say the test site is actually hosted on a specific TCP port 8080, that is, How can I now change the mapping in such a way that the requests for are mapped to

    Is that even possible using /etc/hosts?

    Nope. Which ports are used has nothing at all to do with DNS lookups. The hosts file is only about DNS, which in turn is only about mapping names to IP addresses.



Leave a reply:

Before commenting please:

  • Read the article.
  • Comment on the article.
  • No personal information.
  • No spam.

Comments violating those rules will be removed. Comments that don't add value will be removed, including off-topic or content-free comments, or comments that look even a little bit like spam. All comments containing links and certain keywords will be moderated before publication.

I want comments to be valuable for everyone, including those who come later and take the time to read.