Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I'm working locally on a project and want to have some requests to a domain resolve to localhost and others just go where they normally would.

I want to essentially do this in my hosts file:*

As far as I understand, this isn't possible with /etc/hosts, but I could be wrong. Nevertheless, I'm open to suggestions. I'm using Apache and have tried using a proxy to send /dir/* requests to the real IP address of, but then they can't resolve where I came from—I need it to seem like I'm accessing by going directly to

I.e., this doesn't do what I want in my site configuration:

ProxyPass /dir/

Because then the foreign site thinks I'm accessing it from and not

share|improve this question

As far as I understand, this isn't possible with /etc/hosts, but I could be wrong

You understood that correctly.

DNS (and /etc/hosts is part of the DNS resolver) resolves hosts.
It does not do anything with URLs.

In* is not the name of a computer/host, so it should throw an error or ignore the line.

This is normal DNS operation and this is just how it works.

Confusingly HTTP is an odd duck. the HTTP protocol does look at server names and directories. The host will use DNS to resolve the IP, and then sent a datagram which includes the URL. This is why you can have different rules for different directories when you play with proxies (or even multiple website domains on a single IP).

But as written before. HTTP is the odd duck here. And first it will need to resolve the IP via DNS.

I pondered posting this as a comment since it does not really help you with the problem, other then understanding where things go wrong. Sadly comments do not allow a lot of formatting. :(

share|improve this answer
Good information, and solidifies a few of my assumptions. Thank you. Is it possible to set up something like a DNS interceptor to catch certain domains? – Ian Hunter Apr 6 '13 at 15:48
You might be able to do something with a proxy like squid. That way you have something which understands HTTP and you may be able to redirect some of the domains. However that is outside my experience and does not involve the host file. You might want to check if there are similar posts and if there are none create a new post. – Hennes Apr 6 '13 at 16:01

Your Answer


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.