Set up VPN to a MS Exchange or VPN Server on Command line.

This method of using the VPN via a script works great in crunchbang and I hope other linux systems where the gui is either not available or you prefer to use scripts rather than heavy memory hogging gui's.

Install PPTP Client

First of all we need to install the pptp application:

 # sudo apt-get install pptp-linux

This script will configure everything for you, that's right no messing about no configuring files, just let the script do the hard work for you.

Copy and paste the following into your favorite editor, I used vi

 vi /usr/local/bin/vpnconnect.sh
#!/bin/bash
function routeadd {
   route add -host 61.xxx.xxx.xxx dev ppp0
   route add -host 62.xxx.xxx.xxx dev ppp0
   route add -host 63.xxx.xxx.xxx dev ppp0
}
function makepptp {
   echo pty \"pptp VPN.SERVER.COM --nolaunchpppd\" >> /etc/ppp/peers/pptpvpn;
   echo remotename PPTP >> /etc/ppp/peers/pptpvpn;
   echo require-mppe-128 >> /etc/ppp/peers/pptpvpn;
   echo file /etc/ppp/options.pptp >> /etc/ppp/peers/pptpvpn;
   echo ipparam pptpvpn >> /etc/ppp/peers/pptpvpn;
pppd call pptpvpn &
}
if [ -a /etc/ppp/chap-secrets ];
		then
		rm /etc/ppp/chap-secrets
	echo $1 PPTP $2 '*' >> /etc/ppp/chap-secrets;
else
	echo $1 PPTP $2 '*' >> /etc/ppp/chap-secrets;
fi
 
if [ -e /etc/ppp/peers/pptpvpn ];
	then
	rm /etc/ppp/peers/pptpvpn;
	echo name $1 >> /etc/ppp/peers/pptpvpn;
	makepptp;
	sleep 8;
	routeadd;
else
	echo name $1 >> /etc/ppp/peers/pptpvpn;
	makepptp;
	sleep 8;
	routeadd;
fi

Replace "VPN.SERVER.COM" with the name or ip address of the VPN Server you are connecting to.

Configure the Routing.

"route add -host 63.xxx.xxx.xxx dev ppp0" This will enable you to communicate with servers on these address. (host name or IP address)

For example your pc maybe on 192.168.1.10 but your work PC may be on 172.19.100.5 to ensure you can connect to this machine your pc needs to route it's packets (data) on the 172 network address, to do this we would need the routing to be 172.0.0.0.

You can add as many routes as required but be careful as it gets harder to work out any errors with multiple routes.

To see your configured routes type:

 # route -

or to see the full resolved route table (takes longer to display) type:

 # route

You can now save and close the file.

Make the new script executable:

 # chmod +x /usr/local/bin/vpnconnect.sh

Now the script has been completed we need to run it and test the connection.

Subsitute the username and password for your vpn username and password, this maybe your work pc login credentials.

 # sudo vpnconnect.sh your_username your_password

Hopefully no errors came up when you ran the script.
You can run some tests to see if it is connected as follows:

 # ifconfig pptp

To disconnect your vpn connection type:

 # killall pppd