Monday 16 September 2013

Port Forwarding / Port Mapping on Windows


As a long time friend of linux’s itables command, I mistakenly assumed that trying to port forward on Windows Server 2008 R2 would be just as easy. After quite a long while of searching I was able to determine the correct command; through use of netsh on the command line, it is easy to map incoming TCP traffic from one port to another port.
In my scenario, I needed to have an SSL connection initiated on a port other than 443 on the same machine, but handled by a service listening on port 443. To do this, the following command is entered on the command line; in this example, port 12345 is used as the initiating port.

C:\Users\Administrator> netsh interface portproxy add v4tov4 listenport=12345 listenaddress=192.168.1.1 connectport=443 connectaddress=192.168.1.1

Port 12345 is mapped to port 443 on the same machine. To have the traffic transferred to another machine, change the ip address for the connect address to the desired ip address.

C:\Users\Administrator> netsh interface portproxy add v4tov4 listenport=80 listenaddress=192.168.1.1 connectport=80 connectaddress=10.210.10.10

Source  IP and Port:192.168.1.1:80
Destination IP and Port: 10.210.10.10:80

C:\Users\Administrator> netsh interface portproxy add v4tov4 listenport=80 listenaddress=200.100.50.25 connectport=80 connectaddress=10.210.10.10

Source  IP and Port:200.100.50.25:80
Destination IP and Port: 10.210.10.10:80

If we want to delete particular Rule

C:\Users\Administrator> netsh interface portproxy delete v4tov4 listenport=80 istenaddress=192.168.0.25 protocol=tcp

C:\Users\Administrator> netsh interface portproxy delete v4tov4 listenport=80 listenaddress=200.100.50.25 protocol=tcp


If we want to reset all rules


C:\Users\Administrator> netsh interface portproxy reset


If we want to view all rules


C:\Users\Administrator> netsh interface portproxy show all



Ref:1
Open Port in windows firewall





No comments:

Post a Comment