Netsh Port Forwarding from LAN IP(192.168.xx.xx)-Port(1883) to Local IP(127.0.0.1)-Port(1883) for Mosquitto MQTT Broker

Netsh Port Forwarding from LAN IP(192.168.xx.xx)-Port(1883) to Local IP(127.0.0.1)-Port(1883) for Mosquitto MQTT Broker

Introduction

Port forwarding is a technique of redirecting network traffic from a specific port on one network node to another network node. This technique is often used to allow external users to access services provided by an internal network, such as a web server or a game server. In this blog post, we will discuss how to use the netsh command to forward traffic from a local port to another local port on Windows operating systems.

Setting up Port Forwarding using Netsh

Netsh is a command-line utility that allows users to configure and monitor Windows networking services. To set up port forwarding using netsh, the user must first open the command prompt as an administrator. Once the command prompt is open, the user must enter the following command:

netsh interface portproxy add v4tov4 listenport=[local port number] listenaddress=[local IP address] connectport=[local port number] connectaddress=[local IP address]

In this command, the "listenport" parameter specifies the local port number that the traffic will be forwarded from, and the "connectport" parameter specifies the local port number that the traffic will be forwarded to. The "listenaddress" and "connectaddress" parameters specify the local IP addresses associated with the respective ports.

netsh interface portproxy add v4tov4 listenaddress=192.168.1.7 listenport=1883 connectaddress=127.0.0.1 connectport=1883
Checking Port Forwarding Status using Netsh

To check the status of the port forwarding setup, the user can enter the following command:

netsh interface portproxy show all

This command will display a list of all the current port forwarding rules. The user can check whether the rule they just set up is present in the list and whether it is correctly configured.

Removing Port Forwarding using Netsh

To remove a port forwarding rule, the user can enter the following command:

netsh interface portproxy delete v4tov4 listenport=[local port number] listenaddress=[local IP address]

This command will remove the port forwarding rule associated with the specified local port and IP address.

netsh interface portproxy delete v4tov4 listenaddress=192.168.1.7 listenport=1883 
 
Conclusion

In conclusion, netsh is a powerful command-line utility that allows users to set up, monitor, and remove port forwarding rules on Windows operating systems. By using the commands described in this blog post, users can easily configure their network to forward traffic from one local port to another local port. This technique can be useful for a variety of applications, such as hosting game servers or remote desktop access.

Comments