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

My /etc/hosts file looks like this:       localhost

The first two work. The last one doesn't. Why not? How do I make it work? The reason I am doing this, is because I have a test server (, which is on the local network, but it's ip can vary. e.g. one day, another, etc.

So, how do I make my system always resolve to the same ip as

share|improve this question
Just make it – ott-- May 30 '13 at 9:20
up vote 2 down vote accepted

As Chris already wrote, the problem is that "" is not a number. The format you need is IP hostname1 [hostname2] [hostname3].

The deeper problem however is a misunderstanding about the host file and possibly about DNS in general. Basically the host file was not designed for redirections. It was a simple solution back from when CPU cycles where expensive. It lacked features such as the ability to adjust to rapidly changing IP addresses without manually needing to edit a file. These problems were solved by switching from the host file to network based resolver system.

The real answer to your problem therefore is not to use /etc/hosts, but to use this hierarchical distributed naming system instead. You can do that in several ways. One way is the CNAME as suggested by Chris. Another way would be to give the second server a fixed IP address. Both a real static address, or make a reservation in the DHCP server.

share|improve this answer
Not the kind of answer I'm looking for. This is for development; I don't want to modify any other machines, since the domain name ( does not need to be accessible from anywhere but my local. I just want a way to tell my computer "treat name X like it was Y". – Benubird May 30 '13 at 10:16
In that case you want to insstall a local DNS server and use that as resolver. – Hennes Jul 16 '14 at 7:54
Local DNS server seems to be the solution. For future visitors, I found this helpful: – Benubird Jul 16 '14 at 10:40

Format of /etc/hosts is "IP" "Hostname" - like localhost

You need a CNAME in your local DNS server to achieve what you need. You could get the IP of the "" and link it to "" like you did with "" but when that IP changes you will have to change your /etc/hosts file as well.

share|improve this answer

If has dynamic IP, but is always accessible by name you have to rely on its registered DNS by always referencing it by name.

Your solution is to make a redirecting URL for

ServerName Redirect /

This way always works (not breaking it with bad host entry) and is always redirected to by resolving the name to the right IP.

share|improve this answer

You must log in to answer this question.

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