GUIDE: Setting up Transmission with OpenVPN and PIA

travanx

Explorer
Joined
Jul 1, 2014
Messages
62
Edit: Should have looked at a past reply the last time I tried to get this working.
"You can set up a cron job to do it every hour or so. Go into the regular WebGUI and set up the cron task:
jexec transmission_1 bash /port_forward.sh"

Got this almost working finally. How do I run port_forward.sh as a cron job? Do I run something at the command line, or in the Freenas GUI?

Turns out my issue was how I was copying and pasting to create port_froward.sh. Ended up using nano port_forward.sh, copy and paste into there, delete all the lines with # and make sure no other lines were breaking at the wrong spots. Changed permissions and it worked! Installed openvpn from the first post and changed step #10 to pkg install openvpn.

Used post above, head -n 100 /dev/urandom | md5 | tr -d " -", to get the client id.
 
Last edited:

sp00nlude

Dabbler
Joined
Sep 10, 2016
Messages
21
Thanks to this guide, I was able to get OpenVPN setup and running. However, due to some other issues I ran into with my plugins I had to reinstall them and configure the jails with VIMAGE off. Now when I try to install OpenVPN I keep getting this error:

Sep 17 00:12:04 transmission_1 openvpn[46882]: Could not retrieve default gateway from route socket:: No such process (errno=3)
Sep 17 00:12:04 transmission_1 openvpn[46882]: Cannot allocate TUN/TAP dev dynamically
Sep 17 00:12:04 transmission_1 openvpn[46882]: Exiting due to fatal error


So I'm kinda stumped at the moment. I have tried to reinstall Transmission several times along with OpenVPN but keep encountering the same issue. Perhaps the real problem is why VIMAGE needs to be off for my plugins to work. If I have VIMAGE turned on the Transmission jail and try to start the plugin, it just says some error has occurred and this is what is in the log:

Sep 17 00:17:52 freenas manage.py: [freeadmin.navtree:631] An error occurred while unserializing from http://192.168.0.28/plugins/transmission/4/_s/treemenu: No JSON object could be decoded
Sep 17 00:18:06 freenas manage.py: [plugins.utils:91] Couldn't retrieve http://192.168.0.28/plugins/transmission/4/_s/status: No JSON object could be decoded


When this happens, the GUI shows that the jail has the IP address that I specified. However, if I go to SSH and run jls, the jail does not appear to have an IP address. Turning off VIMAGE and restarting the jail resolves the IP address issue and the above error.

Hoping someone can provide some pointers. Thanks.
 

Btrd2

Cadet
Joined
Aug 23, 2016
Messages
5
Thanks to this guide, I was able to get OpenVPN setup and running. However, due to some other issues I ran into with my plugins I had to reinstall them and configure the jails with VIMAGE off. Now when I try to install OpenVPN I keep getting this error:

Sep 17 00:12:04 transmission_1 openvpn[46882]: Could not retrieve default gateway from route socket:: No such process (errno=3)
Sep 17 00:12:04 transmission_1 openvpn[46882]: Cannot allocate TUN/TAP dev dynamically
Sep 17 00:12:04 transmission_1 openvpn[46882]: Exiting due to fatal error


So I'm kinda stumped at the moment. I have tried to reinstall Transmission several times along with OpenVPN but keep encountering the same issue. Perhaps the real problem is why VIMAGE needs to be off for my plugins to work. If I have VIMAGE turned on the Transmission jail and try to start the plugin, it just says some error has occurred and this is what is in the log:

Sep 17 00:17:52 freenas manage.py: [freeadmin.navtree:631] An error occurred while unserializing from http://192.168.0.28/plugins/transmission/4/_s/treemenu: No JSON object could be decoded
Sep 17 00:18:06 freenas manage.py: [plugins.utils:91] Couldn't retrieve http://192.168.0.28/plugins/transmission/4/_s/status: No JSON object could be decoded


When this happens, the GUI shows that the jail has the IP address that I specified. However, if I go to SSH and run jls, the jail does not appear to have an IP address. Turning off VIMAGE and restarting the jail resolves the IP address issue and the above error.

Hoping someone can provide some pointers. Thanks.

+1 to all of this! I usually never take the time to write out a post on forums, I'd rather just figure it out myself with the available resources, but this one has me ready to post - and wala, my same exact problem is explained word for word above.

