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.

I want to specify host names with two different ports in the Windows hosts file.

Is there a way to do it? Or is it not allowed by Windows itself?

I have been wasting my time searching for the solution for the last 8 hours.

Is it possible to specify ports in the host file, hosts? E.g.: 127.0.0.1:80 and 127.0.0.1:9211

share|improve this question

migrated from stackoverflow.com Feb 21 '10 at 18:45

This question came from our site for professional and enthusiast programmers.

    
The HOSTS file only associates names with IP addresses, not IPs+port(s). Do check superuser.com, however, by describing more of the specifics of what you are trying to do (is this for a web server etc. etc.) as there are many ways to achieve this type of mapping, but always depending on specifics at hand. –  mjv Feb 21 '10 at 18:44

2 Answers 2

You cannot associate a port number with a hostname mapped to an IP in the hosts file. You can achieve this with Fiddler though using FiddlerScript:

if (oSession.HostNameIs("somesite.com")){
    oSession.bypassGateway = true;
    oSession["x-overrideHost"] = "1.2.3.4:8080";
}
share|improve this answer
1  
Nice suggestion for tech users. Just to clarify, 1) First install Fiddler 2) Then open it and go to Rules Menu and pick Customize Rules option ( or press Ctrl + R on windows ). This will open a JS file in notepad. 3) Find static function OnBeforeRequest and paste the script suggested by @John inside its body. Also HostNameIs will not work, it should be HostnameIs. Hope this helps. –  eFriend Aug 13 '13 at 7:40

Yes, simple use ip addresses without ports. Example:

192.168.2.50  SomeAddress

Then, to access 192.168.2.50:5555 from your browser(or other program):

http://SomeAddress:5555/
share|improve this answer
    
Thanks, that solved my problem! –  Aamer Alduais Mar 12 '13 at 7:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.