<h2>Personal OpenVPN</h2>
<p>
This guide will walk you through setting up an OpenVPN server as well as a client.
</p>
<h2>OpenVPN Server Setup</h2>
<p>
Here is how to install OpenVPN on Centos6. Other RedHat derivatives should be similar.
</p>
<p>
<pre>
    wget https://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
    rpm -Uvh epel-release-6-8.noarch.rpm
    yum install openvpn -y
</pre>
</p>
<p>
Here is how to install OpenVPN on a Debian server. Other Debian derivatives should be similar.
</p>
<p>
<pre>
    apt-get install openvpn
</pre>
</p>
<p>
After the server is installed, the server certificate authority and keys must be generated.
This will be followed by the client keys, and then the server configuration file.
</p>
<p>
Copy the easy-rsa scripts into /etc/openvpn
</p>
<p>
<pre>
    cp -rf /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa  # on Debian
</pre>
<pre>
    cp -rf /usr/share/openvpn/easy-rsa/2.0/* /etc/openvpn/easy-rsa  # on Centos6
</pre>
</p>
<p>
Set Environmental variables
</p>
<p>
<pre>
    cd /etc/openvpn/easy-rsa
    vim vars
</pre>
</p>
<p>
Change the following variables to meet your needs. These are used for your
convenience. They will be used as the defaults during the interactive key
generation session to set the keys attributes.
</p>
<p>
<pre>
    export KEY_COUNTRY="US"
    export KEY_PROVINCE="CA"
    export KEY_CITY="SanFrancisco"
    export KEY_ORG="Fort-Funston"
    export KEY_EMAIL="me@myhost.mydomain"
</pre>
</p>
<p>
Source the variables to the current shell
</p>
<p>
    . ./vars
</p>
<p>
Create certificate authority
</p>
<p>
<pre>
    ./clean-all
    ./build-ca
    ./build-dh
</pre>
</p>
<p>
Create keys for the server and clients
</p>
<p>
<pre>
    ./build-key-server server
    ./build-key client1
    ./build-key client2
</pre>
</p>
<p>
Setup the server configuration file
</p>
<p>
<pre>
  cd /etc/openvpn
  gunzip /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz  # on Debian
  vim /etc/openvpn/server.conf
</pre>
</p>
<p>
Server settings
</p>
<p>
<pre>
    port 1194
    proto udp
    dev tun
    ca     /etc/openvpn/easy-rsa/keys/ca.crt
    cert   /etc/openvpn/easy-rsa/keys/server.crt
    key    /etc/openvpn/easy-rsa/keys/server.key
    dh     /etc/openvpn/easy-rsa/keys/dh2048.pem
    server 10.10.42.0 255.255.255.0
    ifconfig-pool-persist ipp.txt
    client-config-dir ccd
    route 10.10.42.0 255.255.255.0
    client-to-client
    keepalive 10 120
    cipher AES-256-CBC   # AES
    comp-lzo
    user nobody
    group nogroup
    persist-key
    persist-tun
    status openvpn-status.log
    verb 3
</pre>
</p>
<p>
Restart VPN Service
</p>
<p>
<pre>
    service openvpn restart
</pre>
</p>
<p>
If the service fails to start, try starting openVPN manually.
The resulting errors will allow you to see what item in the
configuration file is incorrect.
</p>
<p>
<pre>
    openvpen server.conf
</pre>
</p>
<p>
Once you are able to get openVPN to start without error,
kill it and restart it using the service command above.
You can verify that the vpn is successfully running by
looking at the configured interfaces using the following
command.
</p>
<p>
<pre>
    ifconfig
</pre>
</p>
<p>
You should now see an entry like the following:
</p>
<p>
<pre>
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:10.10.42.1  P-t-P:10.10.42.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:622255 errors:0 dropped:0 overruns:0 frame:0
          TX packets:986993 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:40649523 (38.7 MiB)  TX bytes:1344026670 (1.2 GiB)
</pre>
</p>
<h2>OpenVPN Client Setup</h2>
<p>
The installation of OpenVPN for linux is the same as described above for
the server. For Windows, Download and run the OpenVPN installer from the
OpenVPN Community Downloads.
</p>
<p>
<i>NOTE:</i> On Windows, <i>User Account Control (UAC)</i> must be turned
off in order to allow OpenVPN to execute the necessary network
commands to bring up the VPN. Open <i>Start > Control Panel >
User Accounts and Family Safety > User Accounts > Change User
Account Control Settings</i>. Set to <i>Never Notify</i>, click <i>OK</i>,
and reboot the machine.
</p>
<p>
Client Configuration file
</p>
<p>
For linux, the client config file would go in `/etc/openvpn` just like
the server config. We will name it `client.conf` to clarify that the
device is being configured as an OpenVPN client.
On Windows, the keys and client config files go in the
`C:\Program Files (x86)\OpenVPN\config`. The config file has
to have an `.ovpn` suffix.
</p>
<p>
<pre>
    client
    dev tun
    proto udp
    remote myvpn.example.org 1194
    resolv-retry infinite
    nobind
    user nobody
    group nogroup
    persist-key
    persist-tun
    ca     /etc/openvpn/keys/ca.crt
    # on Windows, the format is:
    # ca "C:\\Program Files (x86)\\OpenVPN\\config\\ca.crt"
    # Windows may also change the file suffix on the crt files to cer.
    # So, If Windows complains that it cannot find the file,
    # examine its properties to verify the suffix.
    # The logs are stored at C:\\Program Files (x86)\\OpenVPN\\log
    cert   /etc/openvpn/keys/client1.crt
    key    /etc/openvpn/keys/client1.key
    ns-cert-type server
    cipher AES-256-CBC
    comp-lzo
    verb 3
</pre>
</p>
<p>
Copy client key and server ca files onto client
</p>
<p>
<pre>
    scp  ca.crt  user@client1:.openvpn/
    scp  client1.crt  user@client1:.openvpn/
    scp  client1.key  user@client1:.openvpn/
</pre>
</p>
<p>
On the server create the ccd directory to assign static addresses to clients.
</p>
<p>
<pre>
    mkdir /etc/openvpn/ccd
</pre>
</p>
<p>
For each device, add a file with the CN name of the key.
In that file, you will indicate the static address to be used and the server IP
For linux, the server IP will be the VPN address of your VPN server. On Windows, the VPN client
will set up a local TAP interface that must be used as the server IP. See the OpenVPN docs for available
client and TAP server IP pairs.
</p>
<p>
Examples:
</p>
<p>
<pre>
    cat /etc/openvpn/ccd/linux-client
    ifconfig-push 10.10.42.10 10.10.42.1
    cat /etc/openvpn/ccd/windows-client
    ifconfig-push 10.10.42.13 10.10.42.14
</pre>
</p>

<h2>References:</h2>

<ul>
<li><a href="https://www.hackerpublicradio.org/eps.php?id=297">Hacker Public Radio episode 0297</A></li>
<li><a href="https://wiki.debian.org/OpenVPN">Debian OpenVPN Docs</A></li>
<li><a href="https://openvpn.net/index.php/open-source/documentation/howto.html">OpenVPN HowTo</A></li>
<li><a href="https://openvpn.net/index.php/download/community-downloads.html">OpenVPN Windows Downloads</A></li>
<li><a href="https://community.openvpn.net/openvpn/wiki/Easy_Windows_Guide">OpenVPN Windows Guide</A></li>
</ul>