Has anyone been successful in getting OpenVPN installed in a jail with VIMAGE off?

Regarding the "...No JSON object could be decoded..." error everything I've read says the same thing - a) turn promiscuous mode on (don't really know what this is, but from everything I could find promiscuous mode is strictly a VM thing, and there is no promiscuous mode for a non-VM) or b) turn VIMAGE off.

Thanks sp00nlude for providing a detailed post of the problem so I didn't have too =)
 

sp00nlude

Dabbler
Joined
Sep 10, 2016
Messages
21
+1 to all of this! I usually never take the time to write out a post on forums, I'd rather just figure it out myself with the available resources, but this one has me ready to post - and wala, my same exact problem is explained word for word above.

Has anyone been successful in getting OpenVPN installed in a jail with VIMAGE off?

Regarding the "...No JSON object could be decoded..." error everything I've read says the same thing - a) turn promiscuous mode on (don't really know what this is, but from everything I could find promiscuous mode is strictly a VM thing, and there is no promiscuous mode for a non-VM) or b) turn VIMAGE off.

Thanks sp00nlude for providing a detailed post of the problem so I didn't have too =)

I've found that with VIMAGE on and even without an IP address for the jail that things have been fine. Also read somewhere in this forum that no IP address when querying jls is "ok". I've moved on and just ignore the JSON error.

Hope this helps!
 

Btrd2

Cadet
Joined
Aug 23, 2016
Messages
5
I've found that with VIMAGE on and even without an IP address for the jail that things have been fine. Also read somewhere in this forum that no IP address when querying jls is "ok". I've moved on and just ignore the JSON error.

Hope this helps!

When you get the error, you can still use your plugin? Mine - in the Plugins -> Installed area - will be shut off and lose its icon, and will error when trying to turn back on. The only thing that triggers this is (that I know of so far) OpenVPN installation. Without OpenVPN I can leave VIMAGE on, with OpenVPN it will bug out upon restart of the jail.

Glad you were able to get the combo working =)

EDIT: I think I see what you're saying - even when this bug occurs, you can still access the web interface and appears (at this time) to work properly.
 
Last edited:

denist

Contributor
Joined
Jan 28, 2013
Messages
188
So the script does not work anymore or we have to go step by step I have not done this in a while as it has been working fine but I have a script for firewall rule that I run. I would like to use the new method by adding just to use tun0 for whole nail as the jails has sabnzbd sickrage and couchpotato running. I would also like to use the port forward also that some one has created.

I am thinking of updating freenas to 9.10 is this wise ????


Sent from my iPhone using Tapatalk
 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
Maybe someone can breakdown the steps from start then firewall wall then port forward as a guide in step form in one post as a guide.


Sent from my iPhone using Tapatalk
 

Blaccko

Dabbler
Joined
Apr 10, 2015
Messages
14
Hi all,

I've followed this guide to setup OpenVPN and ipfw.

My Transmission jail is up and running. My VPN is configured and works with OpenVPN. My firewall is configured with ipfw and works (the connection is stopped if the VPN stops). My only concern now is to port forward a port to Transmission. I'm using FreeNAS 9.10, PIA for VPN and ipfw.

I tried to use this script to port forward a port to Transmission )as this script generates the same port each time it is executed, according to the author. However, I get an error (command not found) when I try to execute the script. I've been reading a lot, specially this thread, and I followd Glorious1 advice to install bash, as you can see per code, but it's already installed. So, I don't know what to try now to get the script working. Could you please help me with this issue?

Code:
root@transmission_1:/ # cd /usr/local/etc/openvpn							   
root@transmission_1:/usr/local/etc/openvpn # ls								 
4b05e93c63684ea1a95518fcfbd8a6a04461b1d5										
PIA																			 
ca.rsa.2048.crt																 
crl.rsa.2048.pem																
openvpn.conf																	
openvpn.zip																	 
password.txt																	
port_forward.sh																 
port_forward.sh.1															   
root@transmission_1:/usr/local/etc/openvpn # pkg install bash				   
Updating FreeBSD repository catalogue...										
FreeBSD repository is up-to-date.											   
All repositories are up-to-date.												
Checking integrity... done (0 conflicting)									 
The most recent version of packages are already installed					   
root@transmission_1:/usr/local/etc/openvpn # ./port_forward.sh testuname testpas
sword																		   
./port_forward.sh: Command not found.										   
root@transmission_1:/usr/local/etc/openvpn #


