Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 have a linux test machine which I would like to run a copy of a production webserver. This is a legacy application which does not use a property file for its server name. Throughout the application, the server name is hardcoded (example: open connection to

Is there any linux trick which I can use to redirect all requests for a certain host back to localhost? I know in Windows that I can add an entry to the hosts file and have it redirect back to localhost. How do I do this in linux?

share|improve this question

Add the following line to /etc/hosts:

share|improve this answer
Will that work if is sometimes referenced by http and other times with https? Even with different ports (besides 80)? – somebody Jun 1 '10 at 20:20
Yes, it will. You're only specifying what IP resolves to. It doesn't matter what service you're connecting to on that IP. /etc/hosts is at OSI layer 3, the services are a layer 4 construct. – baumgart Jun 1 '10 at 21:54
I did exactly that on Debian 8 Jessie. And it aint work: host returns Host not found: 3(NXDOMAIN). – Bob Apr 6 at 10:15
It's well known that nslookup/host don't look at /etc/hosts. Try pinging the host, it should give you the proper IP. Or try using a browser to hit it. – baumgart Apr 12 at 17:09

It looks like modifying the etc/hosts file should fix this......

share|improve this answer
This is really a comment, not an answer to the question. You can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. – Matthew Pirocchi Aug 11 '12 at 1:11
@Matthew: He's self-answering I think, or he meant to improve his question. – Tom Wijsman Aug 13 '12 at 14:53

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.