PIA Port Forwarding on OpenWRT: PIA Setup Using OpenVPN

1 Mar 2025 2 min read No comments Networking
Featured image

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:

  1. Install OpenVPN on OpenWRT
    If you haven’t already, install OpenVPN by running:shCopyEditopkg update opkg install openvpn-openssl luci-app-openvpn Then, restart OpenWRT.
  2. Download PIA Configuration Files
    You need PIA’s OpenVPN configuration files. You can get them from:

    Extract the .ovpn file for your preferred NextGen server and place it in /etc/openvpn/.

  3. Modify OpenVPN Configuration for OpenWRT
    Open the .ovpn file and add:shCopyEditauth-user-pass /etc/openvpn/userpass.txt Then, create the userpass.txt file with your PIA credentials:shCopyEditecho "USERNAME" > /etc/openvpn/userpass.txt echo "PASSWORD" >> /etc/openvpn/userpass.txt chmod 600 /etc/openvpn/userpass.txt
  4. Start OpenVPN on OpenWRT
    Run:shCopyEdit/etc/init.d/openvpn restart Verify 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.

  1. 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.
  2. 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.
  3. Verify Port Forwarding
    You can check if the port is open by using:shCopyEditnc -zv YOUR_PUBLIC_IP PORT Or 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.

Need a Prius or hybrid shop?

Search the Verified Prius & Hybrid Shop Directory by category.