Thanks a lot!
 

Blaccko

Dabbler
Joined
Apr 10, 2015
Messages
14
Hi,

@jafrey, is your answer for me? If so, yes I have wget. I use it to get the port_forward.sh file.

I don't understand your comment about rm -rf...

Thanks again,
 

Scharbag

Guru
Joined
Feb 1, 2012
Messages
620
I am interested in using the port forward feature of PIA. I hacked together this script starting from the PIA script, and it seems to work (forwards port to Transmission). I am still learning FreeNAS and scripting so if anyone has a more elegant solution I would be interested.

(this runs inside the jail with OpenVPN and Transmission)

Code:
#! /usr/local/bin/bash
#
# Enable port forwarding
#
# Requirements:
#   your Private Internet Access user and password as arguments
#
# Usage:
#  ./port_forward.sh <user> <password>

error( )
{
  echo "$@" 1>&2
  exit 1
}

error_and_usage( )
{
  echo "$@" 1>&2
  usage_and_exit 1
}

usage( )
{
  echo "Usage: `dirname $0`/$PROGRAM <user> <password>"
}

usage_and_exit( )
{
  usage
  exit $1
}

version( )
{
  echo "$PROGRAM version $VERSION"
}


port_forward_assignment( )
{
  echo 'Loading port forward assignment information..'
  if [ "$(uname)" == "Linux" ]; then
	local_ip=`ifconfig tun0|grep -oE "inet addr: *10\.[0-9]+\.[0-9]+\.[0-9]+"|tr -d "a-z :"|tee /tmp/vpn_ip`
	client_id=`head -n 100 /dev/urandom | md5sum | tr -d " -"`
  fi
  if [ "$(uname)" == "FreeBSD" ]; then
	local_ip=`ifconfig tun0 | grep "inet " | cut -d\  -f2|tee /tmp/vpn_ip`
	client_id=`head -n 100 /dev/urandom | md5 -r | tr -d " -"`
  fi
  json=`wget --no-check-certificate -q --post-data="user=$USER&pass=$PASSWORD&client_id=$client_id&local_ip=$local_ip" -O - 'https://www.privateinternetaccess.com/vpninfo/port_forward_assignment' | head -1`
  echo $json
  PORTNUM=`echo $json | grep -oE "[0-9]+"`
}

EXITCODE=0
PROGRAM=`basename $0`
VERSION=1.0
USER=$1
PASSWORD=$2

while test $# -lt 2
do
  case $1 in
  --usage | --help | -h )
	usage_and_exit 0
	;;
  --version | -v )
	version
	exit 0
	;;
  *)
	error_and_usage "Unrecognized option: $1"
	;;
  esac
  shift
done

port_forward_assignment

transmission-remote -p $PORTNUM

exit 0
Works great. I load this with crontab on
Code:
@reboot
and
Code:
@daily
Is that a wise way to do it?

NOTE: ensure that you either use the whole command path in the shell script when using cron OR export the path within the shell script... :)

One question: sometimes my tunnel adapter is tun1 because of boot order. Is there a way to have the tun* figure itself out? I tried just using tun* but of course that does not exist. I am sure there is a way to figure it with grep or some such but I am not a very good coder (or typist).

I figured it out:

Code:
	# dynamically figure out the tunnel adapter name
	tunnel_adapter=`ifconfig | grep "tun" | cut -d ":" -f1`
	local_ip=`ifconfig $tunnel_adapter | grep "inet " | cut -d\  -f2|tee /tmp/vpn_ip`


Thanks again for the great script.

Cheers,
 
Last edited:

Blaccko

Dabbler
Joined
Apr 10, 2015
Messages
14
Just to make sure there's no confusion, I started a specific thread for my question (I've managed to get passe de "command not found" error, but got another one now). The thread is here.

Thanks!
 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
This is what i have done.

Installed Openvpn like the below
Code:
You'll need this URL: https://www.privateinternetaccess.com/openvpn/openvpn.zip
FYI - it's the files we're going to download in the jail.

Basically we're going to install OpenVPN creating a Portsnap OpenVPN version that allows us to save our username (USER1) and password (PASSWRD) to a txt file that will be used everytime the OpenVPN service is started.

