Friday, March 23, 2012

PPTP from Command Line

Although this blog is supposed to be about StumpWM, there are things unrelated to the window manager that one needs to do in order to make the transition easier. Since the network manager applet is not available in StumpWM (unless you use a systray program like trayer), you need to know how to do certain tasks without it.

I'm comfortable configuring my network from command line. There was one thing though that I had always done using Network Manager applet; setting up pptp. I googled for it and quickly found this which explains how I can use pptp from the command line.

First you create a file in /etc/ppp/peers. Name the file whatever you want, like myvpn. Put this inside that file:

remotename myvpn
linkname myvpn
ipparam myvpn
pty "pptp <host> --nolaunchpppd "
name <username>
usepeerdns
require-mppe
refuse-eap
noauth

# adopt defaults from the pptp-linux package
file /etc/ppp/options.pptp
Fix the host name and the user name accordingly. Then add a line like this to /etc/ppp/chap-secrets:

<username> myvpn <password> *

Again obviously you need to put your own username and password plus the correct connection name.

I have also created two scripts in /etc/ppp/ip-up.d/ and /etc/ppp/ip-down.d/ to set up the default gateway properly. These scripts are tailored for my own system and you might need to adapt them. the one in ip-up.d/ removes the current default gateway and adds a new one. The other one reverses this.

/etc/ppp/ip-up.d/myvpn:
#!/bin/bash

if [[ $PPP_LOCAL = 192.168.2.* ]]; then
    route del default gw 192.168.1.1
    route add default gw 192.168.2.100
fi
/etc/ppp/ip-down.d/myvpn:
#!/bin/bash

if [[ $PPP_LOCAL = 192.168.2.* ]]; then
    route add default gw 192.168.1.1
    route del default gw 192.168.2.100
fi
Don't forget to make the scripts executable. Also notice that ip-up.d/ and ip-down.d/ are only available in Debian and its derivatives (to learn more about the arguments passed to them and the available environment variables, see the Debian /etc/ppp/ip-up and /etc/ppp/ip-down scripts). Other distros use slightly different paths.

No comments:

Post a Comment

Better Console Font (in Arch)

In order to use Terminus as my console (tty) font, I simply installed the package terminus-font with pacman (includes both console and X11 ...