Admins eHow SysAdmin Tips & Tricks

April 30, 2010

Connect to PPTP VPN from Linux only by one command

Filed under: CentOS,Debian,General — Tags: , , , , , , , , , — admin @ 1:03 pm

I’ve used this method to connect to a windows PPTP VPN server on PCLinuxOS 2010 , but I am sure it will work on other ditros too.
First make sure sure pptp-linux and ppp packages are installed on your client PC.
you may install them by yum or apt-get or package manager of your linux.
then use the following command to connect to VPN.

pppd pty "pptp IP_OR_FQDN_VPN_SERVER --nolaunchpppd" file /etc/ppp/options.pptp user USERNAME password PASSWORD

replace IP_OR_FQDN_VPN_SERVER with IP or DNS of your VPS server.
replace USERNAME with your VPN username.
replace PASSWORD with your VPN password.
wait for like 10-15 seconds , then run ifconfig command , you should see ppp0 interface there , if it is not there , you can troubleshoot by looking into syslog of your linux.
please note this command is good for connecting to a windows VPN server with default configuration , if you have any custom settings , you may need to edit /etc/ppp/options.pptp file.
to disconnect form VPN , use the following command :

killall pppd

if you need to route all of your traffic to VPN server ( use it as a gateway ) , do the following :
create a file named vpn-up in /etc/ppp/ip-up.d and put the following lines inside it :

#!/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

and make it executable by :

chmod +x vpn-up

create another file named vpn-down in /etc/ppp/ip-down.d and put the following lines inside it :

#!/bin/bash
H=`route -n | grep UGH | awk '{print $1}'`
DG=`route -n | grep UGH | awk '{print $2}'`
DEV=`route -n | grep UGH | awk '{print $8}'`
route del -host $H
route add default gw $DG dev $DEV

and make it executable by :

chmod +x vpn-down

now reconnect to VPN , and your routing will be done automatically.

  • Pingback: Connect to PPTP VPN from Linux only by one command « Admins eHow | Besthostdeal4u.com()

  • Pingback: The Perfect Desktop – PCLinuxOS 2010 (KDE) « Free Software Download()

  • Pingback: Connect to PPTP VPN from Linux only by one command « Admins eHow | Bulldoghostreviews.com()

  • Pingback: Connect to PPTP VPN from Linux only by one command « Admins eHow | Bestratedwebhost.com()

  • Pingback: Connect to PPTP VPN from Linux only by one command « Admins eHow | Hostdeal4u.com()

  • Pingback: Connect to PPTP VPN from Linux only by one command « Admins eHow « Hotwebhostreviews.com()

  • ==> /var/log/messages <==
    Dec  7 17:54:35 localhost pppd[20464]: pppd 2.4.5 started by jollychang, uid 0
    Dec  7 17:54:35 localhost pppd[20464]: Using interface ppp0
    Dec  7 17:54:35 localhost pppd[20464]: Connect: ppp0 /dev/pts/3
    Dec  7 17:54:35 localhost pptp[20465]: anon log[main:pptp.c:314]: The synchronous pptp option is NOT activated
    Dec  7 17:54:35 localhost pptp[20477]: anon log[ctrlp_rep:pptp_ctrl.c:254]: Sent control packet type is 1 ‘Start-Control-Connection-Request’
    Dec  7 17:54:36 localhost pptp[20477]: anon log[ctrlp_disp:pptp_ctrl.c:754]: Received Start Control Connection Reply
    Dec  7 17:54:36 localhost pptp[20477]: anon log[ctrlp_disp:pptp_ctrl.c:788]: Client connection established.
    Dec  7 17:54:36 localhost pptp[20477]: anon log[ctrlp_rep:pptp_ctrl.c:254]: Sent control packet type is 7 ‘Outgoing-Call-Request’
    Dec  7 17:54:37 localhost pptp[20477]: anon log[ctrlp_disp:pptp_ctrl.c:873]: Received Outgoing Call Reply.
    Dec  7 17:54:37 localhost pptp[20477]: anon log[ctrlp_disp:pptp_ctrl.c:912]: Outgoing call established (call ID 0, peer’s call ID 4864).
    Dec  7 17:54:39 localhost pppd[20464]: CHAP authentication succeeded
    Dec  7 17:54:40 localhost pppd[20464]: LCP terminated by peer (MPPE required but peer refused)
    Dec  7 17:54:40 localhost pptp[20477]: anon log[pptp_read_some:pptp_ctrl.c:559]: read returned zero, peer has closed
    Dec  7 17:54:40 localhost pptp[20477]: anon log[callmgr_main:pptp_callmgr.c:259]: Closing connection (shutdown)
    Dec  7 17:54:40 localhost pptp[20477]: anon log[ctrlp_rep:pptp_ctrl.c:254]: Sent control packet type is 12 ‘Call-Clear-Request’
    Dec  7 17:54:40 localhost pptp[20477]: anon log[pptp_read_some:pptp_ctrl.c:559]: read returned zero, peer has closed
    Dec  7 17:54:40 localhost pptp[20477]: anon log[call_callback:pptp_callmgr.c:79]: Closing connection (call state)
    Dec  7 17:54:40 localhost pppd[20464]: Modem hangup
    Dec  7 17:54:40 localhost pppd[20464]: Connection terminated.
    Dec  7 17:54:40 localhost avahi-daemon[1228]: Withdrawing workstation service for ppp0.
    Dec  7 17:54:40 localhost pppd[20464]: Exit.

    ——-
    What that mean?Thanks

  • Anonymous

    Here is why : LCP terminated by peer (MPPE required but peer refused)
    You should disable encryption requirement on client.

  • LAU

    I’ve used your method a number of times, most recently on a Raspberry Pi running OpenELEC, for which there is no GUI to do VPN.  It seems to work nicely each time.  Thanks for the post.

  • AdminseHow

    You are most welcome 🙂

  • Hazem Mashlah

    I am trying to do the same but the file /etc/ppp/options.pptp does not exist

  • AdminseHow

    May be you have not installed pptp 🙂 also the name of options.pptp may be different on different distributions.

  • Mazay0

     2 William Zhang:
    I think, that the problem is here: “MPPE required but peer refused”
    Edit /etc/ppp/options.pptp to add an option “require-mppe-128” or something similar.

    PS
    Wonderful instruction, BTW.

  • Diego

    eap: unknown authentication type 26; naking… This send to me whem I run

    pppd pty “pptp IP_OR_FQDN_VPN_SERVER –nolaunchpppd” file /etc/ppp/options.pptp user USERNAME password PASSWORD command

  • Pingback: Can Of Code | Revisiting the web()

  • Aroop “Finlay” Roelofs

    I can’t get it to work:

    anon fatal[get_ip_address:pptp.c:437]: getaddrinfo(): Name or service not known

Powered by WordPress