Before diving into an example, lets recap. We know IIS is bound to port 80 and web browser applications use HTTP over port 80. This means that by default, making an HTTP request from a browser to a host (IP) using IIS as a web server, IIS will serve the request.
Like many web servers, IIS can host multiple websites each with unique an IP. It is also able to host multiple web sites under the same IP. This is because IIS has a way to assign a hostname to a web site. This way it knows which web site to map the request.
When making a request to IIS from a web browser, the IP and the port number determines where to send the request. The web browser determines which server to connect to by resolving the hostname to an IP. using dedicated Name servers (NS).
Once the URL is resolved and a connection to the target server is established, the application bound to the port and will handle request (port 80 for web browsers). The web browser will then differentiate the request based on the host header that comes as part of the request.
Demo – mapping host name to application
Using a combination of host file and netsh, you can associate a hostname to applications. We will be using a locally hosted application for an example.
First, edit the host file to direct host name to local traffic:
# edit host file to include the host entry
Followed by using netsh to forward port 80 (handling HTTP request from browsers) to the port your application is bound to.
# netsh: Adding port forwarding rule using netsh netsh interface portproxy add v4tov4 listenport=80 connectaddress=127.0.0.1 connectport=[application_port] listenaddress=127.0.0.1 # OR netsh interface portproxy add v4tov4 listenport=[application_port] connectport=80 connectaddress=127.0.0.1 protocol=tcp # netsh: Show registered rule netsh interface portproxy show all # netsh: Delete registered rule netsh interface portproxy delete v4tov4 listenport=[port_to_delete] listenaddress=[ip_to_delete]