Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

domainA.com --> 127.0.0.1

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.

domainA.com --> domainB.com


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 domainA.com
  • launch a DNS request for a domainB.com
  • serve the IP of domainB.com in response to the request for domainA.com

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

4 Answers 4

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 domainB.com and modifies the entry of domainA.com 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 domainA.com to domainB.com, you simply put domainB.com's ip as domainA.com's entry in the hosts file.

This results in ANYTHING targeting/visiting domainA.com instead being redirected to domainB.com.

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 Google.com shows the following:

enter image description here

(Notice the Host: line).

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

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

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 domainB.com , you simply need to add domainA.com to the addresses it will listen to - then any host header with domainA.com - it will respond with domainB.com'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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.