23 May 2012

Port forwarding on Windows computers

If you want to forward a incoming port to another computer, there’s a simple command to do this:

netsh interface portproxy add v4tov4 listenport=25 listenaddress=0.0.0.0 connectport=25 connectaddress=192.168.1.200

This command will “install” a SMTP server in one second. Nice thing is, that this port forwarding remains active even after restarting your computer.

To view all active forwards, use the following command:

netsh interface portproxy show all

To delete all active forwards or to delete one of those, use one of the following commands:

netsh interface portproxy reset
netsh interface portproxy delete v4tov4 listenport=25 listenaddress=0.0.0.0

image

Not so nice thing is, that you cannot use 127.0.0.1 as connectaddress. This might be necessary when you want to publish your unknown service to another port. Also UDP cannot be forwarded. To verify, that a port is actually listening or forwarding you can use netstat:

netstat -ano | findstr :25

To view what is the process name using that port (XXX is process ID):

tasklist | findstr XXX

image


As an alternative you can use PassPort application http://sourceforge.net/projects/pjs-passport. It runs also on Windows XP, can forward UDP, use 127.0.0.1 as a destination and is graphical utility.

image

17 comments:

  1. Obrigado por compartilhar seu conhecimento, as informações foram uteis para mim.

    ReplyDelete
  2. Obrigado!!!! thanks!!!!

    ReplyDelete
  3. Hi,
    A little help needed under Win XP. I have a pc with two net cards: one is for outer network another is for internal network. PC via internal network card is connected with another machine,ip addresses: 192.168.5.2 (for this machine) and 192.168.5.1 for another machine. I need to connect to the machine that is in internal network via vpn. For that i am using teamviewer for vpn adapter. On the main pc i am trying to forward port 102 192.168.5.2==>192.168.5.1. netsh interface portproxy add v4tov4 listenport=102 listenaddress=0.0.0.0 connectport=102 connectaddress=192.168.5.1 works as charm on win7, but can't make it working on win xp (firewall is off). Any ideas what am i doing wrong? :|

    ReplyDelete
    Replies
    1. As an alternative you can use PassPort application. Netsh is not good for port forwarding on Windows XP

      Delete
    2. Hey Rauno, thanks for so quick reply.

      Delete
  4. Netsh didn't work for me. But a windows port of rinetd worked great
    http://codewut.de/Port-Redirection-with-Windows

    ReplyDelete
    Replies
    1. Please read my article carefully. Netsh works ok, if you have Windows Vista/7/8. If you have earlier version of windows, then use PassPort application. Link to that application is in the article. There are hundreds of port forwarding apps. I recommend this one, because it can also run as a service.

      Delete
  5. It works perfectly fine on Windows XP SP3, You need to install IPV6 for it to work tho.

    netsh interface portproxy add v4tov4 listenport=25 connectport=25 connectaddress=192.168.1.200

    you do not need a listen address unless you want to specifically have a certain nic port forward.

    ReplyDelete
    Replies
    1. Nice to hear those tips. Maybe I test it sometimes.

      Delete
    2. netsh int ipv6 install

      and netsh int ipv6 uninstall

      Delete
  6. on windows 2008 R2 install and unistall are not valid options for
    netsh int ipv6 [ install | uninstall ]

    ReplyDelete
  7. does any one know how to trouble shoot why a portproxy command works fine on one windows 2008 R2 sp1 server and not another identical server, netstat showing the port not binding to MS Loopback adapter IP on one server but not the other. below you can see the portproxy same on both servers but only binding to 172.16.16.1 on one server.
    c:\>netsh interface portproxy show v4tov4
    Listen on ipv4: Connect to ipv4:
    Address Port Address Port
    --------------- ---------- --------------- ----------
    172.16.16.1 445 172.16.16.1 44445
    c:\>netstat -an | find ":445"
    TCP 172.16.16.1:445 0.0.0.0:0 LISTENING
    VS.
    C:\>netsh interface portproxy show v4tov4
    Listen on ipv4: Connect to ipv4:
    Address Port Address Port
    --------------- ---------- --------------- ----------
    172.16.16.1 445 172.16.16.1 44445
    C:\>netstat -an | find ":445"
    TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
    TCP [::]:445 [::]:0 LISTENING
    ** THIS SECOND SERVER DOESN'T WORK **

    ReplyDelete
  8. Obrigado! Thankyou, this small wisdom helped me a lot!

    ReplyDelete
  9. Works great on Windows 2012 -- thanks! Tip: make sure to enable the port in the firewall too.

    ReplyDelete
    Replies
    1. To open a specific port on windows firewall, you can use this tip http://raunomagi.blogspot.com.ee/2015/08/allow-specific-port-through-windows.html

      Delete