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:

/etc/ppp/peers/piavpn

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

pty "pptp 100.100.22.33 --nolaunchpppd"
lock
noauth
nobsdcomp
nodeflate
name PIA_PPTP_USER
remotename piavpn
ipparam piavpn
require-mppe-128
usepeerdns
defaultroute
persist

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:

/etc/ppp/ip-up.local

And put this in it:

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

then:

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

Create this file:

/etc/ppp/ip-down.local

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

#!/bin/bash
#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 157.202.240.1 dev eth0
#route add default gw $G $DEV
route delete $H dev eth0

then:

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, 157.202.0.0/16.  You have to put your default gateway in here too.  Also needed is the IPv4 address of the server (example 157.202.243.181).

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

ip route add 157.202.0.0/16 dev eth0 src 157.202.243.181 table admin
#(local eth0 network and ip of eth0)

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

ip rule add from 157.202.243.181/32 table admin
ip rule add to 157.202.243.181/32 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)