Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using the Windows hosts file, one can redirect traffic for a domain to a specific IP address, e.g. -->

I am looking for a SIMPLE way to do the same, but for a target domain name not for a target IP address (as this is dynamic), I.e. -->

Addition: After the getting some initial answers I think I need to concretise my question.

Situation: I have an application which looks up the IP of the target domain via DNS and then connects via HTTP to the IP address. I do not have control over any proxy settings.

Option 1 Basically I am looking for a way to:

  • intercept DNS requests for a
  • launch a DNS request for a
  • serve the IP of in response to the request for

Without running an entire DNS server.

Option 2 If a DNS server is the only way, in the alternative I would also be happy with an solution to how to define a non-standard DNS-server for a single application. Any ideas for wrapper applications, etc?

share|improve this question
up vote 1 down vote accepted

Third solution

beside setting up a dns-server and injecting a hook into gethostbyname:

Register a script as a service which periodically resolves and modifies the entry of in the /etc/hosts file. Since most dns entries does not change very often, it is sufficient to run the script on startup or once a day.

I am using such a script to update the domain-blocklist on my home computers.

share|improve this answer

Edit - After re-reading your question, I do not think this will be possible without a local DNS server to point at as the hosts file only supports FQDN --> IP. However, I think your best bet will be Either some sort of local redirecting proxy server, or an addon that can rewrite host headers.

However, I wrote a guide you may be interested in, which will hopefully explain things a bit better to you...:

This isn't very easy to explain, so if you have any follow up questions, please write in comments and I will be happy to help:

This is not possible BUT putting the IP results in the exact same end result.

Remember, at the end of the day, all that happens when ever you target a FQDN (Fully Qualified Domain Name) is that it translates that address to an IP address.

If you want to forward anyone visiting to, you simply put's ip as's entry in the hosts file.

This results in ANYTHING targeting/visiting instead being redirected to

HOWEVER I am guessing you want to redirect a website. Websites are a lot more complicated than this, part of the protocol sends something known as a Host Header. This is where the web browser contacts the web server AND tells it the address it is trying to access.

For example, visiting shows the following:

enter image description here

(Notice the Host: line).

You can also visit via it's IP address - - This is because they have a default entry set up which services all requests NOT matching a host header.

So, when you visit it is possible that is only serving content to someone with a host header set to

What you need to do is use a proxy server, Firewall (DPI), or some sort of addon that actually rewrites the Host Header/redirects. Alternatively, if you control the web server , you simply need to add to the addresses it will listen to - then any host header with - it will respond with's content.

Adding addition host headers in IIS:

enter image description here

share|improve this answer
I believe you might be right that a DNS server is unavoidable. - Though I was hoping not. See the addition to my question. – ARF Feb 25 '11 at 19:51

You can set up such redirect actions with Privoxy.

share|improve this answer
is this still possible if I do not have access to the application's proxy settings? – ARF Feb 25 '11 at 19:49
@ArikRaffaelFunke: Ah, your question has been updated, you'll need to run your own DNS server to do what you want. – Tom Wijsman Feb 25 '11 at 20:14

Solution to Option 2

In case anybody else has this problem in future: It is possible to intercept DNS requests from a single application without using the hosts file which affects all functions.

See the CodeProject "Intercept and Rewrite DNS Requests Using Regular Expressions" by Dan Farino

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .