Linux VPN Guide
Linux VPN Guide will help you to create a Linux-based VPN server which can be accessed from any Windows client (primarily Windows XP, but can be extended to work with older Windows operating systems such as Windows 2000 or 95/98/NT). I wrote this guide because of the pain I went through to get VPN up and running at my work. After a couple of days of struggling and heavy debugging I was able to set up a VPN server on Fedora Core 2 and 3 with latest updates. I decided that VPN installation should not be such a nightmare and tried to make everything as simple as possible in this guide.
Linux-Windows VPN Guide with OpenSWAN, l2tpd and pppd
1) Who should use this guide?
If you have a private network that you want to be able to access remotely in VPN (virtual private networking) environment (for example, if you have servers at your workplace that are firewalled from outside with internal IP addresses such as 192.168.x.x and you want to be able to access them from the internet), this guide is definitely for you.
2) Can this guide be used on production servers?
To be honest, I'm not sure yet. I have been using this VPN solution for a while now and haven't had any problems so far. But if you notice any performance/compatibility/stability related issues, please let me know.
3) What about security?
VPN is a secure virtual tunnel, which means security is built into it. However, just like any "bullet-proof" solution out there, it has its own security-related issues. First of all, this guide only shows you how to use PSK (pre-shared security key) method of authenticating a VPN tunnel. Your VPN tunnel is encrypted with this security key and in case the key is stolen (or broken with a brute-force attack), your security is compromised. You can use other methods of encryption based on SSL (secure socket layer), but the process of setting up a VPN server and connecting the clients to it is rather complicated. You can refer to Jacco's VPN tutorial to set up a VPN solution based on SSL. As long as your PSK is very long, unguessable and not prone to a simple brute-force, you should not worry about security.
4) On what operating systems has this guide been tested on?
Installation has been successfully tested on Redhat Linux 9.0 and Fedora Core 1/2/3/4, but it should also work on any other linux flavor. For BSD systems, you would have to obtain source files for OpenSWAN and change some configuration options on l2tpd to be able to compile everything successfully.
5) Stuff we'll be needing (sources)
Download the following sources to a src directory i.e. /usr/local/src
a) OpenSWAN 2.6.14 from http://www.openswan.org | Mirror
b) l2tpd 0.69 from this site
c) l2tpd Legacy PTY patch from this site
d) l2tpd SysV PTY patch from this site
e)l2tpd startup file from this site
6) Assumptions
It is assumed that ppp is already installed on the system and you are running the latest version of linux kernel 2.4 or 2.6. You can check if you have ppp installed on the system by running a query in your package manager ("rpm -q -a | grep ppp" in Redhat or Fedora). You can check the kernel version by running "cat /proc/version".
7) OpenSWAN installation and configuration
I recommend downloading an RPM from openswan.org instead of the source tarball, since the RPM has the patches integrated to fit your system. In case you want to compile OpenSWAN yourself, you will have to find out which patches you need for your system. Compilation and installation from source is pretty straightforward - just read the README file and follow the instructions. Run the following command to see if you already have OpenSWAN installed: "rpm -q -a | grep openswan". If openswan is not installed, proceed with the installation.
cd /usr/local/src<br /> yum install openswan<br /> yum install openswan-doc<br />
The openswan-doc rpm file includes all the documentation which you might need in the future.
The OpenSWAN installation has a sample ipsec.conf file included. Let's go ahead and rename it:
mv /etc/ipsec.conf /etc/ipsec.conf.old
Now copy-paste the following into /etc/ipsec.conf
version 2.0<br />
config setup<br />
interfaces=%defaultroute<br />
klipsdebug=none<br />
plutodebug=none<br />
overridemtu=1410<br />
nat_traversal=yes<br />
virtual_private=%v4:10.0.0.0/8,%v4:172.16.0.0/12,%v4:192.168.0.0/16</p>
<p>conn %default<br />
keyingtries=3<br />
compress=yes<br />
disablearrivalcheck=no<br />
authby=secret<br />
type=tunnel<br />
keyexchange=ike<br />
ikelifetime=240m<br />
keylife=60m</p>
<p>conn roadwarrior-net<br />
leftsubnet=192.168.0.0/16<br />
also=roadwarrior</p>
<p>conn roadwarrior-all<br />
leftsubnet=0.0.0.0/0<br />
also=roadwarrior</p>
<p>conn roadwarrior-l2tp<br />
leftprotoport=17/0<br />
rightprotoport=17/1701<br />
also=roadwarrior</p>
<p>conn roadwarrior-l2tp-updatedwin<br />
leftprotoport=17/1701<br />
rightprotoport=17/1701<br />
also=roadwarrior</p>
<p>conn roadwarrior<br />
pfs=no<br />
left=150.150.150.150<br />
leftnexthop=150.150.150.1<br />
right=%any<br />
rightsubnet=vhost:%no,%priv<br />
auto=add</p>
<p>#Disable Opportunistic Encryption<br />
include /etc/ipsec.d/examples/no_oe.conf<br />
Don't forget to replace "150.150.150.150" with your external IP address and "150.150.150.1" with your default gateway. I'm not going to explain what each line above does. If you want to find out for yourself, please refer to OpenSWAN documentation. The above configuration should work for most people, though.
Now edit the file "/etc/ipsec.secrets" and put the following:
150.150.150.150 %any: PSK "a_very_long_string_up_to_256_characters"
The format of the file is: "external_network_address connecting_from: PSK password". Change "150.150.150.150" to your external IP address. If you want to be able to access the network from anywhere on the Internet, leave "%any" intact. I recommend specifying the IP address of the machine that will be used to initiate VPN connections for security reasons though. PSK stands for "Pre-Shared Key" - it's the key that will be shared by both the server and the client for authentication. Make sure that the key is long (up to 256 characters) and very random. Every client trying to establish a VPN connection will have to provide this pre-shared key.
8) l2tpd installation and configuration
First of all, let me give you some information on l2tpd. The project started out really well and a big community was involved in its development. But seems like the project has been suspended for some reason and there haven't been any new releases of l2tpd since version 0.69 which is more than a year old. Latest versions of the linux distributions such as Fedora and Mandrake are compiled with a new SysV pty system. The current version of l2tpd only supports the old pty system and therefore will not work on these distros unless its patched. Jacco de Leeuw talks about this problem in his detailed VPN guide here. An alternative is to switch to rp-l2tp, which is another l2tpd daemon. But it is not a good way out, since it does not support automatic IP allocations to new connections. Another solution is to recompile the kernel with "Legacy (BSD) PTY support", but most people simply don't know how to do that or are too scared to do it. Recompiling the kernel might be a big problem for those who don't have physical access to the machine. After many hours of googling, I was able to find some patches that fix current l2tpd issues and add some features such as binding l2tpd to a specific IP address. Now here is the interesting part - the rp-l2tp package contains pty.c code that is known to work with the new pty system. I tried to simply copy-paste the script into l2tpd pty.c file, modified l2tpd.c to call "pty_get" instead of the old "getPtyMaster", removed all other pty calls and it worked! I was able to test l2tpd setup successfully on a Fedora Core 3 machine without recompiling the kernel :)
I have included two patches on this page. If you have a recent version of a linux distribution with 2.6 kernel, go ahead and download the file "l2tpd-0.69.sysv.patch". If you have an older version of linux with the old pty system, go ahead and download the file "l2tpd-0.69.lpty.patch".
Now, let's install l2tpd and apply the patch:
cd /usr/local/src<br /> tar zxf l2tpd-0.69.tar.gz<br /> mv l2tpd-0.69.sysv.patch l2tpd-0.69/<br /> mv l2tpd /etc/rc.d/init.d/<br /> cd l2tpd-0.69<br /> patch < l2tpd-0.69.sysv.patch<br /> make<br /> cp l2tpd /usr/sbin<br /> chmod 755 /usr/sbin/l2tpd
Running "make" should compile an l2tpd executable without errors. You might get a couple of warnings, but no fatal errors. If you try to compile the source without patching it first, you will most probably get compilation errors (especially on systems with a newer gcc). Now configure the startup environment:
chmod 755 /etc/rc.d/init.d/l2tpd<br /> chkconfig --add l2tpd<br /> chkconfig l2tpd on
Let's move on to configuring l2tpd. The configuration files for l2tpd should be placed in "/etc/l2tpd" folder. Go ahead and create the folder, then copy paste the following into l2tpd.conf:
[global]<br /> port = 1701</p> <p>[lns default]<br /> ip range = 192.168.1.101-192.168.1.254<br /> local ip = 192.168.1.100<br /> require chap = yes<br /> refuse pap = yes<br /> require authentication = yes<br /> name = LinuxVPN<br /> ppp debug = yes<br /> pppoptfile = /etc/ppp/options.l2tpd<br /> length bit = yes
The "ip range" line is the start and the end pool of the IP addresses the clients will be given when they establish a VPN connection (on their end). The "local ip" is server IP address - it's used only when at least one connection is established. If you have a different internal network, go ahead and change both lines. Everything else should work for most people. Again, if you want to find out what each line does, please feel free to refer to l2tpd documentation.
9) PPP configuration
L2TP tunnels through PPP, which is why we need to configure it to work with l2tpd. The l2tpd configuration above specifies the "/etc/ppp/options.l2tpd" file as "pppoptfile" (PPP options file). Go ahead and create this file and copy-paste the following:
ipcp-accept-local<br /> ipcp-accept-remote<br /> ms-dns 192.168.1.2<br /> ms-wins 192.168.1.3<br /> noccp<br /> auth<br /> crtscts<br /> idle 1800<br /> mtu 1410<br /> mru 1410<br /> nodefaultroute<br /> debug<br /> lock<br /> proxyarp<br /> connect-delay 5000<br /> silent<br />
Change the line "ms-dns" to your real DNS server and "ms-wins" to your WINS server (if you have any).
Now let's create the authentication files. We use CHAP for PPP authentication. Go ahead and edit the file "/etc/ppp/chap-secrets". The format of this file should be "client server secret IP addresses". Here is a sample file:
# Secrets for authentication using CHAP<br /> # client server secret IP addresses<br /> username * "password" 192.168.1.0/24<br /> * username "password" 192.168.1.0/24<br />
You need two lines for each username because it's a two-sided authentication - one from client to server and one from server to client. Both the password and the IP address pool should be the same for both lines. The IP address network that we specify here (192.168.1.0/24) means "allow this username to get an IP address in the range 192.168.1.0 - 192.168.1.255". The l2tpd configuration file above specifies the range to be 192.168.1.101-192.168.1.254, so only the IPs in this range are given to the client on successful authentication. You can change the networks and subnets in both files as needed. If you need more than one account to be able to access the server, go ahead and add it in the same format.
10) Starting and testing VPN
Everything is installed and configured. Let's go ahead and start the daemons:
Starting l2tpd:
/etc/rc.d/init.d/l2tpd start<br /> Starting l2tpd: [ OK ]
Starting OpenSWAN:
/etc/rc.d/init.d/ipsec start
ipsec_setup: Starting Openswan IPsec 2.4.0...
ipsec_setup: insmod /lib/modules/2.6.10-1.741_FC3/kernel/net/key/af_key.ko
ipsec_setup: insmod /lib/modules/2.6.10-1.741_FC3/kernel/net/ipv4/xfrm4_tunnel.ko
Take a look at /var/log/messages and /var/log/secure and make sure there are no errors. You should see notification messages such as "l2tpd: l2tpd startup succeeded" and "ipsec_setup: Starting Openswan IPsec 2.4.0...". If there are no errors, everything is up and running - proceed to next step.
11) Firewall configuration
To be able to route packets from your external to internal interfaces, packet forwarding must be turned on. Edit /etc/sysctl.conf and change "net.ipv4.ip_forward = 0" to "net.ipv4.ip_forward = 1". If you don't have that file, just type "echo 1 > /proc/sys/net/ipv4/ip_forward" and add this line to your /etc/rc.d/rc.local file. Restart your networking by typing "/etc/rc.d/init.d/network restart" or whichever way you restart your network interfaces.
Make sure that the following ports are open: UDP 500 & 4500, TCP 4500. If any of these ports are blocked, VPN will not work. If you have Redhat/Fedora distributions with iptables, insert these lines into your /etc/sysconfig/iptables file, before REJECT line at the end of the file:
-A RH-Firewall-1-INPUT -i ppp+ -j ACCEPT<br /> -A RH-Firewall-1-INPUT -i eth1 -j ACCEPT<br /> -A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 500 -j ACCEPT<br /> -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 4500 -j ACCEPT<br /> -A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 4500 -j ACCEPT
One more thing you should keep in mind while changing your firewall configuration - your internal and VPN network should be trusted, otherwise your firewall will keep rejecting packets from 192.168.x.x network into your LAN. I solve this by simply adding the first two lines above into my iptables file. The interface eth0 is external and eth1 is physically inside my internal network, of course :)
Related posts:
02/03/2005 - 09:00
Hello
Your tutorial looks really nice, I am going to try it with SuSE. I will give you my feedback with the good init scripts. Maybe something missing in your tutorial is a network topology of what you are doing (what are the gateways, left sides, right sides etc..).
BTW, good job :)
03/08/2005 - 11:08
thanks,
have you tried certificate authentication?
03/14/2005 - 20:22
The best!!!! Thank you very much!
03/17/2005 - 00:40
Can we make this work on direct ethernet connection? or do we need PPPoE to solve that purpose? I am confused…
03/18/2005 - 11:14
Excelent guide!! Congratulations.
And thank you very much for the Pty patch for L2TPD. It solved my problem on Fedora Core 3.
Best regards, Alan.
04/28/2005 - 09:17
hmm.. wonder why i cannot compile the ” l2tpd ” im using Redhat 9, any suggest ?
05/13/2005 - 05:40
I did well till point 9)
I also got success to start using ‘/etc/rc.d/init.d/l2tpd start’ command.
But while starting openswan ,it gives me error like
“– ’start’ abortedpsec.conf,line 2) unknown config section “setup
What is it means?
Pls suggest something to resolve this issue.
Thanks and regards
Vishal S.
06/08/2005 - 19:53
Great Idea!! It was a great HELP! thank you
06/11/2005 - 08:28
I did well till point 9)
I also got success to start using ‘/etc/rc.d/init.d/l2tpd start’ command.
But while starting openswan ,it gives me error like
“– ’start’ abortedpsec.conf,line 2) unknown config section “setup
What is it means?
Please suggest something to resolve this issue.
Big thanks and regards
06/27/2005 - 09:04
Hi, sorry for disturbance but I don’t understand a step about l2tpd installation:
mv l2tpd /etc/rc.d/init.d
.. but at this point I don’t have a l2tpd file ?? where I mistake ??
thanks.
Salvatore.
06/27/2005 - 09:48
Hi and sorry for my banal question but when excute:
chkconfig –add /etc/rc.d/init.d/l2tpd
I have how result then l2tpd not supported chkconfig, but pheraps the problem is then I have copied the incorrect l2tpd file in /etc/rc.d/init.d/, but where is the correct l2tpd file for chkconfig ??
I have used alway rpm file and now I have a difficult.
still thanks.
Salvatore.
07/18/2005 - 10:06
Hi all,
Thanks for the guide – it worked perefectly.
I just have 2 questions:
1 – Is it possible to log the username of a rodawarrior logging in, not just the ip? If so, how?
2 – Our internal LAN is split into 2 subnets. When a roadwarrior connects, he gets an ip on our subnet A, but no gateway to subnet B (this is our default gateway on the LAN). The results in the roadwarrior having perfect access to subnet A but not B. The actual VPN box can reach both subnets with no problems. How can I get the roadwarrior to access both subnets?
Any help would be greatly appreciated.
Regards
Shafi
08/17/2005 - 00:40
I also wonder if we can we make this work on direct ethernet connection? if we could then how? And thank very much….
09/01/2005 - 04:15
Help. Everything seems to be going fine until chkconfig –add l2tpd returns the crptic message ‘No such device’. Google reveals nothing relevant.
What am I doing wrong?
09/20/2005 - 11:35
Hi,
wanted to know whether anyone had success downloading the patches. When I try to download the patches and the startup file, they show up as text files. should I cut and paste the contents to the right file names? Pls help. Thanks
praveen
09/24/2005 - 01:41
Hai All.
Installed everything without a hitch on a FC3 Box, tried the same thing on a FC4 Box, and now I get the following error:
aaa.c:28: error: static declaration of âuaddrâ follows non-static declaration
aaa.h:49: error: previous declaration of âuaddrâ was here
(…)
make: *** [aaa.o] Error 1
I have applied the sysv patch!
Any help would be appreciated!
Kind regards,
Onno.
09/26/2005 - 00:58
[b]Onno:[/b] remove the word “static” before “struct addr_ent *uaddr[ADDR_HASH_SIZE];” in file aaa.c (line 28) and it will compile fine :)
09/27/2005 - 14:35
Hi,
I installed everything, but my left side is not the same as Nasim’s configuration. The Linux box is behind a router that hands out the DHCP addresses. The linux box has a static IP within the subnet. I am allowing vpn passthroughs for port UDP/TCP 500 and 4500 as well as 1723. How does the configuration change with the above setup, meaning how do I setup the conf files? I tried a couple of changes to mimic the local segment but to no avail. Anybody have this setup? Please help. I feel I am close but have a problem with some configuration items. Specifically, I am getting errors 789 and 792 on the windows VPN client. Thanks for your help.
praveen
11/12/2005 - 12:19
I have installed everthing like the guide said.
But in the secure log i see the following
initial phase 1 message is invalid: its Encrypted Flag is on
sending notification INVALID_FLAGS to
Can anybody help me?
Erik
01/11/2006 - 16:04
Hi
I have o problem with ipsec , when i try to start show this messege.
/etc/init.d/ipsec: (/etc/ipsec.conf, line 3) section header “interfaces=%defaultroute” has wrong number of fields (1) — `start aborted [FAILED]
I have a linux box whit FC3 and openswan-2.4.4-0.FC3.1 , kernel 2.6.12-1.1381_FC3
01/13/2006 - 11:40
jhony, I ran into the same problem where %defaultroute was bombing on me when starting the service. The problem was the indentation of ipsec.conf was not showing properly within the instructions. The instructions look to be updated now.
02/18/2006 - 02:08
hi there,
this guide is works!
everything is going fine, but i still have a bug,
why this vpn cannot connect multiple user to server?
i mean if im logged in and my friend wants to connect too, he cant connect
im checking tail -f /var/log/secure and /var/log/mesages no indicator that my friend is rejected
although we use different user?
any one have same problem with me?
any one help me?
:’(
thanks
03/15/2006 - 10:03
Thanx for this great howto! Building a VPN server has never been so simple. But I have a little problem getting my connections to work. I used your ipsec.conf, and only changed the relevant IP-addresses. Now every time I try to connect from some remote computer, I get an error message (in /var/log/messages) saying “cannot respond to IPsec SA request because no connection is known for [my PUBLIC ip-address]/32===[local IP of my VPN server]:17/1701…[public IP of remote computer][@Username]:17/1701″. The server then sends an encrypted notification INVALID_ID_INFORMATION to the remote computer.
What am I doing wrong? Could you please help me?
05/02/2006 - 21:48
Not work whit shorewall 3.x firewall, any idea for configuring?. Read a wiki shorewall, but not a clear info for this pruposes. Help please, thanks.-
06/22/2006 - 12:02
Wonderful web site, for VPN solution.
06/25/2006 - 23:03
Thanks for this guide.I m able to stablish vpn connection but only one client can access the server.I have already add the client in /etc/ppp/chap-secrets.But it can’t work.How can I give permission to unlimited access(client)?
07/11/2006 - 02:52
This is perfect but to install a VPN server in fedora core5 you do not have to patch l2tpd.
Just yum that with
yum install l2tpd
yum install Openswan
and follow the same configuration options.
Thanks
08/02/2006 - 06:55
Simple reporting for the L2TPD/IPSEC VPN Server
1. place the following script in your /etc/cron.hourly directory
#————————————————————————-
#!/bin/sh
# retrieve date in 3 letter form and assign the value to DTNOW
DTNOW=`date`
# retrieve date in 3 letter form and assign the value to P1
P1=`date +%b`
# retrieve day of the month in leading space removed format and assign it to P2
P2=`date +%e`
# retrieve Hour in 24 format and assign it to P3
P3=`date +%H`
# retrieve the integer value of P3 and decrement it by one because
# the script is run hourly and searches for the last hour access
P4=`expr $P3 – 1`
# Create a file in the /tmp directory
# a randomly named file
echo > /tmp/k30fsf98.log
echo -e “VPN Connections made from $P4:00 to $P3:00 on $DTNOW and closed\r\n”>> /tmp/k30fsf98.log
echo -e “Total Number of Connections: \r\n” >> /tmp/k30fsf98.log
grep “$P1 $P2 $P4″ /var/log/messages | grep “name = ” | grep Response | wc -l >> /tmp/k30fsf98.log
echo -e “Connection details: \r\n” >> /tmp/k30fsf98.log
grep “$P1 $P2 $P4″ /var/log/messages | grep “name = ” | grep Response >> /tmp/k30fsf98.log
echo -e “\r\n” >> /tmp/k30fsf98.log
grep “$P1 $P2 $P4″ /var/log/messages | grep “Connection closed” >> /tmp/k30fsf98.log
echo -e “\r\n” >> /tmp/k30fsf98.log
grep “$P1 $P2 $P4″ /var/log/messages | grep “: Connect time” >> /tmp/k30fsf98.log
cat /tmp/k30fsf98.log | mail -s “Hourly VPN log from $P4 and $P3 on $DTNOW” SOME_EMAIL@SOME_DOMAIN.COM
#—————————————————————————
2. Replace SOME_EMAIL@SOME_DOMAIN.COM with the email that is supposed to receive the hourly access report.
HOSSEIN
11/06/2006 - 04:38
hello everyone
this guide just rocks
can any body guid me how we can configure l2tpd/ipsec client for linux machine
thanks
04/09/2007 - 08:31
How can I configure this with windows 2000, and some other versions of windows??
04/09/2007 - 09:07
hi
when i first saw your name i guess that you are iranian ( as i am iranian).
i comment here to say that your guide help me a lot. but i am writing a guide in persian
for debian release and i want to use some part of your articles.
Do u know persian?
can use your article in my guide?
tanx
its an honor for me if you came to my very very small weblog. tanx again
05/30/2007 - 15:18
hi
Thanks for your help;your guide I help myself much.
Thanks again
06/11/2007 - 02:01
would you like to give me flow chart to descript your VPN (L2TP with IPsec)…???
i hope you will help me….tahnx before.-ian- (sorry, if my english is not good :D )
06/14/2007 - 15:53
Hello Ian if you speak Spanish i will help you with your VPN (L2TP with IPsec)
07/17/2007 - 00:16
do you have VPN Linux configuration with radius as database authentication?
07/17/2007 - 00:19
may i know howto IPsec work at ur VPN configuration??
for my thesis :D thank
04/03/2008 - 00:19
hi to all,
I need help in creating a vpn connection between winxp and fedora where fedora is acting as server while winxp is client.
on server openswan is installed while using l2tp ipsec vpn on windows.
my mail id : techsolnltd at gmail dot com
Regards
05/15/2008 - 04:48
I followd all of youre steps and while connecting from XP with SP2 i get error no. 721 after saying verifying username and passwod. can you trace what is my my error
12/10/2008 - 05:18
Hi
It is the most comprehensive document on VPN which I have come across and everything worked fine on RHEL5 and it is functioning in it’s first attempt :-) thanks for everything
dillip
02/06/2009 - 06:07
Hi, can comebody let me know what is the configuration required on the Linux client.
02/20/2009 - 16:03
I’ve now employed Hamachi as well and ditched the problematic MS VPN solution.
There would be miss dials, I’d have to restart the
“Routing and Remote Access” service sometimes as well as power cycle the modem.
Now I have no issues. Install Hamachi on the client pc’s and set their
hosts file up and all is well. The notebook users benefit as well.
Hamachi is intelligent and knows when to use the
Local Area Network to peer when it can.
When remote and there is an internet connect a route is found via the net.
Hamchi – it just works – it’s great!!!
05/27/2009 - 05:25
I have to wonder how that comparison would fare if it was Vista vs Linux? We bought a new HP Vista machine and converted an old WIn 2K based desktop to SUSE Linux – http://file.sh/SUSE+Linux+torrent.html . After 2 months the hassles with Linux are far fewer! There are hassles with both, but the Linux hassles are well documented and Novell ($60 SUSE Linux support) actually DOES provide solutions in real English! We are preparing to convert the new machine to Linux as well.