Friday, May 3, 2013

How to Connect PPTP on Linux command line

This tutorial explains how to connect via PPTP protocol on Linux using command-line,

so you don't need to use any network managers of GUIs like KDE, Gnome, etc.



Check if ppp-generic module exists. If not, it will probably not work:
modprobe ppp-generic


Install necessary packages:
apt-get install pptp-linux pptpd ppp curl

Create PPTP configuration file:
nano /etc/ppp/peers/hmavpn


Enter this as content of the "hmavpn" file:
(replace 72.11.154.130 is the IP of the PPTP server you want to connect to, and MYHMAACCOUNTUSERNAME with your username)
pty "pptp 72.11.154.130 --nolaunchpppd"
lock
noauth
nobsdcomp
nodeflate
name MYHMAACCOUNTUSERNAME
remotename hmavpn
ipparam hmavpn
require-mppe-128
usepeerdns
defaultroute
persist

Enter VPN login credentials into chap-secrets file: ([tab] being replaced by a tab, username with your VPN account username and password with your PPTP password):
nano /etc/ppp/chap-secrets
username[tab]hmavpn[tab]password[tab]*

Create script to replace default routes - otherwise the VPN is not being used by your system:
nano /etc/ppp/ip-up.local

Enter this as content of the "ip-up.local" file:
#!/bin/bash
H=`ps aux | grep 'pppd pty' | grep -v grep | awk '{print $14}'`
DG=`route -n | grep UG | awk '{print $2}'`
DEV=`route -n | grep UG | awk '{print $8}'`
route add -host $H gw $DG dev $DEV
route del default $DEV
route add default dev ppp0

Make this script executable:
chmod +x /etc/ppp/ip-up.local

To connect to the VPN:
pon hmavpn

To disconnect from the VPN:
poff hmavpn

Check your current IP:
curl http://checkip.dyndns.org


Notes:

  • You can check via "ifconfig" if there is a ppp0 adapter. If there is, you are successfully connected.
  • All commands must be run with "sudo" if you're not logged in as a root user.
  • When you are connected but the VPN is not being used by your system, incorrect iptables / routing rules are responsible.
    Try running "route add default dev ppp0". I'll list other possible fixes here ASAP.

No comments:

Post a Comment