Numbering private subnets
Setting up a VPN often entails linking together
private subnets
from different locations.
The Internet Assigned Numbers Authority (IANA) has
reserved the
following three blocks of the IP address space for private internets
(codified
in RFC 1918):
| 10.0.0.0 |
10.255.255.255 |
(10/8 prefix) |
| 172.16.0.0 |
172.31.255.255 |
(172.16/12 prefix) |
| 192.168.0.0 |
192.168.255.255 |
(192.168/16 prefix) |
While addresses from these netblocks should
normally be used in VPN configurations,
it's important to select addresses that minimize the probability of IP
address
or subnet conflicts. The types of
conflicts that need to be avoided are:
- conflicts from different sites on the VPN using
the same LAN subnet numbering, or
- remote access connections from sites which are
using private subnets which conflict
with your VPN subnets.
For example, suppose you use the popular
192.168.0.0/24 subnet as your private LAN subnet.
Now you are trying to connect to the VPN from an internet cafe which is
using
the same subnet for its WiFi LAN. You will have a routing conflict
because your machine
won't know if 192.168.0.1 refers to the local WiFi gateway or to the
same address on the VPN.
As another example, suppose you want to link
together multiple sites by VPN, but each
site is using 192.168.0.0/24 as its LAN subnet. This won't work without
adding a complexifying
layer of NAT translation, because the VPN won't know how to route
packets between multiple sites
if those sites don't use a subnet which uniquely identifies them.
The best solution is to avoid using 10.0.0.0/24 or
192.168.0.0/24 as private LAN network addresses.
Instead, use something that has a lower probability of being used in a
WiFi cafe, airport, or hotel
where you might expect to connect from remotely. The best candidates
are subnets in the middle of the
vast 10.0.0.0/8 netblock (for example 10.66.77.0/24).
And to avoid cross-site IP numbering conflicts,
always use unique numbering for your LAN subnets.
Setting up your own Certificate Authority (CA)
and generating certificates and keys for an OpenVPN server and multiple
clients
Overview
The first step in building an OpenVPN 2.0 configuration is
to establish a PKI (public key infrastructure). The PKI consists of:
- a separate certificate (also known as a public
key) and private key
for the server and each client, and
- a master Certificate Authority (CA) certificate
and key which is used
to sign each of the server and client certificates.
OpenVPN supports bidirectional authentication
based on certificates,
meaning that the client must authenticate the server certificate and
the
server must authenticate the client certificate before mutual trust is
established.
Both server and client will authenticate the other
by
first verifying that the presented certificate was signed by the master
certificate authority (CA), and then by testing information in the
now-authenticated certificate header, such as the certificate common
name
or certificate type (client or server).
This security model has a number of desirable
features from
the VPN perspective:
- The server only needs its own certificate/key
-- it doesn't need to
know the individual certificates of every client which might possibly
connect to it.
- The server will only accept clients whose
certificates were signed by
the master CA certificate (which we will generate below). And because
the server can perform this signature verification without needing
access
to the CA private key itself, it is possible for the CA key (the
most sensitive key in the entire PKI) to reside on a completely
different machine, even one without a network connection.
- If a private key is compromised, it can be
disabled by adding
its certificate to a CRL (certificate revocation list). The CRL
allows compromised certificates to be selectively rejected without
requiring
that the entire PKI be rebuilt.
- The server can enforce client-specific access
rights based on
embedded certificate fields, such as the Common Name.
Generate the master Certificate Authority (CA)
certificate & key
In this section we will generate a master CA
certificate/key, a
server certificate/key, and certificates/keys for 3 separate clients.
For PKI management, we will use a set of scripts
bundled with OpenVPN.
If you are using Linux, BSD, or a unix-like OS,
open a shell
and cd to the easy-rsa subdirectory of the OpenVPN
distribution.
If you installed OpenVPN from an RPM file, the easy-rsa directory can
usually
be found in /usr/share/doc/packages/openvpn or
/usr/share/doc/openvpn-2.0 (it's best to copy
this directory to another location such as /etc/openvpn,
before any edits, so that
future OpenVPN package upgrades won't overwrite your modifications).
If you installed
from a .tar.gz file, the easy-rsa directory will be in the top level
directory
of the expanded source tree.
If you are using Windows, open up a Command Prompt
window and
cd to \Program Files\OpenVPN\easy-rsa. Run the following
batch file to copy configuration files into place (this will
overwrite any preexisting vars.bat and openssl.cnf files):
init-config
Now edit the vars file (called vars.bat
on Windows)
and set the KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, and KEY_EMAIL
parameters. Don't leave any of these parameters blank.
Next, initialize the PKI. On Linux/BSD/Unix:
. ./vars ./clean-all ./build-ca
On Windows:
vars clean-all build-ca
The final command (build-ca) will build the
certificate authority (CA)
certificate and key by invoking the interactive openssl command:
|