HERE WE GO!

##Step 1: SSH into freenas. (I use PuTTy)

##Step 2: Get a list of jails
root@freenas ~# jls
JID  IP Address  Hostname  Path
4  -  transmission_1  /mnt/<volumename>/jails/transmission_1

##Step 3: jexec into the jail (mine happens to be 4 - yours may vary)
root@freenas ~# jexec 4 tsch
root@transmisssion_1:/ #

##Step 4: install bash. May be prompted several times - reply Y then press enter each time.
root@transmission_1:/ # pkg install bash

##step 5: install nano. Again, may be prompted several times. Reply Y each time.
root@transmission_1:/ # pkg install nano

##Step 6: move to the /etc folder.
root@transmission_1:/ # cd /etc
root@transmission_1:/etc #

##Step 7: Fetch Portsnap via portsnap fetch
root@transmission_1:/etc # portsnap fetch

## This will take a while to download and ask for several prompts -
you know the drill.

##Step 8: Extract Ports to /usr/ports
root@transmission_1:/etc # portsnap extract

## This will also take a long time and A LOT of scrolling will happen. It's normal.

##Step 9: Navigate to /usr/ports/security/openvpn
root@transmission_1:/etc # cd /usr/ports/security/openvpn
root@transmission_1:/usr/ports/security/openvpn #

##Step 10: Make a clean install which allows us to set the option of a password file.
root@transmission_1:/usr/ports/security/openvpn # pkg install openvpn

We've successfully created OpenVPN that will have an interactive passwords read from a file.
Yeay!
Now to set it up.

##Step 11: go to root directory of the transmission_1 jail.
root@tranmission_1:/usr/ports/security/openvpn # cd /
root@transmission_1:/ #

##Step 12: Enter Bash
root@transmission_1:/ bash
[root@transmission_1 /]#
##Step 13: Make a directory for OpenVPN & our files we download from PIA
[root@transmission_1 /]# mkdir /usr/local/etc/openvpn
##Step 14: Add lines to the rc.conf so OpenVPN starts when the jail starts.
[root@transmission_1 /]# cd /etc
##note - use Ctrl+o will write the file and Ctrl+X will exit.
[root@transmission_1 /etc]# nano rc.conf

##File is open.
##Add the following (can copy/paste using ctrl+C then right clicking in the shell)

openvpn_enable="YES"
openvpn_configfile="/usr/local/etc/openvpn/openvpn.conf"

##Write via Ctrl+O. Press Enter
##Exit via Ctrl+X.

##Step 15: Move to a new folder (helps me keep things straight)
[root@transmission_1 /etc]# cd /media/
[root@transmission_1 /media]#

##Step 16: wget the PIA files, you'll likely need to add --no-check-certificate so it will actually download.
[root@tranmission_1 /media]# wget https://www.privateinternetaccess.com/openvpn/openvpn.zip --no-check-certificate

##Step 17: unzip the PIA openvpn files.
[root@tranmission_1 /media]# unzip openvpn.zip

##Step 18: make a pass.txt file to hold your username and password.
[root@tranmission_1 /media]# nano pass.txt

##Nano will pop up. ONLY type in the following (substituting your REAL username and password of course)
USER1
PASSWRD

##Press Ctrl+o. call it pass.txt. then enter. then Ctrl+X

##Step 19: Configure the .ovpn file of your selected server. (I did UK London)
[root@tranmission_1 /media]# nano "UK London.ovpn"

## On the auth-user-pass line add pass.txt after it like so:
auth-user-pass pass.txt

####Press Ctrl+o. call it UK London.ovpn. then enter. then Ctrl+X

Getting very close to being done.

##Step 20: skipped.

##Step 21: Move the fixed PIA files into the correct folder we just created
##The actual OpenVPN files we created earlier.
##ca.crt next
[root@transmission_1 /media]# cp /media/ca.rsa.2048.crt /usr/local/etc/openvpn/ca.rsa.2048.crt
##crl.pem next
[root@transmission_1 /media]# cp /media/crl.rsa.2048.pem /usr/local/etc/openvpn/crl.rsa.2048pem
##our pass.txt file we created
[root@transmission_1 /media]# cp /media/pass.txt /usr/local/etc/openvpn/pass.txt
##finally renaming the <Server>.ovpn file to .conf file --- You'll have to use "" around the name if there is a space in it.
[root@transmission_1 /media]# cp /media/"UK London.ovpn" /usr/local/etc/openvpn/openvpn.conf

