Skip to content
Johnny Morano's Tech Articles

Johnny Morano's Tech Articles

Ramblings of an old-fashioned space cowboy

Menu
  • About
  • Privacy Policy
Menu

Connect your home and company networks with OpenVPN

Posted on June 22, 2011September 4, 2012 by insaniac

Introduction

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: 192.168.1.0/24
* one to create a secure network of client PC’s, Macbooks, Linux desktops, … : 10.66.99.0/24

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

.oO( ieyasu | /etc/openvpn )Oo. cat server.conf 
# LIKE A BOSS
local 176.9.64.17
port 1194
proto udp
dev tun0

mode server
tls-server

persist-key
persist-tun

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

server 192.168.1.0 255.255.255.0
route  10.66.99.0 255.255.255.0

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

# 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 192.168.1.0/24 -d 192.168.1.0/24 -j ACCEPT
$IPTABLES -A INPUT   -i tun0 -s 10.66.99.0/24  -d 192.168.1.1    -j ACCEPT
$IPTABLES -A INPUT   -i tun0 -s 10.66.99.0/24  -d 10.66.99.0/24  -j ACCEPT

$IPTABLES -P FORWARD DROP
$IPTABLES -A FORWARD -i tun0 -s 10.66.99.0/24  -d 192.168.1.1    -j ACCEPT
$IPTABLES -A FORWARD -i tun0 -s 10.66.99.0/24  -d 10.66.99.0/24  -j ACCEPT
$IPTABLES -A FORWARD -i tun0 -s 192.168.1.0/24 -d 192.168.1.0/24 -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.
Example:

.oO( ieyasu | ~ )Oo. cat /etc/openvpn/ccd/bear
ifconfig-push 192.168.1.11 192.168.1.12
.oO( ieyasu | ~ )Oo. cat /etc/openvpn/ccd/lion
ifconfig-push 10.66.99.3 10.66.99.4

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

First:

# 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
*snip*
# These are the default values for fields
# which will be placed in the certificate.
# Don't leave any of these fields blank.
export KEY_COUNTRY="BE"
export KEY_PROVINCE="LIM"
export KEY_CITY="As"
export KEY_ORG="MORETRIX"
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/:

client
dev tun
remote 176.9.64.17 1194
nobind
resolv-retry infinite
persist-key
persist-tun
ca ca.crt
cert bear.crt
key bear.key
tls-auth ta.key 1
cipher AES-256-CBC
comp-lzo
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

Resources

* 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 Cancel reply

Your email address will not be published. Required fields are marked *

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

Recent Posts

  • Use multiple Azure subscriptions in Terraform modules
  • Read the HAProxy UNIX socket file using Perl
  • A Prometheus Exporter framework written in Perl
  • Managing LDAP passwords with Perl
  • Libvirt guest startup issue with AppArmor
  • Deploy a PostgreSQL database with an initial schema using Ansible
  • Using Ansible to finalize Hashicorp Packer images

Categories

  • Automation (8)
  • Blog (60)
  • Database (4)
  • Development (37)
  • Linux (26)
  • Mac OS X (5)
  • Media (2)
  • OpenBSD (3)
  • Perl (34)
  • Photo (2)
  • PostgreSQL (4)
  • Terraform (5)
  • Web (11)

Tags

Ajax (3) Android (1) Ansible (2) API (5) AppArmor (1) Automation (5) Azure (3) azurerm (2) Bash (4) Cloud (2) CPAN (4) CSS (1) Debian (4) Dev (35) DevOps (11) EXIF (1) Facebook (1) Geotag (1) GMail (1) Google (3) Hack (2) Hashicorp (4) Hetzner (2) HTML (4) IMAP (2) IPTables (6) JavaScript (4) Libvirt (2) Linux (25) Logging (2) MacOSX (5) Media (2) Monitoring (6) MySQL (3) OpenBSD (4) Packer (1) Perl (35) PF (2) Postgresql (6) Security (7) SysAdmin (24) Terraform (4) Ubuntu (2) UNIX (9) Web 2.0 (3)

Archive

  • April 2022 (10)
  • March 2022 (6)
  • December 2016 (1)
  • March 2016 (1)
  • November 2015 (1)
  • November 2014 (1)
  • August 2014 (1)
  • May 2014 (1)
  • February 2014 (2)
  • December 2013 (1)
  • October 2013 (2)
  • September 2013 (2)
  • August 2013 (2)
  • October 2012 (1)
  • August 2012 (4)
  • March 2012 (3)
  • July 2011 (1)
  • June 2011 (2)
  • April 2011 (3)
  • March 2011 (4)
  • February 2011 (2)
  • December 2010 (2)
  • October 2010 (4)
  • September 2010 (1)
  • August 2010 (5)

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Footer

  • Shihai Corp
  • My Photo website
© 2022 Johnny Morano's Tech Articles | Powered by Superbs Personal Blog theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT