How can I specify IP and ports for a hostname in the Windows hosts file?
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
Solution 1:
Simply use IP addresses without ports. Example:
192.168.2.50 example.com
Then, to access 192.168.2.50:5555 from your browser (or other program):
http://example.com:5555/
The hosts
file can be found at:
Linux /etc/hosts
Windows: C:\Windows\System32\drivers\etc\hosts
Solution 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";
}