Now to see if it works!!

[root@transmission_1 /]# /usr/local/etc/rc.d/openvpn start
Starting OpenVPN

To check IP from VPN to see if it is working

wget -qO - http://wtfismyip.com/text

If the IP is different to your IP then VPN is working.
 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
then i created the ipfw set. Kill switch

Code:
Enter Jail via putty

Edit /etc/rc.conf and add the below lines

ee /etc/rc.conf

firewall_enable="YES"
firewall_type="/sabnzbd/scripts/ipfw_rules"

Copy script file to script folder (pia.py) to /sabnzbd/Scripts

chmod +x /sabnzbd/scripts/pia.py

in freenas gui cron job (add Cron Jobs)

Name it OpenVpn Script

User root
command jexec transmission_1 python2.7 /sabnzbd/scripts/pia.py
Every N minute 5
Every N hour 1
Day of month 1
month check all
day of week check all
redirect check
enabled check


Ip Checking in putty

wget http://smart-ip.net/myip -O - -q ; echo

wget -qO- http://wtfismyip.com/text


Pia Script below

Code:
#!/usr/local/bin/python2.7
import sys
import socket
import subprocess
url = 'Sweden.privateinternetaccess.com'
try:
  # Raise if it can't ping the server or openvpn isn't running
  subprocess.check_output(['service', 'openvpn', 'status'])
  subprocess.check_output(['ping', '-c', '1', url])
except subprocess.CalledProcessError:
  pass
else:
  sys.exit()
hostname, aliaslist, ipaddrlist = socket.gethostbyname_ex(url)
content = '''
add 01006 allow ip from 192.168.2.0/24 to 192.168.2.0/24 keep-state
'''
rule_number = 2001
for ip in ipaddrlist:
  content += '''
add {} allow ip from 192.168.2.0/24 to {} keep-state
add {} allow ip from {} to 192.168.2.0/24 keep-state
'''.format(rule_number, ip, rule_number + 1, ip)
  rule_number += 2
content += '''
add 04000 allow ip from 127.0.0.1 to any
add 05000 allow ip from 10.0.0.0/8 to any
add 05002 allow ip from any to 10.0.0.0/8
add 65534 deny ip from any to any
'''
# Stop ipfw
subprocess.call(['service', 'openvpn', 'stop'])
subprocess.call(['service', 'ipfw', 'stop'])
f = open('/sabnzbd/scripts/ipfw_rules', 'w')
f.write(content)
f.close()
# Start ipfw
subprocess.call(['service', 'ipfw', 'start'])
# Check if running
if 'ipfw' in subprocess.check_output(['service', '-e']):
  subprocess.call(['service', 'openvpn', 'start'])
sys.exit()

 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
The kill switch above runs every 5 min and will restart openvpn if it sees that there is not internet activity. Once openvpn starts it creates a new set of iffw_rules set.

I then used the above script for port forwarding

Code:
#! /usr/local/bin/bash
#
# Enable port forwarding
#
# Requirements:
#  your Private Internet Access user and password as arguments
#
# Usage:
#  ./port_forward.sh <username> <password>

error( )
{
  echo "$@" 1>&2
  exit 1
}

error_and_usage( )
{
  echo "$@" 1>&2
  usage_and_exit 1
}

usage( )
{
  echo "Usage: `dirname $0`/$PROGRAM <user> <password>"
}

usage_and_exit( )
{
  usage
  exit $1
}

version( )
{
  echo "$PROGRAM version $VERSION"
}


port_forward_assignment( )
{
  echo 'Loading port forward assignment information..'
  if [ "$(uname)" == "Linux" ]; then
   local_ip=`ifconfig tun0|grep -oE "inet addr: *10\.[0-9]+\.[0-9]+\.[0-9]+"|tr -d "a-z :"|tee /tmp/vpn_ip`
   client_id=`head -n 100 /dev/urandom | md5sum | tr -d " -"`
  fi
  if [ "$(uname)" == "FreeBSD" ]; then
   local_ip=`ifconfig tun0 | grep "inet " | cut -d\  -f2|tee /tmp/vpn_ip`
   client_id=`head -n 100 /dev/urandom | md5 -r | tr -d " -"`
  fi
  json=`wget --no-check-certificate -q --post-data="user=$USER&pass=$PASSWORD&client_id=$client_id&local_ip=$local_ip" -O - 'https://www.privateinternetaccess.com/vpninfo/port_forward_assignment' | head -1`
  echo $json
  PORTNUM=`echo $json | grep -oE "[0-9]+"`
}

