How to Redirect Port in Microsoft Windows

Posted on

Introduction

This article is an article about doing a specific thing in Microsoft Windows. That thing is to redirect port from a specific port to another port. There are several purpose for redirecting port. One of the reason is to disguise the service using a default port to use another different port. Another reason is an usual reason. If it is a service running where the access to that service is through a web browser, then redirecting it port 80 will be very helpful. That is the case if the service itself is using a different port than port 80. Below is the illustration of it in the form of an image :

Solution

In order to achieve the above scenario, the following are the steps for implementing it :

1. Run the Command Line Interface or the Command Prompt in Microsoft Windows as Administrator. The following output in the command line will appear :

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>

2. After executing the above command, create a port to listen incoming request on port 80 and then redirect it to port 8080 by executing the following command :

netsh interface portproxy add v4tov4 listenaddress=IP_Address_Machine listenport=Port_For_Redirection connectaddress=IP_Address_machine connectport=Original_Port

So, using the above command pattern, the execution exist as follows with in this example, the IP Address of the server is 192.168.1.1 :

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>netsh interface portproxy add v4tov4 listenaddress=192.168.1.1 listenport=80 connectaddress=192.168.1.1 connectport=8080
C:\Users\Administrator>

3. Execute the following command to create a service that listens in port 80.

C:\Users\Administrator>netstat -ano | findstr :80
  TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       2392
  TCP    192.168.1.1:80         0.0.0.0:0              LISTENING       756
C:\Users\Administrator>

Another command pattern exist to check the service running for listening any incoming request to port 80 :

C:\Users\Administrator>tasklist | findstr 756
svchost.exe                    756 Services                   0     36,236 K
C:\Users\Administrator>

4. Last but not least, execute the following command to allow any incoming request to port 80 :

C:\Users\Administrator>netsh advfirewall firewall add rule name="Allow_AppServer_Port_80" protocol=TCP dir=in localip=192.168.1.1 localport=80 action=allow
Ok.
C:\Users\Administrator>

5. Finally, check the status of the redirect or the proxy port running after executing all of the previous steps using the following command :

C:\Users\Administrator>netsh interface portproxy show all
Listen on ipv4:             Connect to ipv4:
Address         Port        Address         Port
--------------- ----------  --------------- ----------
192.168.1.1     80          192.168.1.1     8080
C:\Users\Administrator>

As it appear in the above output, the result is very clear. There is a port listening on port 80 in a machine with the IP Address of 192.168.1.1. Any incoming request to that port will be redirected to the same machine but on a different port. That port is on port 8080.

Leave a Reply