Port forwarding on OpenWRT with Private Internet Access (PIA) VPN can be a bit tricky, especially when using OpenVPN. While PIA supports Next Generation Network servers with port forwarding, there’s limited documentation on how to set it up properly on OpenWRT.
This guide will help you understand how to enable PIA’s port forwarding feature on OpenWRT while routing all your traffic through OpenVPN.
Step 1: Setting Up PIA on OpenWRT
Before configuring port forwarding, you must have PIA VPN running correctly on your OpenWRT router using OpenVPN. Here’s how to do it:
- Install OpenVPN on OpenWRT
If you haven’t already, install OpenVPN by running:shCopyEditopkg update opkg install openvpn-openssl luci-app-openvpnThen, restart OpenWRT. - Download PIA Configuration Files
You need PIA’s OpenVPN configuration files. You can get them from:Extract the
.ovpnfile for your preferred NextGen server and place it in/etc/openvpn/. - Modify OpenVPN Configuration for OpenWRT
Open the.ovpnfile and add:shCopyEditauth-user-pass /etc/openvpn/userpass.txtThen, create theuserpass.txtfile with your PIA credentials:shCopyEditecho "USERNAME" > /etc/openvpn/userpass.txt echo "PASSWORD" >> /etc/openvpn/userpass.txt chmod 600 /etc/openvpn/userpass.txt - Start OpenVPN on OpenWRT
Run:shCopyEdit/etc/init.d/openvpn restartVerify the connection with:shCopyEditlogread -e openvpn
Step 2: Enabling Port Forwarding on PIA
Once OpenVPN is running with PIA, you can request a forwarded port from PIA’s API.
- Run the Port Forwarding Script
PIA provides a script to request a forwarded port:shCopyEditcurl -s "https://www.privateinternetaccess.com/api/client/v2/requestPort" \ -H "Authorization: Bearer YOUR_PIA_TOKEN"This will return a port number that you can use. - Manually Add Port Forwarding in OpenWRT
In OpenWRT’s LuCI interface:- Navigate to Network > Firewall
- Click Port Forwards and Add New Rule
- Set:
- Name: PIA Port Forward
- Protocol: TCP/UDP
- External Port: (Use the forwarded port from PIA’s API)
- Internal IP Address: Your LAN device
- Internal Port: (Same as external)
- Save and apply changes.
- Verify Port Forwarding
You can check if the port is open by using:shCopyEditnc -zv YOUR_PUBLIC_IP PORTOr use an online port checker tool.

Additional Notes
- PIA’s Port Forwarding Expiry:
The forwarded port changes periodically, so you need to re-run the script every so often. - Automating the Process:
There used to be PIA scripts that automated this, but they are outdated. You may need to run the curl command manually. - Alternative VPNs:
If PIA no longer meets your needs, check out Mullvad VPN, which offers better OpenWRT compatibility.
Conclusion
Setting up PIA port forwarding on OpenWRT with OpenVPN requires extra steps, but it can be done with some manual configuration. By requesting a port from PIA and adding firewall rules in OpenWRT, you can ensure your services are accessible while still benefiting from VPN security.
If you run into issues, checking PIA’s GitHub issues and Reddit forums for updates is always a good idea.


































