hosts file is for host name resolution only
- The browser, in the absence of directly specifying the port: i.e.
<hostname>:<port>, defaults to port
###Typical Problem Scenario###
- applications typically set their servers to the same default ip address
localhost (defined in the hosts file).
- to avoid collision between possibly other existing/running servers, the application typically allows you to change the port, but not the ip address.
2a. If you could change the servers ip address to another in the loopback reserved address space
127.0.0.0/8, then you probably wouldn't be attempting to set ports in the hosts file.
You can work around this using Windows included Networking tool
netsh as a port proxy.
| <--browser defaults to port 80
| <--Hostname resolution by Hosts File
| <--Link by netsh Utility
- Start your server on
- Add the "local DNS" in the hosts file as a new line
- Any free address in the network
127.0.0.0/8 can be used.
- Note: I am assuming
127.65.43.21:80 is not occupied by another service.
- You can check with
netstat -a -n -p TCP | grep "LISTENING"
- add the following network configuration with netsh command utility
netsh interface portproxy add v4tov4 listenport=80 listenaddress=127.65.43.21 connectport=8081 connectaddress=127.0.0.1
- Access the server at
- These commands/file modifications need to be executed with Admin rights*
- netsh portproxy needs ipv6 libraries even only to use v4tov4, typically they will also be included by default, otherwise install them using the following command:
netsh interface ipv6 install
You can see the entry you have added with the command:
netsh interface portproxy show v4tov4
You can remove the entry with the following command:
netsh interface portproxy delete v4tov4 listenport=80 listenaddress=127.65.43.21
###Links to Resources:###
Note: this answer is a duplication of my answer discussed in this similar question/answer on stackoverflow.