New PIA Port Forwarding API

1235

Comments

  • If I already requested port forwarding when it expires? I'd like to create script and already "spoiled" two regions.

    Or how to retreive port number if I didn't write it down?
  • maaboo said:
    If I already requested port forwarding when it expires? I'd like to create script and already "spoiled" two regions.

    Or how to retreive port number if I didn't write it down?
    Reconnecting should be enough. You may end up with the same port number, or not, but that should work to test your script.

    Basically when you connect to a server, it (presumably because I haven't checked, there's other ways to do the exact same thing) spins up a temporary server for 2 minutes that, when hit, assigns you a port number, sets up the forwarding, returns the port to you and then turns itself off. The port forwarding then lasts until you disconnect.
  • Im gonna be leaving PIA to when my subscription is up.  I didnt think with a VPN provider u also needed to be some sort of code wizard in order to get port forwarding to work.

    Im off to NordVPN soon.
  • edited March 2018
    I installed the latest linux version v78, and I no longer get the port # in my tooltip. Is there a command I can run to get it for now? It was working fine in v76.

    The Tooltip just says: "Private Internet Access - You are connected (CA Toronto)"

    I am on Ubuntu 7.10

    I have restarted machine, tried other servers, toggled settings on and off.

    Also
    echo '{"cmd": "status"}' | nc 127.0.0.1 31743
    just hangs and never returns.
  • Hi Guys,

    I'm really new to this stuff, so if someone could simplify things it would be much appreciated.  I'm running Freenas with Transmission on it.  I have Merlin firmware on a Asus AC5300 router, with PIA running on the router. How do I go about using the port forwarding script to open up the port for transmission.  Do I run it from the Freenas shell,  what is the full script?  Thank you.
  • @pf1F Try connecting to another region or restarting the app a few times. There's some occasional issues with port forwarding still being investigated, but in the meantime just reconnecting and trying again usually works.

    Also, this way of querying the VPN daemon unfortunately no longer works. It has moved to a subscription based event bus, so those are now streamed instead of polled.

    @bigdog5000 For this to work you will need to run the script (or the curl command itself) on the router and then expand the script to also configure port forwarding on your router to redirect that forwarded port to the final destination, your Freenas. That tends to be somewhat messy and complicated and will be specific to Merlin in your case.

    I usually recommend to set up the VPN directly to the freenas machine and set the VPN up there so you don't have to do all the configuration.
  • I'm connecting my Synology NAS to the Sweden node, but when running the script I'm getting the error "Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding".
    Is it not possible to open ports on this region anymore? It worked with the old system.
  • edited March 2018
    I'm connecting my Synology NAS to the Sweden node, but when running the script I'm getting the error "Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding".
    Is it not possible to open ports on this region anymore? It worked with the old system.
    That's what Max is saying no longer works in response to my post.

    Max-P
    said:
    @pf1F Try connecting to another region or restarting the app a few times. There's some occasional issues with port forwarding still being investigated, but in the meantime just reconnecting and trying again usually works.

    Also, this way of querying the VPN daemon unfortunately no longer works. It has moved to a subscription based event bus, so those are now streamed instead of polled.

    I've tried it all except downgrading to v77 which I'm going to try now.

    Downgrading didn't work and I don't want to figure out why it doesn't launch right now or what I need to remove so v77 will work.
  • edited March 2018
    Ok I found the answer. There are TWO problems. The ubuntu tooltip isn't updating. AND Some of the servers are returning CONNECTION RESET BY PEER. If you turn on debugging logs and switch servers you'll find your port eventually by grepping the debug log:
    grep -a "Forwarded port:"  ~/.pia_manager/log/pia_manager.log

    should be the last one if you got one.


    It works for now! Hope this helps you fix the next build PIA.

    This tooltip on unbuntu always seems to have troubles. I would suggest throwing it on the SETTINGS LOCKED screen as well as a backup since these tooltips have gotten broken twice now.

  • @machinemade Port forwarding has temporarily been disabled on the Sweden region due to it having some connectivity issues. PF will be enabled again on that region once the connectivity issue is resolved (likely by switching datacenter). Sorry for the inconvenience. Please use another region in the meantime.
  • null
    Thank you for the feed back appreciated. I will try the router route. It's the reason I came to PIA. Trying to keep the main connection for streaming 4ks. These are on the local network using Plex. We have 3, tvs doing it. Goal is to try and keep our main resources for that. Once again thanks for the response.
  • Max-P said:
    @machinemade Port forwarding has temporarily been disabled on the Sweden region due to it having some connectivity issues. PF will be enabled again on that region once the connectivity issue is resolved (likely by switching datacenter). Sorry for the inconvenience. Please use another region in the meantime.
    I've tried Norway, Denmark and Finland, and I'm getting the same error on all of them.
    Are none of the nordic regions open to port forwarding?
  • Max-P said:
    @machinemade Port forwarding has temporarily been disabled on the Sweden region due to it having some connectivity issues. PF will be enabled again on that region once the connectivity issue is resolved (likely by switching datacenter). Sorry for the inconvenience. Please use another region in the meantime.
    I've tried Norway, Denmark and Finland, and I'm getting the same error on all of them.
    Are none of the nordic regions open to port forwarding?
    @machinemade Nope none of those support port forwarding, take a look here for an up to date list:-

    https://helpdesk.privateinternetaccess.com/hc/en-us/articles/219460187-How-do-I-enable-port-forwarding-on-my-VPN-

    @Max-P ; what i would REALLY like is a way of getting an up to date list of endpoints that support port forwarding in a programmatic fashion (API request ideally), is this possible? if not any chance of the API being enhanced to support this?, having to monitor some randomly posted FAQ squirreled away on the PIA website is NOT fun.
  • I'm trying to get the port from the script posted earlier pointing at: http://209.222.18.222:2000/?client_id=$client_id

    Gives me the error message: Loading port forward assignment information... Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding

    This is all within a script that stops OpenVPN, starts it again, then straight away (within 2 minutes) checks the forwarded IP. I'm connecting to Switzerland server. Why is this so difficult? Why does it have to be in 2 minutes? Why not just give me the port number whether I ask once, twice, or fifty times? I don't need a new port each time, I'd just like to be able to port forward.


  • binhex said:
    Max-P said:
    @machinemade Port forwarding has temporarily been disabled on the Sweden region due to it having some connectivity issues. PF will be enabled again on that region once the connectivity issue is resolved (likely by switching datacenter). Sorry for the inconvenience. Please use another region in the meantime.
    I've tried Norway, Denmark and Finland, and I'm getting the same error on all of them.
    Are none of the nordic regions open to port forwarding?
    @machinemade Nope none of those support port forwarding, take a look here for an up to date list:-

    https://helpdesk.privateinternetaccess.com/hc/en-us/articles/219460187-How-do-I-enable-port-forwarding-on-my-VPN-

    Netherlands also, and a lot of other europeans countries seem to be unavailable for port forwarding since 2 days?
    Please confirm it is a temporary situation ; those regions were the favorite ones for most of europeans VPN customers.
  • doaks said:

    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.

    Why would I need a port forwarding API?
  • edited April 2018
    Netherlands stoppd working for port forward, came here, checked the list. Seems Netherlands is not on the port forward list anymore. Fair enough, Switzerland is on there, downloaded everything agian. New openvpn files and the .sh.
    Still cant port forward for any location.
    "Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding"

    [EDIT]
    I got Germany to work, maybe you need to update your port forward list again.  Cant connect to Switzerland
  • I have been unable to get this working properly.   I run the script and get a response back providing the port that is supposedly forwarded, however when trying to access that port over the IP address provided by PIA, it cannot get through.   I have no problem validating the open port when using my ISP provided IP address.

    So far, I have tried both Toronto and Montreal gateways.  Has anybody been able to get this to work properly via these gateways ?
  • for anyone having trouble d4rkcat's script works perfectly -- either with the built in -p option (for port forwarding) or through PIAs new script.

    I believe it has something to do with us directly running openvpn from console -- as his script drops to a daemon at the end and stays running in the background with an option to kill it from the terminal it ran from. I believe that is why, for some reason, the new port forwading doesnt work unless we all write scripts similar to d4rkcat.

    Im not sure exactly the reason for it -- my reasoning was a guess and nothing more (not even an educated one really) -- but it DEFINITELY has something to do with directly running openvpn from console to connect. there is a very specific reason we had this problem, but his script works.
  • honestly its a nice little console client as well -- id highly reccomend it as long as its up-to-date with PIA. much nicer than running sudo openvpn
  • p6021691 said:
    Im gonna be leaving PIA to when my subscription is up.  I didnt think with a VPN provider u also needed to be some sort of code wizard in order to get port forwarding to work.

    Im off to NordVPN soon.

    I dont think it willl be much different no matter where you go on linux. quite simply, there are too many distros for PIA to provide a client (unless they make a minimal script one like d4rkcat) -- binaries simply cannot be compatible from distro-to-distro like windows...

    so your gonna be stuck scripting stuff no matter what.

    if you dont like writing scripts then perhaps linux is not really the right OS for you... sure, today we have easy distros -- but the easiest of them (ubuntu/debian) support proprietary clients.

    otherwise, if your using any other distro your pretty much assumed to be an IT pro, hobbyist, or otherwise educated individual. the power of linux comes not because its free, but because its flexible and lets you do anything you want as long as you know how to do it.

    Im not trying to be an elitist prick, but I doubt even nordVPN is going to have a good offering for port forwarding and client settings across all linux distributions. its pretty much impossible, and im very thankful they dont hide all the openvpn settings under proprietary software -- otherwise there would be no way at all to access them even if you connected via openvpn directly.

  • ^wasnt supposed to be all in a quote, sorry for spam
  • screwed said:
    Netherlands stoppd working for port forward, came here, checked the list. Seems Netherlands is not on the port forward list anymore. Fair enough, Switzerland is on there, downloaded everything agian. New openvpn files and the .sh.
    Still cant port forward for any location.
    "Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding"

    [EDIT]
    I got Germany to work, maybe you need to update your port forward list again.  Cant connect to Switzerland
    Yeah, thanks for informing us PIA! NOT!
  • Ok so I am trying to run a script that gets the port number and the ip after openvpn connects
    But I always get an error ! Many here are having the same problem. I found the reason here. Openvpn DOESN'T ALLOW ANY CONNECTION OUT UNTIL THE UP SCRIPT FINISH RUNNING ! For security, but headache for me !

    The solution is using nohup !
    Here are my configs :

    #End of /etc/openvpn/client.conf : 
    script-security 2
    up '/etc/openvpn/up.sh'
    down '/etc/openvpn/down.sh'

    ==> /etc/openvpn/up.sh <==
    #UFW RULES HERE
    nohup /etc/pia/public_ip.sh & 
    nohup /etc/pia/port_forwarding.sh &
    exit 0

    ==> ../openvpn/down.sh <==
    #!/bin/sh -e
    #UFW RULES 
    echo "" > /etc/pia/forwarded.port
    echo "" > /etc/pia/public.ip

    ==> /etc/pia/public_ip.sh <==
    #!/bin/sh
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    dig +short myip.opendns.com @resolver1.opendns.com > /etc/pia/public.ip

    ==> /etc/pia/port_forwarding.sh <==
    #SAVE TO FILE THE PORT !
    echo $json > /etc/pia/forwarded.port

    create the files :
    mkdir /etc/pia -p
    touch /etc/pia/forwarded.port
    touch /etc/pia/public.ip
    chmod g+w /etc/pia/forwarded.port
    chmod g+w /etc/pia/public.ip

    I also had trouble that the rc.local wasn't run before openvpn.service started, resulting in the tun0 device not beeing created and vpn not connecting. Was ok on Ubuntu 16, but stopped working on 17.
    so I disabled openvpn :
    systemctl disable openvpn 

    And start it from rc.local after tun is created.

    ==> /etc/rc.local <==
    #!/bin/sh -e
    if ! [ -c /dev/net/tun ]; then
    mkdir -p /dev/net
    mknod -m 666 /dev/net/tun c 10 200
    ip tuntap add mode tap
    fi
    echo 1 > /proc/sys/net/ipv6/conf/eth0/disable_ipv6
    /etc/openvpn/down.sh
    systemctl restart openvpn
    exit 0

    After all that, IT WORKS LIKE A CHARM !!
  • edited April 2018
    Greetings. I’m running PIA through Viscosity and want to have port forwarding enabled to help my torrent client, Transmission, seed more effectively.

    Here’s what I’ve been able to do (with admittedly little understanding of what I’m doing). 

    1. I’ve downloaded the shell script.
    2. I ran the command line in my terminal: chmod u+x /Users/iMac/Desktop/port_forwarding.sh
    3. I opened Script Editor and ran the line I was instructed by Viscosity to enter: do shell script "/Users/iMac/Desktop/port_forwarding.sh"
    In Viscosity I’m running PIA’s Toronto connection, which allows port forwarding. 

    The result I get in Script Editor is:

    "Loading port forward assignment information...
    {\"port\":23422}"

    I’m psyched to have gotten this far. I can now go into Transmission, enter 23422 into the Peer listening port, and I see the Port is open. 

    So, what I’d love to do next is have the port forwarding be more automated. What I like about Viscosity is that it’s way more stable than PIA’s client. And it’s a real plug and play. It comes on automatically and my browsers work great with it (not always the case with PIA’s client). What I don’t like about Viscosity is that, without port forwarding, my torrent client doesn’t seed effectively. 

    What do I do next with Viscosity? I see that under the connection in the Advanced tab I can point the app to “Before Connect Script” or “Connected Script.” I’m assuming I could use one of these to point to the script I saved in Script Editor. But, then I’m not sure where to find the port path that seems to be different each time I connect. 

    Any advice would be great.
  • edited April 2018
    Okay, I did some futzing this morning and have a solution that works okay. 

    1. My script command line now reads: 

    do shell script "/Users/iMac/Library/Scripts/Viscosity/port_forwarding.sh"
    display notification result

    2. I've saved and located the script in the library script folder so that it shows up in the menu

    3. I set up Viscosity to connect automatically to PIA's port forwarding enabled Toronto connection

    4. In Viscosity, under the Advanced tab, I have "Connected Script" pointed to the script I saved

    5. I changed my notification settings not to notify me when Viscosity connects, and to notify me when a script is active

    So, now what happens is every time Viscosity connects to PIA Toronto I see a notification with a new port forwarding ID.

    This seems to be a decent solution to the problem.  

    Anyone have something that's better (and that you can explain clearly to a novice).
  • edited May 2018
    The only way this script works for me is to escape the question mark, "/\?client_id" and connect using the PIA app. If I try to use Viscosity I get this message every time:

    Loading port forward assignment information...
    Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding

    Is there something I missed that allows this script to work with other applications?

    p4830932 said:

    5. I changed my notification settings not to notify me when Viscosity connects, and to notify me when a script is active


    Really could use some help here. Thanks.
  • edited May 2018
    Hi,

    This might not necessary be a specific problem related to this script, but I cant get my script to work with "up" command in the conf.

    My script IS launched but can´t call the port_forwarding script..  
    If I run the script manually it works like a charm.. but when launched from openvpn... not so good..
    I have tried with absolute path, but still no luck. The script it self works, but not getting the result from port_forward (kind of the whole idea)..
    Im banging my head here..  can anyone point me in the right direction?

    Script as follow (don´t judge me.. Im not a coder!)

    #!/bin/sh -e
    log=/etc/openvpn/pia_script/log.txt
    sleep 5

    -- THIS PART IS NOT WORKING (when launched from openvpn) --
    port=$(/bin/sh -c /etc/openvpn/pia_script/port_forwarding.sh| /usr/bin/grep -o '[[:digit:]]*')
    -- END --

    echo $port
    echo "" >> $log
    echo "------------------------" >> $log
    date -u >> $log
    if [ "$port" -eq "$port" ] 2>/dev/null; then
      echo $port > /etc/openvpn/pia_script/pia_port.txt
      echo "Got the following port: $port" >> $log
      echo "Reconfiguring and restarting ruTorrent" >> $log
    sed -i "s/\(port_range =\)\(.*\)/\1 $port-$port /" /config/rtorrent/rtorrent.rc
    /usr/bin/docker stop rutorrent
    /usr/bin/docker rm rutorrent
    /usr/bin/docker run --name=rutorrent --restart unless-stopped -v /run -v /config:/config -v /downloads:/downloads -v /fast_down:/fast_down -e PGID=1001 -e PUID=1001 -e TZ=Europe/Stockholm -p 80:80 -p
     5000:5000 -p $port:$port -p 6881:6881/udp linuxserver/rutorrent &

    else
      echo "Did not got a portnumber..." >> $log
    fi
  • edited May 2018


    -- THIS PART IS NOT WORKING (when launched from openvpn) --
    port=$(/bin/sh -c /etc/openvpn/pia_script/port_forwarding.sh| /usr/bin/grep -o '[[:digit:]]*')
    -- END --

    Think I found the problem..  
    OpenVPN option "up" is triggered before you actually get the IP from PIA :(
    Hence the script wont work..  
    solution is quite simple..  get the script to wait..
    I just put:
    (sleep 10
    SCRIPT_GOES_HERE
    ) &

    problem solved!

    script-security 2
    up /etc/openvpn/pia_script/getPort.sh
  • Anyone noticed this isn't working anymore? Haven't really looked into it yet -- just noticed its not working?!
Sign In or Register to comment.