I guess the guide never got updated. My apologies, I haven't been trolling the forums in a good while. I actually came back to check i they added an 18.04 guide yet. lol
Anyroad... This is how mine works atm
/etc/openvpn/update-resolv-conf:
/etc/openvpn/portforward.sh:
don't forget to change the relevant deluge information. If using transmission (i don't so I don't know specifically needs to change), the main important part is the the PORTFORWARD.json section that is updated for the new api.
/etc/openvpn/routing.sh:
Anyroad... This is how mine works atm
/etc/openvpn/update-resolv-conf:
Code:
#!/bin/bash
#
# Parses DHCP options from openvpn to update resolv.conf
# To use set as 'up' and 'down' script in your openvpn *.conf:
# up /etc/openvpn/update-resolv-conf
# down /etc/openvpn/update-resolv-conf
#
# Used snippets of resolvconf script by Thomas Hood and Chris Hanson.
# PIA Port Forward API fix by LtHawk & Drake at HTPCGuides.com
# Licensed under the GNU GPL. See /usr/share/common-licenses/GPL.
#
# Example envs set from openvpn:
#
foreign_option_1='dhcp-option DNS 209.222.18.222'
foreign_option_2='dhcp-option DNS 209.222.18.218'
foreign_option_3='dhcp-option DNS 8.8.8.8'
#
[ -x /sbin/resolvconf ] || exit 0
[ "$script_type" ] || exit 0
[ "$dev" ] || exit 0
split_into_parts()
{
part1="$1"
part2="$2"
part3="$3"
}
case "$script_type" in
up)
NMSRVRS=""
SRCHS=""
for optionvarname in ${!foreign_option_*} ; do
option="${!optionvarname}"
echo "$option"
split_into_parts $option
if [ "$part1" = "dhcp-option" ] ; then
if [ "$part2" = "DNS" ] ; then
NMSRVRS="${NMSRVRS:+$NMSRVRS }$part3"
elif [ "$part2" = "DOMAIN" ] ; then
SRCHS="${SRCHS:+$SRCHS }$part3"
fi
fi
done
R=""
[ "$SRCHS" ] && R="search $SRCHS
"
for NS in $NMSRVRS ; do
R="${R}nameserver $NS
"
done
echo -n "$R" | /sbin/resolvconf -a "${dev}.openvpn"
;;
down)
/sbin/resolvconf -d "${dev}.openvpn"
;;
esac
sleep 30 && /etc/openvpn/portforward.sh
Code:
#!/usr/bin/env bash
# Source: http://www.htpcguides.com
# Adapted from https://github.com/blindpet/piavpn-portforward/
# Author: Mike
# Based on https://github.com/crapos/piavpn-portforward
VPNINTERFACE=tun0
VPNLOCALIP=$(ifconfig $VPNINTERFACE | awk '/inet / {print $2}' | awk 'BEGIN { FS = ":" } {print $(NF)}')
CURL_TIMEOUT=5
CLIENT_ID=$(head -n 100 /dev/urandom | sha256sum | tr -d " -")
# set to 1 if using VPN Split Tunnel
SPLITVPN="1"
DELUGEUSER=YOUR_DELUGE_USER
DELUGEPASS=YOUR_DELUGE_PASSWORD
DELUGEHOST=DELUGE_IP [usually `localhost`]
# set date
echo $(date) >> /etc/openvpn/port.log
#get VPNIP
VPNIP=$(curl -m $CURL_TIMEOUT --interface $VPNINTERFACE "http://ipinfo.io/ip" --silent --stderr -)
echo VPN IP: >> /etc/openvpn/port.log
echo $VPNIP >> /etc/openvpn/port.log
#request new port
# echo $CLIENT_ID
PORTFORWARDJSON=$(curl -m $CURL_TIMEOUT --silent --interface $VPNINTERFACE "http://209.222.18.222:2000/\?client_id=$CLIENT_ID")
echo $PORTFORWARDJSON
PORT=$(echo $PORTFORWARDJSON | tr -d '{"port":}')
echo Open Port on VPN: >> /etc/openvpn/port.log
echo $PORT >> /etc/openvpn/port.log
echo END >> /etc/openvpn/port.log
#change firewall rules if SPLITVPN is set to 1
if [ "$SPLITVPN" -eq "1" ]; then
#change firewall rules if necessary
IPTABLERULETWO=$(iptables -L INPUT -n --line-numbers | grep -E "2.*reject-with icmp-port-unreachable" | awk '{ print $8 }')
if [ -z $IPTABLERULETWO ]; then
sudo iptables -D INPUT 2
sudo iptables -I INPUT 2 -i $VPNINTERFACE -p tcp --dport $PORT -j ACCEPT
else
sudo iptables -I INPUT 2 -i $VPNINTERFACE -p tcp --dport $PORT -j ACCEPT
fi
fi
#change deluge port on the fly
deluge-console -c /home/vpn/.config/deluge "connect $DELUGEHOST:58846 $DELUGEUSER $DELUGEPASS; config -s listen_ports ($PORT,$PORT)"
/etc/openvpn/routing.sh:
Code:
#! /bin/bash
# Niftiest Software – www.niftiestsoftware.com
# Modified version by HTPC Guides – www.htpcguides.com
VPNIF="tun0"
VPNUSER="vpn"
GATEWAYIP=$(ifconfig $VPNIF | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | egrep -v '255|(127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})' | tail -n1)
if [[ `ip rule list | grep -c 0x1` == 0 ]]; then
ip rule add from all fwmark 0x1 lookup $VPNUSER
fi
ip route replace default via $GATEWAYIP table $VPNUSER
ip route append default via 127.0.0.1 dev lo table $VPNUSER
ip rule add from all to 209.222.18.222 lookup $VPNUSER
ip route flush cache
# run update-resolv-conf script to set VPN DNS
/etc/openvpn/update-resolv-conf
exit 0