Sunday, August 24, 2008

Connect to a VPN using the PPTP (Microsoft propietary) protocol under openSuse 11.0 Linux

I use openSuse but it surely work under other distros too.
I did some research and I didn't found much information about this on the web, that is why I am writing this little article.
Install the “pptp” package, it comes with two binaries:
“pptp” and “pptp-command”, we will be using “pptp-command” for everything.
As root run:
# pptp-command

it will present four options:
1.)start
2.) stop
3.) setup
4.) quit

We need first to setup the connection so we select: 3
it will present 8 options

1.) Manage CHAP secrets
2.) Manage PAP secrets
3.) List PPTP Tunnels
4.) Add a NEW PPTP Tunnel
5.) Delete a PPTP Tunnel
6.) Configure resolv.conf
7.) Select a default tunnel
8.) Quit

First we need to authenticate, so we have to select 1 or 2 depending on the kind of authentication the server use.
When I configure it, the server I was trying to connect use CHAP so lets select 1
It will present:

1.) List CHAP secrets
2.) Add a New CHAP secret
3.) Delete a CHAP secret
4.) Quit

We need to add a new CHAP secret, so we select: 2
first the program ask for the Local Name,

Local Name: myusername

there put the username of your vpn account, then it asks for the Remote Name [PPTP]

Remote Name [PPTP]:

there in most cases we can leave the default (see the explanation), so we left it blank... then it asks for the password of your vpn account

Password: mypassword

there we put the password.
Once this is done the CHAP secret is added, then we go back(or we can do any other task that the program offers), we press 4.

The main menu appears again and we need to add a new PPTP tunnel so we select option 4

Add a NEW PPTP Tunnel.

1.) Other
Which configuration would you like to use?: 1
Tunnel Name: thenameofmytunnel
Server IP: serverdir
What route(s) would you like to add when the tunnel comes up?
This is usually a route to your internal network behind the PPTP server.
You can use TUNNEL_DEV and DEF_GW as in /etc/pptp.d/ config file
TUNNEL_DEV is replaced by the device of the tunnel interface.
DEF_GW is replaced by the existing default gateway.
The syntax to use is the same as the route(8) command.
Enter a blank line to stop.
route: add-net 192.168.10.0 netmask 255.255.255.0 dev TUNNEL_DEV
Local Name and Remote Name should match a configured CHAP or PAP secret.
Local Name is probably your NT domain\username.
NOTE: Any backslashes (\) must be doubled (\\).

Local Name: myusername
Remote Name [PPTP]:
Adding thenameofmytunnel - serverdir - myusername
Added tunnel thenameofmytunnel

It asks for the configuration to use, we select Other (there Is no any other choice), then it asks for the “Tunnel Name” we put there the name which you want to identify your tunnel, put it the way you want.
Then it asks for the Server IP, put there the ip or name of the server which you want to connect to.
Then it asks for the route, using the same syntax of the linux route command, you can put in there(for example): add-net 192.168.10.0 netmask 255.255.255.0 dev TUNNEL_DEV, so that the operating system knows that every packet send to the network 192.168.10.0 with the netmask 255.255.255.0 should use the device of the tunnel interface, here the program replaces TUNNEL_DEV with the name of the device of your vpn connection (generally ppp0). For this you should know the internal of the network behind your vpn connection.
You could also left this blank and add the route from the operating system like this:
#route add -net 192.168.10.0 netmask 255.255.255.0 dev ppp0
but in this case it will be lost when you reboot the machine.

At last it ask for the “Local Name” and the “Remote Name”, this have to match the ones you put in your CHAP secrets, remember that the local name is the username of your vpn account and the Remote Name we leave it blank.

Once this is done we just quit and then we type again the pptp-command as root but here we select 1 (start), you could have also typed:
#pptp-command start

It asks for the connection you want to use, and thats it!, you should be connecting to your vpn.

If you need to connect to a machine in your vpn that uses the RDP protocol which come installed with windows, you can download the package “rdesktop” and type:
>rdesktop -zfk keymap machineip , you can look at the installed keymaps doing a
>locate keymap and see the ones that are installed inside ..rdesktop/keymaps this is important because by default it uses the english keymap, so if your keyboard is not english then you might have the keys changed.

You can take a look at http://pptpclient.sourceforge.net for more details