| 1 |
<h1 id="overview">Overview of VPNs and IPsec</h1> |
| 2 |
<h2 id="vpns">Virtual Private Networks</h2> |
| 3 |
<p>The purpose of a VPN is to create a secure channel ontop of an |
| 4 |
un-secure medium, where a computer or a device are put in each end-point |
| 5 |
in order to establish communication, each of these end-points are often |
| 6 |
reffered to as Point of Presense, or POP. This kind of a communication |
| 7 |
allows the capability of creating a Virtual Private Network, which is |
| 8 |
accesable over a medium such as the Internet and thus, extend the |
| 9 |
physical boundaries of an existing local network.</p> |
| 10 |
<p>VPNs have three forms:</p> |
| 11 |
<dl> |
| 12 |
<dt>Site-To-Site VPNs</dt> |
| 13 |
<dd> |
| 14 |
<p>these setups exist in order to extend the local network to create a |
| 15 |
much bigger LAN over the Internet.</p> |
| 16 |
</dd> |
| 17 |
<dt>Network-To-Host or Remote access VPNs</dt> |
| 18 |
<dd> |
| 19 |
<p>where a central VPN server is able to achieve multiple connections, |
| 20 |
often reffered to as RoadWarrior VPNs. (This setup is very common among |
| 21 |
ISPs)</p> |
| 22 |
</dd> |
| 23 |
<dt>Network-To-Network</dt> |
| 24 |
<dd> |
| 25 |
<p>extranet VPNs allow secure connections within branches and business |
| 26 |
partners, they are an extension of a Site-To-Site VPNs.</p> |
| 27 |
</dd> |
| 28 |
</dl> |
| 29 |
<p><img src="./images/site-to-site-vpn.png" alt="site to site" /><br /> |
| 30 |
shows a Site-To-Site VPN diagram.</p> |
| 31 |
<p>IP/VPNs are connections which are based upon IP tunnels. A tunnel is |
| 32 |
a way to encapsulate an IP packet inside another IP packet or some other |
| 33 |
type of packet. Why do we need tunneling? A Virtual Private Network is |
| 34 |
identified by IANA's private IP assignments and so such packet can not |
| 35 |
go beyond the uplink Internet interface.</p> |
| 36 |
<p><img src="./images/tunneling-process.png" |
| 37 |
alt="tunneling process" /><br /> |
| 38 |
shows the tunneling process.</p> |
| 39 |
<p>Several tunneling protocols are available for manifesting VPNs.</p> |
| 40 |
<dl> |
| 41 |
<dt>L2F</dt> |
| 42 |
<dd> |
| 43 |
<p>Layer 2 Forwarding, an older implementation which assume position at |
| 44 |
the link layer of the OSI. It has no encryption capabilities and hence, |
| 45 |
deprecated.</p> |
| 46 |
</dd> |
| 47 |
<dt>L2TP</dt> |
| 48 |
<dd> |
| 49 |
<p>Layer 2 Tunneling Protocol, still no encryption capabilities.</p> |
| 50 |
</dd> |
| 51 |
<dt>PPTP</dt> |
| 52 |
<dd> |
| 53 |
<p>Point-to-Point Tunneling Protocol, and yet again, no encryption.</p> |
| 54 |
</dd> |
| 55 |
</dl> |
| 56 |
<p>As seen, the requirement of encryption enhancement is urgent in order |
| 57 |
to assure authentication, data integrity and privacy. IPsec solves this |
| 58 |
by providing a suite of security measures implemented at layer 3.</p> |
| 59 |
<h2 id="ipsec">IP Security Suite (IPsec)</h2> |
| 60 |
<p>VPN Security is now appearing, this complex things. How so? VPN |
| 61 |
tunnels by themselves are easily maintained by single-standalone tools |
| 62 |
like pppd, l2tpns, stunnel and others. Involving security with VPNs |
| 63 |
though requires more:</p> |
| 64 |
<ul> |
| 65 |
<li><p>authentication, data integrity and privacy</p></li> |
| 66 |
<li><p>keying management</p></li> |
| 67 |
</ul> |
| 68 |
<div class="note"> |
| 69 |
<p>Keys are secrets being shared by two end-points to provide a secure |
| 70 |
mean of communication against a third-party connection from sniffing the |
| 71 |
actual data.</p> |
| 72 |
</div> |
| 73 |
<p>Different ways to handle key management include RADIUS (Remote |
| 74 |
Authentication Dial In User Service) systems which provide AAA |
| 75 |
(Authentication, Authorization and Accounting). Another solution is |
| 76 |
ISAKMP/Oackly - Internet Security Association and Key Management |
| 77 |
Protocol. This solution requires you to posess one of the following:</p> |
| 78 |
<ul> |
| 79 |
<li><p>something you have</p></li> |
| 80 |
<li><p>something you know</p></li> |
| 81 |
<li><p>something you are</p></li> |
| 82 |
</ul> |
| 83 |
<p>The more requirements you meet the more secure is the medium, once |
| 84 |
established. Let's review, something we have is like a certificate, it |
| 85 |
proves who we are. Something we know, is a key, a secret password which |
| 86 |
we were told in a whisper, and something we are is our-fingerprint which |
| 87 |
identifies ourselves from other individuals.</p> |
| 88 |
<h3 id="ipsec-in-depth">IPsec in Depth</h3> |
| 89 |
<p>IPsec consists of two main protocols, an Authentication Header and |
| 90 |
Encapsulation Security Payload, also known as AH and ESP. Although it is |
| 91 |
not bound to these and can be extended (and often is) to other standarts |
| 92 |
such as</p> |
| 93 |
<ul> |
| 94 |
<li><p>Data Encryption Standart (DES and 3DES)</p></li> |
| 95 |
<li><p>Diffie-Hellman (DH)</p></li> |
| 96 |
<li><p>Secure Hash Algorithm-1 (SHA1)</p></li> |
| 97 |
<li><p>Message Digest 5 (MD5)</p></li> |
| 98 |
<li><p>Internet Key Exchange (IKE)</p></li> |
| 99 |
<li><p>Certification Authorities (CA)</p></li> |
| 100 |
</ul> |
| 101 |
<p>We'll be deploying an IKE daemon to handle the key management, which |
| 102 |
uses the Diffie- Hellman cryptography protocol in order to allow two |
| 103 |
parties to establish a connection based upon a shared secret key that |
| 104 |
both parties posess. (Authentication within IKE is handled by MD5 |
| 105 |
hashing)</p> |
| 106 |
<p>IKE is responsible for authentication of two IPsec parties, |
| 107 |
negotiation of keys for encryption algorithms and security associations. |
| 108 |
This process is commonly regarded as two phases:</p> |
| 109 |
<dl> |
| 110 |
<dt>Phase 1: IKE Security Association</dt> |
| 111 |
<dd> |
| 112 |
<p>The IKE daemon authenticates against the peers in order to achieve a |
| 113 |
secure channel, according to the Diffie-Hellman key agreement.</p> |
| 114 |
</dd> |
| 115 |
<dt>Phase 2: IKE IPsec Negotiation</dt> |
| 116 |
<dd> |
| 117 |
<p>After achieving an authenticated channel, the parties now negotiate a |
| 118 |
secure transform (the way to encrypt and secure the medium) where the |
| 119 |
sender is offering his/hers transform set after which the receiver |
| 120 |
decides upon one. An IPsec session can now safely begin.</p> |
| 121 |
</dd> |
| 122 |
</dl> |
| 123 |
<p>Just to be clear, a Security Association is an agreed relation |
| 124 |
between two parties which describes how they will use security services |
| 125 |
(from IPsec) to communicate.</p> |
| 126 |
<h3 id="ipsec-modes">IPsec Modes</h3> |
| 127 |
<p>IPsec can operate in two different modes:</p> |
| 128 |
<dl> |
| 129 |
<dt>Transport mode</dt> |
| 130 |
<dd> |
| 131 |
<p>takes place when two devices (like a station and a gateway (now |
| 132 |
considered a host)) are establishing a connection which upon they both |
| 133 |
support IPsec.</p> |
| 134 |
</dd> |
| 135 |
<dt>Tunnel mode</dt> |
| 136 |
<dd> |
| 137 |
<p>we require tunnel mode when we proxy IPsec connetions between two |
| 138 |
stations behind the IPsec gateway. For example, in a Site-to-Site VPN a |
| 139 |
tunnel mode lives, since it exists in order to provide the stations |
| 140 |
behind these gateways runing the VPN/IPsec to communicate securely. In |
| 141 |
this situation, both end-points are runing an IPsec software.</p> |
| 142 |
</dd> |
| 143 |
</dl> |
| 144 |
<p>In definition, a tunnel mode IPsec is better secured than transport. |
| 145 |
Without going too deep into the ins-and-outs of the technical side, |
| 146 |
transport mode doesn't encapsulate the actual IP layer but only the |
| 147 |
tcp/udp (Transport layer of the OSI) where-as a tunnel mode encapsulate |
| 148 |
both the Transport layer and the IP layer into a new IP packet.</p> |
| 149 |
<p>To summarize, we need VPNs for data-exchange methods and a set of |
| 150 |
IPsec tools for security reasons.</p> |
| 151 |
<h1 id="deployment">VPN Deployment</h1> |
| 152 |
<p>I've assembled another diagram to view the actual VPN setup.<br /> |
| 153 |
<img src="./images/vpn-deployment.png" alt="vpn deployment" /><br /> |
| 154 |
gives a general description of how the network will be layed out in |
| 155 |
real-world scenario.</p> |
| 156 |
<p>We notice that a single Linux box is acting as a Gateway and has all |
| 157 |
the services included with it. This is a bad idea from a security |
| 158 |
prespective but it's easy to just deploy the FreeRADIUS and MySQL |
| 159 |
servers on another machine. Of course the L2TPns and the rest of the |
| 160 |
IPsec tools suite would have to remain on the Gateway box (not |
| 161 |
necessarily the Firewall).</p> |
| 162 |
<p><img src="./images/vpn-process.png" alt="vpn process" /><br /> |
| 163 |
attempts to explain the actual process that the VPN takes and to detail |
| 164 |
the place that each of that application-in-charge takes place.</p> |
| 165 |
<h2 id="deployment-requirements">Requirements</h2> |
| 166 |
<h3 id="deployment-requirements-toolbox">The Toolbox</h3> |
| 167 |
<p>Following is a description of the requirements you will have to |
| 168 |
meet:</p> |
| 169 |
<dl> |
| 170 |
<dt>A Linux box</dt> |
| 171 |
<dd> |
| 172 |
<p>preferably a 2.4.27 kernel or higher.</p> |
| 173 |
<p>Debian is the chosen distribution which means we'll be using apt-get |
| 174 |
for installation, but I'll also focus on basic source tarballs |
| 175 |
installation.</p> |
| 176 |
<p>Dependencies:</p> |
| 177 |
<ul> |
| 178 |
<li>ipsec configuration in the kernel</li> |
| 179 |
</ul> |
| 180 |
</dd> |
| 181 |
<dt>L2TPns</dt> |
| 182 |
<dd> |
| 183 |
<p>an L2TP PPP Termination tool.</p> |
| 184 |
<p>Dependencies:</p> |
| 185 |
<ul> |
| 186 |
<li><p>libcli 1.8.0 or greater</p></li> |
| 187 |
<li><p>tun/tap interface compiled in the kernel or as a module</p></li> |
| 188 |
</ul> |
| 189 |
</dd> |
| 190 |
<dt>FreeRADIUS</dt> |
| 191 |
<dd> |
| 192 |
<p>For authentication, and accounting.</p> |
| 193 |
</dd> |
| 194 |
<dt>MySQL</dt> |
| 195 |
<dd> |
| 196 |
<p>To act as a back-end database for the RADIUS.</p> |
| 197 |
</dd> |
| 198 |
<dt>OpenSwan</dt> |
| 199 |
<dd> |
| 200 |
<p>Provides the ipsec suite package.</p> |
| 201 |
</dd> |
| 202 |
</dl> |
| 203 |
<h3 id="deployment-requirements-kernel">Kernel Support</h3> |
| 204 |
<p>Debian stock kernel 2.4.27 and up are ipsec compatible although if |
| 205 |
you think otherwise check for the kernel-patch-openswan package.</p> |
| 206 |
<h2 id="deployment-installation">Installation</h2> |
| 207 |
<h3 id="deployment-installation-l2tpns">L2TPns</h3> |
| 208 |
<h4 id="deployment-installation-l2tpns-install">Installation</h4> |
| 209 |
<blockquote> |
| 210 |
<p>L2TPns is a layer 2 tunneling protocol network server (LNS). It |
| 211 |
supports up to 65535 concurrent sessions per server/cluster plus ISP |
| 212 |
features such as rate limiting, walled garden, usage accounting, and |
| 213 |
more.</p> |
| 214 |
</blockquote> |
| 215 |
<p>In a personal note - L2TPns is highly configurable for many cases, |
| 216 |
and extremely reliable for production/commerical use.</p> |
| 217 |
<dl> |
| 218 |
<dt>Step 1:</dt> |
| 219 |
<dd> |
| 220 |
<p>Make sure you have libcli-1.8 development package installed:</p> |
| 221 |
<pre><code># apt-cache search libcli |
| 222 |
libcli-dev - emulates a cisco style telnet command-line interface (dev files) |
| 223 |
libcli1 - emulates a cisco style telnet command-line interface |
| 224 |
# apt-get install libcli-dev</code></pre> |
| 225 |
</dd> |
| 226 |
<dt>Step 2:</dt> |
| 227 |
<dd> |
| 228 |
<p>Download the source from <a |
| 229 |
href="http://sourceforge.net/projects/l2tpns/">SourceForge</a>.</p> |
| 230 |
</dd> |
| 231 |
<dt>Step 3:</dt> |
| 232 |
<dd> |
| 233 |
<p>Build and install: <code>make && make install</code></p> |
| 234 |
</dd> |
| 235 |
</dl> |
| 236 |
<div class="note"> |
| 237 |
<p>Alternately, you can skip these steps and simply |
| 238 |
<code>apt-get install l2tpns</code>.</p> |
| 239 |
</div> |
| 240 |
<div class="note"> |
| 241 |
<p>On RPM-based distributions, you should be able to make packages from |
| 242 |
the libcli and l2tpns source tarballs with |
| 243 |
<code>rpmbuild -ta</code>.</p> |
| 244 |
</div> |
| 245 |
<p>Once compiliation is done you will have l2tpns in |
| 246 |
<code>/usr/sbin/l2tpns</code>, and all configuration files can be found |
| 247 |
in <code>/etc/l2tpns/</code>.</p> |
| 248 |
<h4 id="deployment-installation-l2tpns-config">Configuration</h4> |
| 249 |
<p>The only configuration that L2TPns takes is centralized in the |
| 250 |
configuration file <code>/etc/l2tpns/startup-config</code>.</p> |
| 251 |
<pre><code>set debug 2 # Debugging level |
| 252 |
set log_file "/var/log/l2tpns" # Log file: comment out to use stderr, use |
| 253 |
# "syslog:facility" for syslog |
| 254 |
set pid_file "/var/run/l2tpns.pid" # Write pid to this file |
| 255 |
set l2tp_secret "secret" # shared secret |
| 256 |
set primary_dns 212.117.128.6 # Only 2 DNS server entries are allowed |
| 257 |
set secondary_dns 212.117.129.3 |
| 258 |
set primary_radius 192.168.0.1 # Can have multiple radius server entries, |
| 259 |
# but ony one radius secret |
| 260 |
set primary_radius_port 1812 |
| 261 |
set radius_secret "radius_secret" |
| 262 |
set radius_accounting yes |
| 263 |
set radius_dae_port 3799 |
| 264 |
set accounting_dir "/var/run/l2tpns/acct" # Write usage accounting files into specified |
| 265 |
# directory |
| 266 |
set peer_address 192.168.0.1 # Gateway address given to clients |
| 267 |
load plugin "sessionctl" # Drop/kill sessions |
| 268 |
load plugin "autothrottle" # Throttle/snoop based on RADIUS |
| 269 |
load plugin "throttlectl" # Control throttle/snoop with nsctl |
| 270 |
load plugin "snoopctl"</code></pre> |
| 271 |
<p>This is the trimmed down version of probably most of the common |
| 272 |
configuration and even some extra options.</p> |
| 273 |
<p>Important configuration options are highlited and you should adjust |
| 274 |
these to meet your network needs. We can deploy all of the environment |
| 275 |
into one box which is of course not a very good idea from a security |
| 276 |
point of view, but will function just fine. Moreover, we will be using |
| 277 |
aliased IP addresses so once you've decided to move the FreeRADIUS |
| 278 |
daemon to another computer on the LAN it will be fairly easy and won't |
| 279 |
take too much configuration into it.</p> |
| 280 |
<p>Next, we need to setup the IP pool that L2TPns will provide to each |
| 281 |
VPN client. The configuration file is located at |
| 282 |
<code>/etc/l2tpns/ip_pool</code> and should look like the following:</p> |
| 283 |
<pre><code>172.16.21.0/24</code></pre> |
| 284 |
<div class="important"> |
| 285 |
<p>Of course you can change this pool to anything else (IANA IPs |
| 286 |
assigned for private internets only) just make sure it is not |
| 287 |
conflicting with your current LAN network addresses. This means that if |
| 288 |
you've assigned addresses of 192.168.0.1 and 192.168.0.2 to your LAN |
| 289 |
boxes you can't have a pool of 192.168.0.1/24 defined since L2TPns will |
| 290 |
try to route those addresses from the tun device, which is needless to |
| 291 |
say a bad idea...</p> |
| 292 |
</div> |
| 293 |
<p>Next up, creating the access-list for L2TPns.</p> |
| 294 |
<p>Add a username and password into <code>/etc/l2tpns/users</code>:</p> |
| 295 |
<pre><code>admin:12345</code></pre> |
| 296 |
<p>The password may either be plain-text as above, or encrypted with MD5 |
| 297 |
or DES (to distinguish DES from plain-text passwords, prefix the value |
| 298 |
with <code>{crypt}</code>).</p> |
| 299 |
<p>L2TPns utilizes a terminal connection on port 23 which you would feel |
| 300 |
very comfortable in if you have worked with routers and switches devices |
| 301 |
before. The terminal provides control over the ppp termination which is |
| 302 |
why we've created an account to log on to.</p> |
| 303 |
<h3 id="deployment-installation-ipsec">IPsec</h3> |
| 304 |
<h4 id="deployment-installation-ipsec-install">Installation</h4> |
| 305 |
<p>User-space IPsec tools for various IPsec implementations exist for |
| 306 |
linux, among them is the port of KAME's libipsec, setkey, and racoon. |
| 307 |
Others are the OpenSWAN (a successor to the FreeSWAN project).</p> |
| 308 |
<p>Getting IPsec installed is fairly easy with Debian:</p> |
| 309 |
<pre><code># apt-get install openswan</code></pre> |
| 310 |
<p>The OpenSWAN project provides packages for RPM-based |
| 311 |
distributions.</p> |
| 312 |
<p>Alternately, you may download the <a |
| 313 |
href="http://www.openswan.org/code/">source</a> from the OpenSWAN |
| 314 |
project:</p> |
| 315 |
<pre><code># tar xvzf openswan-2.4.4.tar.gz |
| 316 |
# cd openswan-2.4.4 |
| 317 |
# ./configure && make && make install</code></pre> |
| 318 |
<h4 id="deployment-installation-ipsec-config">Configuration</h4> |
| 319 |
<p>OpenSWAN acts as the IKE daemon (remember IKE? it's job is to |
| 320 |
authenticate between the two peers and negotiate a secure medium). We |
| 321 |
will be setting up the IKE daemon as a RoadWarrior configuration, a term |
| 322 |
for remote access VPNs.</p> |
| 323 |
<p>We desire this approach for compatibilty because after our VPN |
| 324 |
solution will be complete any user from a Windows machine will be easily |
| 325 |
ready to connect without any 3rd party applications, same for Linux.</p> |
| 326 |
<p>Configuration files are placed in <code>/etc/ipsec.d/</code>, |
| 327 |
<code>/etc/ipsec.conf</code> and <code>/etc/ipsec.secrets</code>.</p> |
| 328 |
<p>Let's start by choosing the remote client and it's PSK (Private |
| 329 |
Shared Key) <code>/etc/ipsec.secrets</code>:</p> |
| 330 |
<pre><code>hostname_or_ipaddress %any : PSK "mysecretkeyisverylong"</code></pre> |
| 331 |
<p>This is an IP/key pair. The IP or FQDN defines the local peer (like a |
| 332 |
SOHO branch), then the remote host. Here we defined %any for all hosts, |
| 333 |
though it's possible to define only a specific IP. At last, we define |
| 334 |
the key associated with it.</p> |
| 335 |
<p>A better way to create a key is to utilize /dev/random for creating a |
| 336 |
unique key.</p> |
| 337 |
<pre><code># dd if=/dev/random count=16 bs=1 2>/dev/null | xxd -ps</code></pre> |
| 338 |
<p>Next, let's prepare the configuration file |
| 339 |
<code>/etc/ipsec.conf</code>:</p> |
| 340 |
<pre><code>version 2.0 |
| 341 |
config setup |
| 342 |
nat_traversal=yes |
| 343 |
|
| 344 |
conn l2tp |
| 345 |
authby=secret |
| 346 |
pfs=no |
| 347 |
keyingtries=3 |
| 348 |
left=real_ip_address |
| 349 |
leftnexthop=%defaultroute |
| 350 |
leftprotoport=17/%any |
| 351 |
right=%any |
| 352 |
rightprotoport=17/%any |
| 353 |
auto=add |
| 354 |
|
| 355 |
include /etc/ipsec.d/examples/no_oe.conf</code></pre> |
| 356 |
<p>In this file we have first defined version 2 which is a must, then |
| 357 |
enabled NAT Traversal. To understand the importance of this feature |
| 358 |
think of the following scenario: A remote user attempts to connect while |
| 359 |
he's behind a router and therefore NATed. The router has to |
| 360 |
de-encapsulate the packet, change things and then build it up again and |
| 361 |
send it. IPsec doesn't like other people messing with it's packet. |
| 362 |
That's why we solve this issue with NAT Traversal.</p> |
| 363 |
<p>Next up we configure authentication type (certificates, psk, rsa |
| 364 |
keys, etc) then the left and right peers. The default mode OpenSWAN |
| 365 |
takes is tunnel unless told otherwise. I won't go into in-depth |
| 366 |
explanation of every method, you can take a quick look at |
| 367 |
<code>/etc/ipsec.d/examples</code> for more explanation and other |
| 368 |
variations of working with RSA keys, Certificates, host-to-host, and |
| 369 |
more.</p> |
| 370 |
<p>In summary:</p> |
| 371 |
<ul> |
| 372 |
<li><p>We've configured an almost complete IPsec VPN setup.</p></li> |
| 373 |
<li><p>We've installed and configured a VPN server (L2TPns) and our |
| 374 |
IPsec security suite.</p></li> |
| 375 |
<li><p>To control both of them we use: <code>/etc/init.d/l2tpns</code> |
| 376 |
and <code>/etc/init.d/racoon</code> (location of start-up scripts may |
| 377 |
vary on non-Debian systems, or if you've installed from |
| 378 |
source).</p></li> |
| 379 |
</ul> |
| 380 |
<h3 id="deployment-installation-freeradius">FreeRADIUS</h3> |
| 381 |
<p>The VPN setup needs to authenticate against something, that is the |
| 382 |
users database which we chose to be a FreeRADIUS server backed with a |
| 383 |
MySQL database.</p> |
| 384 |
<h4 id="deployment-installation-freeradius-install">Installation</h4> |
| 385 |
<blockquote> |
| 386 |
<p>FreeRADIUS is the premiere open source RADIUS server. While detailed |
| 387 |
statistics are not available, we believe that FreeRADIUS is well within |
| 388 |
the top 5 RADIUS servers world-wide, in terms of the number of people |
| 389 |
who use it daily for authentication. It scales from embedded systems |
| 390 |
with small amounts of memory, to systems with millions of users. It is |
| 391 |
fast, flexible, configurable, and supports more authentication protocols |
| 392 |
than many commercial servers.</p> |
| 393 |
</blockquote> |
| 394 |
<p>Installing on Debian:</p> |
| 395 |
<pre><code># apt-get install freeradius freeradius-mysql</code></pre> |
| 396 |
<p>From source: Download the latest freeradius package from <a |
| 397 |
href="http://freeradius.org/getting.html">freeradius.org</a></p> |
| 398 |
<pre><code># tar xvzf freeradius.tar.gz |
| 399 |
# cd freeradius |
| 400 |
# ./configure && make && make install</code></pre> |
| 401 |
<h4 id="deployment-installation-freeradius-config">Configuration</h4> |
| 402 |
<p>This will appear a bit complex but it isn't, it's just a lot of |
| 403 |
configuration.</p> |
| 404 |
<p>Following are the configurations you need to have in your |
| 405 |
<code>/etc/freeradius/</code> files.</p> |
| 406 |
<p>In this section I will not give you a dump of the configuration since |
| 407 |
they are very long and mostly default. I'll just post which changes to |
| 408 |
make.</p> |
| 409 |
<p>We haven't yet configured MySQL, but it'll come afterwards, don't |
| 410 |
worry.</p> |
| 411 |
<p>Make the following changes to the file |
| 412 |
<code>/etc/freeradius/sql.conf</code>:</p> |
| 413 |
<pre><code>server = "192.168.0.1" |
| 414 |
login = "radius" |
| 415 |
password = "12345678"</code></pre> |
| 416 |
<p>Add the following to the file |
| 417 |
<code>/etc/freeradius/clients.conf</code>:</p> |
| 418 |
<pre><code>client 192.168.0.1 { |
| 419 |
secret = my_secret |
| 420 |
shortname = localhost |
| 421 |
nastype = other |
| 422 |
}</code></pre> |
| 423 |
<p>Don't confuse the secret directive there with IPsec. RADIUS server |
| 424 |
are using secret keys also to identify their allowed NAS (Network Access |
| 425 |
Servers), these are the clients that talk to the RADIUS server.</p> |
| 426 |
<p>Also, change the <code>client 127.0.0.1 {}</code> directive to hold |
| 427 |
the secret "my_secret" like we configured for 192.168.0.1 to avoid |
| 428 |
conflicts.</p> |
| 429 |
<p>Uncomment the <code>sql</code> directive in the |
| 430 |
<code>authorize</code>, <code>accounting</code>, and |
| 431 |
<code>session</code> sections of |
| 432 |
<code>/etc/freeradius/radiusd.conf</code>.</p> |
| 433 |
<p>Now for populating FreeRADIUS with MySQL. If you don't know or |
| 434 |
haven't set root password for MySQL you can do it now with:</p> |
| 435 |
<pre><code># mysqladmin -u root password password_here</code></pre> |
| 436 |
<p>Then add the following to <code>/root/.my.cnf</code>:</p> |
| 437 |
<pre><code>[mysqladmin] |
| 438 |
user = root |
| 439 |
password = password_here</code></pre> |
| 440 |
<p>Create the <code>radius</code> database, using the schema given in |
| 441 |
<code>/usr/share/doc/freeradius/examples/db_mysql.sql.gz</code>.</p> |
| 442 |
<div class="note"> |
| 443 |
<p>It may be necessary to modify the column definition of |
| 444 |
<code>id</code> in the <code>nas</code> table, removing |
| 445 |
<code>DEFAULT '0'</code> such that the definition reads:</p> |
| 446 |
<pre><code>id int(10) NOT NULL auto_increment,</code></pre> |
| 447 |
</div> |
| 448 |
<pre><code># mysqladmin create radius |
| 449 |
# mysql radius |
| 450 |
mysql> source db_mysql.sql |
| 451 |
mysql> GRANT ALL ON * TO 'radius'@'localhost' IDENTIFIED BY 'radius_password';</code></pre> |
| 452 |
<p>All the configuration is now done. Let's add a user to our VPN |
| 453 |
database.</p> |
| 454 |
<pre><code># mysql radius |
| 455 |
mysql> INSERT INTO radcheck values (0, "test", "User-Password", "==", "1234");</code></pre> |
| 456 |
<p>We have now created a user in the database of username |
| 457 |
<code>test</code> and password <code>1234</code>.</p> |
| 458 |
<p>Testing the RADIUS setup is simple using the radtest utility provided |
| 459 |
with it.</p> |
| 460 |
<pre><code># radtest |
| 461 |
Usage: radtest user passwd radius-server[:port] nas-port-number secret [ppphint] [nasname] |
| 462 |
# radtest test 1234 192.168.0.1 1812 my_secret</code></pre> |
| 463 |
<p>radtest sends an Access-Request to the RADIUS server and expects an |
| 464 |
Access-Accept back from it. If you're not getting an Access-Accept from |
| 465 |
the RADIUS you're advised to check the configuration again and see what |
| 466 |
you might have missed.</p> |
| 467 |
<h3 id="deployment-installation-firewall">Firewall Configuration</h3> |
| 468 |
<p>We need to apply a few things to iptables configuration and kernel |
| 469 |
networking.</p> |
| 470 |
<p>First off, we need to accept VPN-specific packets through the |
| 471 |
firewall. Of course you will have to adjust the rules to fits you needs, |
| 472 |
in this case, ppp0 is the Internet interface.</p> |
| 473 |
<pre><code># iptables --append INPUT --in-interface ppp0 -p udp --dport 1701 -j ACCEPT |
| 474 |
# iptables --append INPUT --in-interface ppp0 -p udp --dport 500 -j ACCEPT |
| 475 |
# iptables --append INPUT --in-interface ppp0 -p udp --dport 4500 -j ACCEPT |
| 476 |
# iptables --append INPUT --in-interface ppp0 -p 50 -j ACCEPT</code></pre> |
| 477 |
<p>If you haven't setup your Linux box as a gateway yet then you have to |
| 478 |
allow forwarding/masqing for the boxes on the LAN (and therefore for the |
| 479 |
VPN clients):</p> |
| 480 |
<pre><code># iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE |
| 481 |
# iptables --append FORWARD --in-interface eth0 -j ACCEPT |
| 482 |
# echo 1 > /proc/sys/net/ipv4/ip_forward</code></pre> |
| 483 |
<h1 id="references">References</h1> |
| 484 |
<p><a href="http://www.jacco2.dds.nl/networking/freeswan-l2tp.html">VPN |
| 485 |
Reference</a></p> |
| 486 |
<p><a href="https://code.ffdn.org/l2tpns/l2tpns/">L2TPns Project</a></p> |
| 487 |
<p><a href="http://www.openswan.org">OpenSWAN Project</a></p> |