EXITCODE=0
PROGRAM=`basename $0`
VERSION=1.0
USER=$1
PASSWORD=$2

while test $# -lt 2
do
  case $1 in
  --usage | --help | -h )
   usage_and_exit 0
   ;;
  --version | -v )
   version
   exit 0
   ;;
  *)
   error_and_usage "Unrecognized option: $1"
   ;;
  esac
  shift
done

port_forward_assignment

transmission-remote -p $PORTNUM

exit 0


i then run the command from the script director where i saved the script

sh port_forward.sh username pasword

this creates the port opened. My issue is how to run this in the cron so it runs after the kill switch or is there a more elegant way to do all of this. or is there a way for the script to be edited so it checks if transmission port is closed and if so then creates a new port. If it see that the port is opened then it just exist.

Thanx in advance.
 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
If we can get the script to check if the port is opened/closed then i can run it through cron gui.
 

Trask

Cadet
Joined
Dec 19, 2016
Messages
1
Hey all,

I'm trying to get the port forwading script to work, but it doesn't seem like the PIA vpninfo address is returning the portnumber etc. Can anyone confirm if this is the case?

P.S. Thanks to everyone in this thread who's contributed. You've got me this far :)
 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
Hey all,

I'm trying to get the port forwading script to work, but it doesn't seem like the PIA vpninfo address is returning the portnumber etc. Can anyone confirm if this is the case?

P.S. Thanks to everyone in this thread who's contributed. You've got me this far :)

Hi Trask,

I am using this code for the script
Code:
#!/usr/local/bin/bash
# Cronable port forwarding script for PIA/transmission running on
# FreeNAS
#
# Requires bash, jq (JSON parser) and curl
# pkg install -y jq bash curl
# Assumes tunnel is tun0 if different change below
#

# Your PrivateInternetAccess credentials
PIA_USER=username
PIA_PASS=password

# Export path for when you use this in cron
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin"

# echo date/time for logging
echo "Transmission Port Forward $(date +%Y-%m-%d-%H:%M:%S)"

get_new_port( ) {
  if ! [ -x $(curl)  ]; then
  echo "Curl not installed/not executable"
  exit 0
  fi
   
  # get the local tunnel ip
  local_ip=$(ifconfig tun0 | grep "inet " | cut -d\  -f2)
   
  #client_id seems to want random data
  client_id=$(head -n 100 /dev/urandom | md5 -r | tr -d " -")
   
  port=$(curl --silent --data "user=$PIA_USER&pass=$PIA_PASS&client_id=$client_id&local_ip=$local_ip" https://www.privateinternetaccess.com/vpninfo/port_forward_assignment | jq .port)
   
  if ! [[ $port =~ ^[0-9]+$ ]]; then
  echo "Garbled data: $port"
  exit 0
  fi
   
  transmission-remote -p $port
}

is_port_forwarded( ) {
  # -pt tests for open port.
  json=$(transmission-remote -pt)
   
  if [[ $json == "Port is open: No" ]]; then
  echo "Closed port detected"
  get_new_port
  elif [[ $json == "Port is open: Yes" ]]; then
  echo "Open port detected"
  exit 1

  fi
}

check_for_connectivity( ) {
  if nc -zw 1 google.com 80; then
  echo "VPN connection up."
  else
  echo "VPN connection down. Exiting."
	exit 0

  fi
}

check_for_connectivity
is_port_forwarded




Just change in the script the username and password.

Save the script to port_forward.sh, save it somewhere on your server, chmod +x to make the script executable make sure you install jq, bash and curl if not already installed.
Run the script like bash port_forward.sh. I run mine in cron every 5 min as the script check to see if the transmission port is open and if it is then the script exits. If it detect the port as closed then it will port forward a port and tells transmission to use that port.
 
Top