CSIA 430 Linux Administration – Windows Local DNS and Port Forwarding


When testing network systems and services you often have to use the server’s IP address and port number, unless you have access to a DNS server and want to go through the trouble of creating new DNS entries for the server. While typing the IP address and port number isn’t a huge burden, testing things like virtual web servers may require using a DNS name to find the correct virtual web server. On Windows computers entries can be added to the \Windows\System32\drivers\etc\hosts file to set up DNS names. This is perfect for testing, as it’s simple and quick, and it only adds the DNS name on one computer, as opposed to adding the name(s) to a production DNS system where the name would be used by everyone using DNS or pretty much the entire Internet.

But one of the limits for using \Windows\System32\drivers\etc\hosts to resolve DNS names to IP addresses locally is that it can only be used for host names, there’s no way to add a port number. That is, you can add entries such as:

127.0.0.1 testWeb.org

But it won’t work if you add a port number such as:

127.0.0.1:8000 testWeb.org

Once again this isn’t a huge burden as it only requires adding the port number any time you type the URL. But if you really want to skip typing the port number there is a way. This can be done using a Windows utility called netsh which is a command line utility that will allow you to change the local network configuration, and make it possible to connect to a network port without typing it as part of the URL. The netsh utility comes loaded on Windows by default.

The Process for Using netsh to Redirect HTTP Packets to a Different Port

The following process can be used to configure the network on a Windows computer to simulate a network proxy server, and take any packets destined to specific host and forward them to a different network port.

  • Note the IP address and port number of the HTTP server the packets are being sent to. If port forwarding is being used this is the IP address and port of used on the host side of the connection, NOT the IP address and port on the server side. For example, if on the host you have a rule to forward packets from 127.0.0.1:8000 to 10.0.2.15:80 the IP address and port you want are 127.0.0.1:8000.
  • (This step must be done with Administrator rights.) Open the Windows Command Prompt program.
  • Use netsh to add the a network configuration rule by typing:
    • netsh interface portproxy add v4tov4 listenport=8000 listenaddress=127.0.0.1 connectport=80 connectaddress=127.0.0.1
  • To check to see if the rule was added use the following:
    • netsh interface portproxy show v4tov4
  • The rule can be removed using:
    • netsh interface portproxy delete v4tov4 listenport=8000 listenaddress=127.0.0.1

You should now be able to connect to the web server without adding the port number in the URL. That is, you can connect to 127.0.0.1:8000 by using the URL 127.0.0.1. If a DNS name has been set for the server in either big DNS or in the local Windows hosts file, you can also connect to the web server by just using the DNS name.

Note – netsh portproxy requires the IPv6 libraries even if you’re using IPv4 and v4tov4. The IPv6 libraries should be included by default, but if not they can be installed using: 

netsh interface ipv6 install


References: