298

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?

user1256477
  • 10,763
  • 7
  • 38
  • 62

3 Answers3

605

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

gavenkoa
  • 45,285
  • 19
  • 251
  • 303
user1256477
  • 10,763
  • 7
  • 38
  • 62
  • 23
    Just be sure to have IPv6 installed. Accordingly to this [MS KB article](http://support.microsoft.com/kb/555744), netsh need some IPv6 libraries to configure the port proxy feature. – Renan Mozone Mar 30 '13 at 05:26
  • Yes, netsh portproxy need ipv6 libraries even only use v4tov4 – diyism Jul 27 '13 at 07:48
  • 21
    Also, you can do cleanup using `netsh interface portproxy reset` or `netsh interface portproxy delete` – patrikbeno May 12 '15 at 13:39
  • 3
    Thanks! Does this persist after session logout or rebooting, or do I need to automate this? – jjmontes Oct 07 '15 at 19:21
  • 7
    I tried using this technique, and while it worked, it was extremely slow. Instead. I found a utility called PassPort (http://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. – James L. Oct 10 '15 at 22:03
  • 18
    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=tcp` – alwi Sep 15 '16 at 10:17
  • 5
    NOTE that this *only works on TCP*, so no luck if you wanted to forward UDP traffic. – user276648 Dec 13 '16 at 07:13
  • 3
    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=allow` – Borg8 Jun 07 '17 at 18:22
  • 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](https://social.technet.microsoft.com/Forums/ie/en-US/e794910b-9325-4ef9-be82-3e57925e6586/problem-with-adding-a-portproxy-using-netsh?forum=winservergen). Also make sure you have the `Forwarding` flag enabled on the listening interface. See [this article](https://kb.iweb.com/hc/en-us/articles/230239648-Activate-IP-Forwarding-on-the-physical-server-for-a-specific-network-interface) for more info. – Anttu Sep 15 '17 at 07:05
  • This is actually a proxy, not port forwarding - i.e. the originator is completely hidden from the receiver. – Egor Pavlikhin Feb 01 '18 at 10:47
  • the term of port-forwarding seems to be used very lightly here. – Sajuuk May 20 '19 at 11:24
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/;
        }
     }
}
Jonas Lundgren
  • 1,031
  • 11
  • 17
  • 18
    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. – Uli Köhler Jul 09 '16 at 01:19
  • 2
    That said, it's an incredibly good solution for HTTP forwarding, so I'm glad it's here. – Casey Apr 11 '17 at 22:16
  • Why is that? You can stream forward whatever you like, including https – user1156544 Jun 04 '18 at 13:46
  • @uli which settings do you tolking about ... It will be usefull to share – user3787216 Nov 20 '18 at 07:19
  • 2
    @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 https://netfxharmonics.com/2016/03/nginx – David Betz Jan 15 '19 at 15:45
7

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.

voon
  • 763
  • 8
  • 13