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?
Best Answer
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.