Skip to content

Port-forwarding with netsh on Windows

Sometimes you run a program on your Windows computer that binds it’s ports to only the localhost address (127.0.0.1). Usually you can configure the program to also bind to other interfaces. But sometimes you can’t reconfigure it or you don’t find the configuration options, because it’s poorly documented. In some situations there are also good security reasons why the program only binds to the localhost. So I also have to tell you:

WARNING:

Most times programs bind to 127.0.0.1 is because of security reasons. Thus you should take care when you want to make a port available to other computers in the network and you should not do it unless you know what you are doing. Each port that is accessible from the “outside” is an attack vector that hackers will use.

You can use the information I provide here at your own risk.

Make a local port available on a public interface

Let’s assume there is a service running on 127.0.0.1:12345 and you want to make it available to other computers in the network. First you have to find out the address that your computer has in the network you want to make the local port accessible to.

You can find it out with ipconfig

> ipconfig
....
Ethernet-Adapter Ethernet xxx:
   ...
   IPv4-Adress . . . . . . . . . . . : 192.168.178.23
   ...
....

In the example above my computer has the address 192.168.178.23.

Now I can add a port forwarding, let’s say from port 192.168.178.23:54321 to 127.0.0.1:12345 by executing the following netsh command in a command prompt with administrator priviledges.

netsh interface portproxy add v4tov4 listenport=54321 listenaddress=192.168.178.23 connectport=12345 connectaddress=127.0.0.1

I can also remove the port forwarding using

netsh interface portproxy delete v4tov4 listenport=54321 listenaddress=192.168.178.23

If you don’t know the ports that are forwarded you can also list all.

netsh interface portproxy show v4tov4

Leave a Reply

Your email address will not be published. Required fields are marked *

 

GDPR Cookie Consent with Real Cookie Banner