Connect your home and company networks with OpenVPN



OpenVPN is an opensource Virtual Private Networking (VPN) solution which can be downloaded freely on the Internet. It also included in almost every Linux distro to-date, so it can be easily installed using your distro’s favourite package manager tools. It uses the SSL/TLS VPN stacks, which makes it different from almost every other VPN solution (which are usually based on IPSec).

This guide will described how OpenVPN can be installed and configured on a Debian system, so that it can be used as a means to connect to your home and company networks.

The Server

First install the openvpn package:

# apt-get install openvpn

If apt-get suggests extra packages to install, just install them!

Two networks will be created:
* one to create a secure network for servers:
* one to create a secure network of client PC’s, Macbooks, Linux desktops, … :

Next, we will need an OpenVPN configuration file for the OpenVPN we’re about to create:

.oO( ieyasu | /etc/openvpn )Oo. cat server.conf 
port 1194
proto udp
dev tun0

mode server


#certificates and encryption
ca ca.crt
cert ieyasu.crt
key ieyasu.key
dh dh2048.pem
tls-auth ta.key 0
cipher AES-256-CBC


ifconfig-pool-persist ipp.txt
push "route"

# separate client configs
client-config-dir ccd

#log and security
user nobody
group nogroup
keepalive 5 30
status /var/log/openvpn-status.log
verb 3

We will also need some firewall rules allowing our OpenVPN traffic:

$IPTABLES -A INPUT   -i tun0 -s -d -j ACCEPT
$IPTABLES -A INPUT   -i tun0 -s  -d    -j ACCEPT
$IPTABLES -A INPUT   -i tun0 -s  -d  -j ACCEPT

$IPTABLES -A FORWARD -i tun0 -s  -d    -j ACCEPT
$IPTABLES -A FORWARD -i tun0 -s  -d  -j ACCEPT
$IPTABLES -A FORWARD -i tun0 -s -d -j ACCEPT

$IPTABLES -A INPUT -p udp --dport 1194 -j ACCEPT

Now we need to create a CCD file for each client. The CCD file contains the network settings for the connection OpenVPN clients.

.oO( ieyasu | ~ )Oo. cat /etc/openvpn/ccd/bear
.oO( ieyasu | ~ )Oo. cat /etc/openvpn/ccd/lion

The final thing to do for the OpenVPN server, is to create the x509 certificates.


# mkdir /etc/openvpn/easy-rsa/
# cp -R /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa/

This will copy the required tools for creating the certificates for both the server as the clients.

Next, specify your information in /etc/openvpn/easy-rsa/vars, only the bottom is of real importance:

vi /etc/openvpn/easy-rsa/vars
# These are the default values for fields
# which will be placed in the certificate.
# Don't leave any of these fields blank.
export KEY_CITY="As"
export KEY_EMAIL="info@moretrix.com"

Finally we will create the CA and the server certificate (we’re making a 2048 one!):

# cd /etc/openvpn/easy-rsa/
# chown -R root:admin .
# chmod g+w .
# source ./vars
# ./clean-all
# ./build-dh
# ./pkitool --initca
# ./pkitool --server server
# cd keys
# openvpn --genkey --secret ta.key
# cp server.crt server.key ca.crt dh2048.pem ta.key ../../

Finally we just need to start the OpenVPN service and the server is ready!

# /etc/init.d/openvpn restart

The Clients

Every client will need his own x509 certificate:

# cd /etc/openvpn/easy-rsa
# ./pkitool bear

bear is the name of the client host.

Now create a client configuration file, let’s call it bear.conf and we’ll save in it /tmp/client_config/:

dev tun
remote 1194
resolv-retry infinite
ca ca.crt
cert bear.crt
key bear.key
tls-auth ta.key 1
cipher AES-256-CBC
verb 3

Finally grab all the files the client will need

# cd /etc/openvpn/easy-rsa/keys/
# cp ca.crt ta.key bear.crt bear.key /tmp/client_config/
# cd /tmp/client_config/
# ls -ltr
total 24
-rw------- 1 root root  636 Jun 22 16:17 ta.key
-rw-r--r-- 1 root root 1537 Jun 22 16:17 ca.crt
-rw-r--r-- 1 root root 5053 Jun 22 16:17 bear.crt
-rw------- 1 root root 1704 Jun 22 16:17 bear.key
-rw-r--r-- 1 root root  185 Jun 22 16:17 bear.conf

If the client also uses the OpenVPN command line tools, just copy the above files to /etc/openvpn and restart the openvpn service.

root@bear:/etc/openvpn# ls -ltr
total 28
-rwxr-xr-x 1 root root 1357 2011-03-11 02:03 update-resolv-conf
-rw-r--r-- 1 root root  636 2011-06-20 22:40 ta.key
-rw-r--r-- 1 root root 1537 2011-06-20 22:40 ca.crt
-rw-r--r-- 1 root root 1704 2011-06-20 22:40 bear.key
-rw-r--r-- 1 root root 5053 2011-06-20 22:40 bear.crt
-rw-r--r-- 1 root root  185 2011-06-21 20:13 bear.conf
root@bear:/etc/openvpn# /etc/init.d/openvpn restart


* https://help.ubuntu.com/community/OpenVPN
* http://openvpn.net/index.php/open-source/documentation/howto.html
* http://openvpn.net/index.php/open-source/documentation/miscellaneous/76-ethernet-bridging.html

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Previous Post

Geotag your photos with Perl and GPX files

Next Post

Syslog event generator with Net::RawIP (perl)

Related Posts