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.

We can use C:\WINDOWS\system32\drivers\etc\hosts file to map hostname with IP addresses like this

127.0.0.1 localhost

But is it possible to assign one hostname to another like this?

localhost a_new_host_name

share|improve this question
3  
Why don't you just try it? –  fretje Feb 16 '10 at 9:21
2  
Just tried. It does not work. But is there an alternate way to achieve this? –  bdhar Feb 16 '10 at 9:35

3 Answers 3

up vote 1 down vote accepted

From wikipedia :

The hosts file contains lines of text consisting of an IP address and one or more hostnames, each field separated by white space (blank or tabulation characters). Comment lines may be included; they are indicated by a hash character (#) in the first position of such lines. For example,

#This is an example of the hosts file
127.0.0.1  localhost loopback
share|improve this answer

You could put in the hosts file:

a_new_host_ip_addr localhost 

Beyond that, I think you would need to set up a local (or nearby) DNS server with CNAME entries to map localhost to some other host (and you'd have to remove 'localhost' from the hosts file for this to work).

share|improve this answer
    
I am not sure if this is a good advice. Why would one ever make localhost point to a different IP address? –  Arjan Feb 16 '10 at 13:44

You may have got the impression that some kind of 'redirection' is possible from things like

127.0.0.1    ads.stackoverflow.com

in your hosts file. Purely as an example, you understand. This does not conflict with the usual definition of localhost elsewhere in the same hosts file.

The Internet has a number of sample hosts file which ensure that unwanted images don't appear on your screen.

share|improve this answer
    
One could also use 74.125.79.18 superuser.com to make the domain name superuser.com erroneously point to a (current) IP address of the Google servers. However, a browser will send the original hostname in the HTTP request. Many shared web servers host multiple domains on a single IP address (like 74.125.79.18 is google.com but also gmail.com), and then only accept known host names or default to some specific site when an unknown name is requested. So, one cannot really use a hosts file for reliable "redirection", though one can indeed redirect to "nothing" (like in the answer above). –  Arjan Feb 16 '10 at 13:53
    
Attackers sometimes try to hijack dns using this method. It doesn't get you much when you make it point to a google server, but if you are the attacker you can make it point to your own server where you spoof their bank's login page or whatever. –  Mnebuerquo Mar 29 '10 at 21:47

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.