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

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.: and

share|improve this question

migrated from 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, 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

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("")){
    oSession.bypassGateway = true;
    oSession["x-overrideHost"] = "";
share|improve this answer
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:  SomeAddress

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

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

You must log in to answer this question.