New PIA Port Forwarding API
Hi everyone!
We've recently introduced a new port forwarding API. This one's simpler, more reliable, and will be replacing the port forwarding API all of you fine folks currently use.
Here is a shell script that retrieves a port using this new API:
https://privateinternetaccess.com/installer/port_forwarding.sh
To run this script, simply download, make sure it has the correct permissions, and then you should be free to run it. Or, these commands in your terminal:
wget https://privateinternetaccess.com/installer/port_forwarding.sh chmod +x port_forwarding.sh ./port_forwarding.sh
Essentially, to use this API you send a request to the URL below, where client_id is a unique 256-bit ID in Base36 format:
http://209.222.18.222:2000/?client_id=$client_id
For an easy way to calculate the client ID, take a look at the script above.
Once you've sent this request, the API should return json containing the port number: {"port":49645}
Then, this port should be available for you to use!
Keep in mind that this new API will be replacing the old one, and that the old API located at vpninfo/port_forward_assignment will be discontinued sometime soon.
I've also got some considerations to remember while using this API:
- This request is handled locally by the gateway you're connected to.
- You can only request one port per connection.
- With the new API, you no longer need to 'poll' the API periodically to keep the forwarded port open. As such, you only need to query the API once to open up the port.
- When a port is forwarded, you will not be able to connect to that port from the public IP that initiated the OpenVPN connection.
To confirm port forwarding is working, retrieve a port using the API and run a command like this to listen on it:ncat -l <port>
After this, you can use an online testing site to confirm that port's open on your VPN gateway.
Hopefully this lets you update your scripts to use the new API and interoperate nicely with it! For more guidance on error-handling, feel free to dig into the script above, and if there are any issues feel free to post in here and I can take a look.

Comments
If you send
{"cmd": "status"}to127.0.0.1:31743over plain TCP it will return you the PIA status, including the forwarded port. I think that's the only way to do it while using the PIA client.Alternatively, if you pass the same arguments to OpenVPN as the PIA client does you should be able to get the same speeds and then have much more flexibility for scripting.
None of them gave the same results as the client. I have a 75/75 connection, with the client I usually see 65/65, and with OpenVPN I've never seen more than 30/30. Weird, huh? Looking at the running client, I see it's using UDP on port 500, which isn't even listed in your table
curl: (52) Empty reply from server. The cURL commands I've tried are/usr/bin/curl http://127.0.0.1:31743 -d '{"cmd": "status"}' -H "Content-Type: application/json" -X POSTand/usr/bin/curl http://127.0.0.1:31743 -d '{"cmd": "status"}'Currently I'm parsing the pia_manager.log for the port but it isn't 100% accurate so I'd love to be able to query the client directly. Thanksecho '{"cmd": "status"}' | nc 127.0.0.1 317431. Modify the script, since i couldn't get the sha256sum command to run
Download https://privateinternetaccess.com/installer/port_forwarding.sh
Edit only section or :port_forward_assignment( ) to something like this, (remove client id generation if statements and specify client_id by yourself)
# Edit only this part of the script
port_forward_assignment( )
{
echo 'Loading port forward assignment information...'
json=`curl "http://209.222.18.222:2000/?client_id=YOURsha256HERE" 2>/dev/null`
if [ "$json" == "" ]; then
json='Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding'
fi
echo $json
}
# Don't edit script below
The SHA sum should be generated with some unique characteristics
http://www.xorbin.com/tools/sha256-hash-calculator
or on windows use CMD , certUtil -hashfile \some_personal_file.txt SHA256
place it in json command and save script.
It should look something like this
json=`curl "http://209.222.18.222:2000/?client_id=9b7ecc6eeb83abf9ade10fe38865df4499be3568dcc507ae2ec3b44989cb0093" 2>/dev/null`
2. Use WinSCP to transfer the script to your router, chmod (F9 change permission to XXX)
3. From the terminal putty or built in from WinSCP , run:(make sure y are in right dir ect. )
sh /port_forwarding.sh
Loading port forward assignment information...
{"port":XXxXX}
Note: This must be done 2 min after router reboot or VPN connection is established and problems must be investigated from
1. DD-WRT Port forwarding
2. PC firewall i.e Norton Internet Security software ect.
3. DD-WRT router is behind a 1st primary router in network ect.
I have an Apache web server running on Linux Debian 8. OpenVPN is installed and configured.
PIA VPN TCP connection is established with a server port 80 open.
The script Portforwarding.sh I also use.
If I now from the Internet my webserver via the public VPN IP reach I can only do this if I enter the "VPN Public IP:Port" and the web server on the Portforwarding.sh port list.
But I would like to reach the web server on port 80 without having to enter the port extra behind the IP.
Who has a solution?
I only ask because this morning the old and new way to get port forwarding isn't working.
I've done normal troubleshooting - deleting plists, even reinstalling the OS. All but a fresh install. I believe there is a setting somewhere that is preventing Messages from receiving incoming info.
Please help! I've been going back and forth with Apple Senior Support staff since October.
Thanks!
For the life of me I can NOT get the forward to work in iptables. Well I get a correct response that the new PIA script that a port has been forwarded and provided a port number.
Can anyone test this with 1194 OpenVPN? I notice the new setup for DD_WRT OpenVPN uses 1198 for the PIA server port. I wonder if port 1194 has been neglected and does not forward ports with this new forward script.
I'll attempt to try this new method on my older QNAP at some point, but would like to have an idea of exacrly how much time I've got so I can plan it in.
Also, any plans to change the 2 minute limit? I'm sure i'm not alone in saying majority of us leave our connections on, and for those of us using private trackers we're obviously trying to seed back. If the connection drops or resets for whatever reason it can be hours before I've noticed it. The old way I just SSH in, run the script again, get my port number and change it.
This new way looks as if I'm going to have to also go into my QNAP Web gui, disconnect, reconnect, then run the script. Which is anything but simpler, especially if I'm not at home.
Maybe someone with some serious magic can help with the curl limitation on DD-WRT. I think there are ways to us nc instead of curl.
I connect to CA Toronto. I ran the script within two minutes of connecting and got a proper port forward response. I use that port and place it in the two commands below where xxxxx is the port and PCIP is the LAN IP address of my Windows PC connected to DD-WRT.
The iptables rule I must run after running the PIA script in DD-WRT was this:
Port 22222 is something I use contantly so I don't have to modify the port on my PC software. I did not have to use a FORWARD rule.
I then run nc -l xxxxx on my Windows PC (withing Cygwin)
and use the website: http://www.yougetsignal.com/tools/open-ports/
The nc command should exit and the website should report that the port is open.
I did the same testing on a Raspberry PI 3 and only had to issue the INPUT iptables rule above. However, the nc command was "nc -l -p xxxxx". The difference is that my Raspberry PI does not have NAT or act as a router in anyway. I will at some point turn it into a full router and have to issue the PREROUTING rule from above. I will say that I was surprised at how fast the PI 3 was. I could get a full 50mbps over the VPN. Bye bye DD-WRT...