VPN Abstracting For On The Fly IP Changing With HMA, PIA etc.
 Page :   [ 1 ]    [ 2 ]    [ 3 ]    [ 4 ]  

Setting up PPTP for connecting to PIA (or other providers).

apt-get install pptp-linux pptpd ppp curl

Create this file:


and put this in it (the IP is one of the IP's from PIA)..

pty "pptp --nolaunchpppd"
remotename piavpn
ipparam piavpn

open the chap-secrets file

pico -w /etc/ppp/chap-secrets

and add this to it (important: there is a TAB between each field).  The user and pass here are provided by PIA.  They are the credentials you use to connect to their server using PPTP.

"PIA_PPTP_USER"    piavpn    "PIA_PPTP_PASSWD"    *

Create this file:


And put this in it:

#typically eth0
DEV=`route -n | grep "UGH\?" | awk '{print $8}'`
route del default $DEV
route add default dev ppp0


chmod +x /etc/ppp/ip-up.local

Create this file:


and put the following into it.  The "" (for example) is the default gateway on your server.  Use the command "route" to see it.  It will be listed as the default gateway.

#host ip of vpn server
H=`route -n | grep UGH | awk '{print $1}'`

#gateway of local server
G=`route -n | grep UGH | awk '{print $2}'`

#main interface .. typically eth0
DEV=`route -n | grep UG | awk '{print $8}'`

while ip route del default; do :; done
route add default gw dev eth0
#route add default gw $G $DEV
route delete $H dev eth0


chmod +x /etc/ppp/ip-down.local


Now add the following stuff to /etc/rc.local (above the line that says exit 0).  You will need to work out the network of your server, in my case it was, for example,  You have to put your default gateway in here too.  Also needed is the IPv4 address of the server (example

echo "1 admin" >> /etc/iproute2/rt_tables

ip route add dev eth0 src table admin
#(local eth0 network and ip of eth0)

ip route add default via dev eth0 table admin
#(gateway for local network)

ip rule add from table admin
ip rule add to table admin

modprobe nf_conntrack_pptp

Do all these commands to add some rules to iptables:

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A INPUT -p tcp --dport 22 -j ACCEPT

iptables -A OUTPUT -p tcp --dport 1723 -j ACCEPT

iptables -A OUTPUT -o ppp0 -p tcp -j ACCEPT
iptables -A OUTPUT -o ppp0 -p udp -j ACCEPT

iptables -A OUTPUT -j DROP

And do this to save them:

iptables-save > /etc/iptables.rules

 Now edit /etc/network/interfaces this file and directly below the line that says iface lo inet loopback , add the following:

pre-up iptables-restore < /etc/iptables.rules

To turn the VPN on and off you would do:

pon piavpn

poff piavpn


(Page 2 of 4)