VPN PPTP Client on Raspberry Pi

To start, you will need to install pptpclient, this can be achieved by:

sudo apt-get install pptp-linux

Next, Create a file in /etc/ppp/peers with arbitrary name and the following contents:

pty "pptp $VPNHOSTNAME --nolaunchpppd --debug"
name $USERNAME
password $PASSWORD
remotename PPTP
require-mppe-128
require-mschap-v2
refuse-eap
refuse-pap
refuse-chap
refuse-mschap
noauth
debug
persist
maxfail 0
defaultroute
replacedefaultroute
usepeerdns

Where $VPNHOSTNAME is your VPN host name, $PASSWORD is your VPN password and $USERNAME is your VPN username.

After you have done that, you should do:

sudo pon $FILENAME

where $FILENAME is the name of the file you saved earlier. Or you should do this to see debug messages (this command will display logs until connection off):

pon $FILENAME debug dump logfd 2 nodetach

To start your VPN client on boot, you can follow the instructions on http://pptpclient.sourceforge.net/howto-debian.phtml (point 8 or 9, Hand configuration section)

An alternate method to make your VPN client run on boot is to make a script /etc/init.d/pptp containing these contents:

#! /bin/sh

case "$1" in
  start)
sleep 10
pon $/etc/ppp/peers/FILENAME

    echo "PPTP Started"
    ;;
  stop)
    poff $/etc/ppp/peers/FILENAME
    echo "PPTP Stopped"
    ;;
  *)
    echo "Usage: /etc/init.d/pptp {start|stop}"
    exit 1
    ;;
esac

exit 0

Then run:

update-rc.d [filename of script] defaults

To make it run at startup.

Raspberry Pi (or Ubuntu) IP Address Setting

IP Address Settings Static:

# /etc/network/interfaces
iface eth0 inet static
address a.b.c.d
netmask 255.255.255.0
gateway 192.168.0.1

IP Address Settings DHCP:

# /etc/network/interfaces
iface eth0 inet manual

Or

# /etc/network/interfaces
iface eth0 inet dhcp

Starting Ubuntu 18.04 LTS using netplan:
/etc/netplan/01-network-manager-all.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: no
      addresses: [192.168.1.222/24]
      # gateway4: 192.168.1.1 --deprecated
routes:
- to: default
via: 192.168.1.1

      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

apply the configuration:
netplan apply

or using NetworkManager

network:
  version: 2
  renderer: NetworkManager

and use command below to set ip:

nmcli con mod "Wired connection 1" ipv4.address 1.2.3.4/24 ipv4.gateway 1.2.3.4 ipv4.dns 1.2.3.4 ipv4.method manual
# write above command in one single line

Nameserver:
a) Ubuntu versions < 14.04

# /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

b) Ubuntu versions >= 14.04

# /etc/network/interfaces
dns-nameservers 8.8.8.8

Note: For raspbian, when using static ip, you must disable DHCP service in /etc/dhcpcd.conf, add this line:

denyinterfaces eth0

Update 13 Oct 18, raspbian now use dhcp5 so you need to edit/etc/dhcpcd.conf

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1