port forwarding in windows
Asked Answered
M

3

305

I have two network board in my pc:

The main one has the local ip -> 192.168.1.111 The secondary ones has the local ip -> 192.168.0.200

The main one has internet connection and the second one is connected to a device with the IP 192.168.0.33, it has a http server in port 80.

I have an apache-server in the main connection (port 4422), and I can access from anywhere, what I want now is when I detect a connection from 4422 i want to redirect this connection to 192.168.2.33:80

How can I do this with windows?

Moldboard answered 17/7, 2012 at 15:22 Comment(1)
More information can be found here. technet.microsoft.com/en-us/library/cc731068(v=ws.10).aspxHydrometeor
M
617

I've solved it, it can be done executing:

netsh interface portproxy add v4tov4 listenport=4422 listenaddress=192.168.1.111 connectport=80 connectaddress=192.168.0.33

To remove forwarding:

netsh interface portproxy delete v4tov4 listenport=4422 listenaddress=192.168.1.111

Official docs

Moldboard answered 18/7, 2012 at 6:23 Comment(11)
Just be sure to have IPv6 installed. Accordingly to this MS KB article, netsh need some IPv6 libraries to configure the port proxy feature.Kall
Yes, netsh portproxy need ipv6 libraries even only use v4tov4Hornsby
Also, you can do cleanup using netsh interface portproxy reset or netsh interface portproxy deleteNike
Thanks! Does this persist after session logout or rebooting, or do I need to automate this?Linter
I tried using this technique, and while it worked, it was extremely slow. Instead. I found a utility called PassPort (sourceforge.net/projects/pjs-passport) that does the same type of port forwarding bound to a specific NIC, but does not have the performance issues of netsh. It installs and runs well on Win2008SvrR2.Blakeney
The command above didn't work for me on Windows7 nor on Windows Server 2003. I had to specify protocol=tcp parameter too. Full command: netsh interface portproxy add v4tov4 listenport=4422 listenaddress=192.168.1.111 connectport=80 connectaddress=192.168.0.33 protocol=tcpCharbonnier
NOTE that this only works on TCP, so no luck if you wanted to forward UDP traffic.Hynda
Don't forget to allow the connection in firewall: netsh advfirewall firewall add rule name="any_name" protocol=TCP dir=in localip=listen_address localport=listen_port action=allowCompetent
I tried forwarding to connectaddress=127.0.0.1 which didn't seem to be possible to get to work at all. Forwarding to the Ethernet's IP solved it for me! Found some hints about that here. Also make sure you have the Forwarding flag enabled on the listening interface. See this article for more info.Sutra
This is actually a proxy, not port forwarding - i.e. the originator is completely hidden from the receiver.Rivers
the term of port-forwarding seems to be used very lightly here.Facelifting
B
17

nginx is useful for forwarding HTTP on many platforms including Windows. It's easy to setup and extend with more advanced configuration. A basic configuration could look something like this:

events {}

http {
     server {

        listen 192.168.1.111:4422;

        location / {
            proxy_pass http://192.168.2.33:80/;
        }
     }
}
Baer answered 14/4, 2016 at 12:12 Comment(5)
This is a good solution for HTTP forwarding, but only for HTTP forwarding (with all its caveats, e.g. websockets need additional config). For HTTPS forwarding or other arbitrary protocols (e.g. RDP) it's mostly useless.Bartley
That said, it's an incredibly good solution for HTTP forwarding, so I'm glad it's here.Netty
Why is that? You can stream forward whatever you like, including httpsCahan
@uli which settings do you tolking about ... It will be usefull to shareQualified
@UliKöhler Nginx is a tool to decouple TCP connections. You can use it for HTTP, HTTPS, AMQP, WebSockets, whatever. It's used internally by tools all over for redirecting and managing general TCP connectivity. So, this is the correct solution. See also netfxharmonics.com/2016/03/nginxDulcet
W
8

I've used this little utility whenever the need arises: http://www.analogx.com/contents/download/network/pmapper/freeware.htm

The last time this utility was updated was in 2009. I noticed on my Win10 machine, it hangs for a few seconds when opening new windows sometimes. Other then that UI glitch, it still does its job fine.

Wolk answered 4/9, 2018 at 21:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.