In Windows, you can use netsh to redirect traffic from one port to another with its portproxy option, which lets you redirect traffic from one server to another or from one connection to another. However, remember that the recommended approach is to use a reverse proxy configured with IIS for web applications.
On a Linux system, you can use iptables to do this. For example, the following article explains how to redirect port 587 to port 25, and for web applications, using a reverse proxy with a web server is also recommended (Reverse proxy with Apache).
This article explains how to redirect traffic from one port to another in an example scenario on a Windows server, along with some additional commands useful for this feature.
Information
Currently, the netsh interface port proxy feature only supports the TCP protocol.
Example scenario
In this example scenario, IIS is configured on the server and listening on the default port, 80 TCP (HTTP):
C:\Users\administrator>netstat -a -b | findstr 0.0.0.0:80
TCP 0.0.0.0:80 windows:0 LISTENING
C:\Users\administrator>curl -I localhost
HTTP/1.1 404 Not Found
Content-Length: 315
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Wed, 09 Nov 2022 21:50:50 GMT
Connection: close
Creating a portproxy
To create a portproxy that redirects all incoming traffic on a port—in this case, the server's port 81 TCP—to port 80 TCP, where IIS is listening, use the following command:
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=81 connectaddress=0.0.0.0 connectport=80Once the command has been run, the server will have an open connection on port 81 TCP:
C:\Users\administrator>netstat -a -b | findstr :81
TCP 0.0.0.0:81 windows:0 LISTENING
As a result, requests to this port will have all their traffic redirected to port 80 TCP:
C:\Users\administrator>curl -I localhost:81
HTTP/1.1 404 Not Found
Content-Length: 315
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Wed, 09 Nov 2022 22:08:45 GMT
Connection: close
Additional commands
To list all port proxies, you can run the following:
netsh interface portproxy show allTo list only IPv4 proxies:
netsh interface portproxy show v4tov4And to delete a portproxy, enter the listen information with the delete option:
netsh interface portproxy delete v4tov4 listenport=puerto listenaddress=direcciónThe following example would delete the connection on port 81 TCP created earlier:
netsh interface portproxy delete v4tov4 listenport=81 listenaddress=0.0.0.0Remember, if you have any questions about this or any other issue related to your Clouding servers, feel free to email soporte@clouding.io We're here for whatever you need. Get in touch!