This Go application provides an intuitive way to manage port forwarding and firewall rules on Windows, making it easy to expose local application ports within your local network. It automates the otherwise cumbersome process of using netsh
commands to enable port forwarding, ensuring a smoother experience for developers and system administrators.
When working with applications that expose ports (e.g., Docker containers, web servers, or custom services), it’s common to face challenges when trying to access these services from other devices on the same network. Windows does not natively support dynamic or persistent port forwarding rules through a GUI, requiring manual configuration of netsh
commands and firewall rules every time.
This app was built to solve the following issues:
- Access Exposed Ports from Other Devices: Enable seamless access to local services (e.g.,
localhost:6300
) from other devices in the network (e.g.,192.168.0.230:6300
). - Avoid Manual Configurations: Simplify repetitive
netsh
and firewall configuration steps. - Dynamic and Persistent Rules: Allow dynamic creation and management of forwarding rules that persist across reboots.
- Centralized Management: Provide a user-friendly interface to manage port forwarding and firewall rules without relying on multiple tools or scripts.
-
Add Port Forwarding Rules:
- Dynamically forward traffic from a specific IP (
listen address
) and port (listen port
) to another IP (connect address
) and port (connect port
). - Automatically create corresponding firewall rules to allow traffic for forwarded ports.
- Dynamically forward traffic from a specific IP (
-
Remove Port Forwarding Rules:
- Easily clean up forwarding rules and associated firewall rules from the app.
-
List Existing Rules:
- View all active port forwarding and firewall rules in a centralized interface.
-
Simple UI:
- A lightweight, browser-based interface built with Go and
htmx
for easy management.
- A lightweight, browser-based interface built with Go and
-
Hidden Operation:
- Can run as a background process or startup application without requiring a visible console window.
- Port Proxy Rules:
- Uses the
netsh interface portproxy
command to add, delete, and list port forwarding rules.
- Uses the
- Firewall Rules:
- Automatically creates or removes firewall rules using
netsh advfirewall
to ensure traffic is allowed for forwarded ports.
- Automatically creates or removes firewall rules using
- Database:
- Tracks all rules in a local SQLite database to provide persistence and easy retrieval.
- Go 1.20 or higher (for building the application).
- Windows 10/11 (or a compatible version with
netsh
available). - Admin Privileges: Required to create port proxy and firewall rules.
git clone https://github.com/pieeee/windows-port-forwarding.git
cd windows-port-forwarding
go build -o port-forwarding.exe
port-forwarding.exe
By default, the app runs on http://localhost:2233
. Open this URL in your browser to manage port forwarding rules.
- Open the app at
http://localhost:2233
. - Fill in the required fields:
- Rule Name: A descriptive name for the rule.
- Listen Address: The IP address to listen for incoming traffic (default: local machine's IP).
- Listen Port: The port to forward traffic from.
- Connect Address: The destination IP address (default:
127.0.0.1
). - Connect Port: The port to forward traffic to.
- Click Add Rule to create the rule.
- View all active port proxy and firewall rules in the table on the main page.
- Click the Remove button next to a rule to delete both the port proxy and firewall rule.
To automatically start the app at system boot, add the executable to the Startup Folder:
- Press
Win + R
and type:shell:startup
- Copy the
port-forwarding.exe
file to this folder.
- Backend: Go with
netsh
commands for port proxy and firewall management. - Database: SQLite for persistent rule storage.
- Frontend: Minimal HTML UI with htmx for dynamic updates.
- Port Forwarding: Uses
netsh interface portproxy
for traffic redirection. - Firewall Rules: Configures Windows Firewall automatically for each port forwarding rule.
- Local Network Only: This app is designed for managing ports within the local network (LAN).
- Admin Rights Required: Creating port proxy and firewall rules requires administrative privileges.
- System Tray Integration: Add a tray icon for quick access and notifications.
- TLS Support: Secure the web interface with HTTPS.
- Cross-Platform Support: Extend functionality to Linux and macOS.
- Advanced Firewall Rules: Add options for IP ranges and protocols.
Contributions are welcome! Feel free to open issues or submit pull requests for improvements or new features.
This project is licensed under the MIT License. See the LICENSE file for details.