Last Updated: February 25, 2016
·
2.042K
· sebas5384

Connect your self to a PPTP VPN server

Big companies use things like VPNs to give you access to some servers, and thats cool when you have a nice graphical interface to do that.

But!! when it comes to connect a GNU/Linux machine to a VPN PPTP with only a command line available, you can take some good time till discover how to do that.

So, I'm going to explain in a very short way how to establish your connection to the VPN, and we are going to name it my-vpn.

1. Install the software that you will need

sudo apt-get install pptp-linux

2. Create a configuration file for the peer connection

sudo vi /etc/ppp/peers/my-vpn

Then put the configuration parameters

Replace "vpn-server.your-client.com" with the real url of the VPN server and "taller" with the VPN user name.

# Url of the VPN server.
pty "pptp vpn-server.your-client.com --nolaunchpppd"
remotename my-vpn
linkname my-vpn
ipparam my-vpn
# VPN user name.
name taller
usepeerdns
require-mppe
refuse-eap

# Adopt defaults from the pptp-linux package.
file /etc/ppp/options.pptp

3. Configure the connection credentials.

sudo vi /etc/ppp/chap-secrets

Put the credentials

Replace taller with your VPN user name and PASSWORD with the password.

# Secrets for authentication using CHAP
# client    server  secret  IP addresses
taller  my-vpn  123456      *

4. Let's connect our selves.

sudo pon my-vpn nodetach &

Now if everything goes as expected, check if a new lan interface named ppp0 Point-to-Point Protocol.

ifconfig

5. But! that's not it!! must route some of the traffic to the VPN.

Let's create a file to always have this route up and running.

sudo vi /etc/ppp/ip-up.d/my-vpn 

Put the routing rule. Take a look at the IP range, maybe in your VPN is different.

#!/bin/bash
route add -net 192.168.0.0/24 dev ppp0

Make it executable, and run it!

sudo chmod +x /etc/ppp/ip-up.d/my-vpn
sudo /etc/ppp/ip-up.d/my-vpn

6. Resolving domains.

We could config a some DNS to resolve the domains inside the VPN, but I prefer doing manually, so the traffic is all controlled. See this post for how to do the resolving thing.

sudo vi /etc/hosts

...and put this for example:

192.168.0.12    ldap-server.my-client.com

6. DONE !!

If you want to unplug the VPN connection, just do this:

sudo poff my-vpn

There are some other ways to do it, but this one, worked for me!! and now I can connect to my client LDAP through his VPN.