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.

So basically I want to map the IP address 1.2.3.4 to localhost.

So that when I browse to:

1.2.3.4/somepage.html

It will fetch:

127.0.0.1/somepage.html

Does anyone know how I could go about doing this? Unfortunately the hosts file does not allow these kind of mappings.

share|improve this question

3 Answers 3

What if you add 1.2.3.4 as an extra IP address to your machine.

share|improve this answer
    
Straightforward, but the disadvantage here would be that the machine would be visible to others as that address. This could cause conflicts, or the desired address might be on a completely different network which won't work on the network(s) to which the machine is currently attached. –  kbluck Apr 16 '10 at 15:39
    
I would agree with you on the first point, assuming the ip address is within your own network range. And it would cause ip conflicts if you are attempting to use the address of an existing machine on your network. However, if the ip address is on a completely different network range, then should work fine and it effectively means that your machine and your machine alone is on a second network. –  sgmoore Apr 16 '10 at 18:48
    
See superuser.com/a/768375/144375 for instructions to do so. –  Amir Ali Akbari Oct 20 at 7:28

The best way to do this is to install a loopback network adapter and assign it the desired IP address. The machine will consider itself as "owning" that address, but it won't be visible on the actual network. For that matter, the machine won't even need to be connected to a real network.

http://support.microsoft.com/kb/839013

You may have routing issues for the subnet surrounding the address you're hijacking by this method. This can be overcome by adding a persistent route for the affected subnet with a cheaper metric so that only the specific IP you want is routed to the loopback adapter, while the rest of that subnet is routed out to the real network.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/route.mspx?mfr=true

You can also crank down the subnet mask so that only a handful of addresses are affected, for example using subnet mask 255.255.255.252 which will be a block of only 4 IP addresses. As long as your machine doesn't need to contact any outside hosts at any of those 4 IPs in the block, it will suffice without messing with persistent routes.

Oh, and of course you'll need your web server to be listening on that IP address. Setting it to listen on "all" addresses should suffice.

share|improve this answer

You can install IIS and create more directories so you can have multiple websites.

How to install IIS 7

share|improve this answer

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.