[HowTo] Install Configure OpenVPN On Ubuntu

“OpenVPN is a free and open source software application that implements virtual private network (VPN) solutions for creating secure point-to-point or site-to-site connections in routed or bridged configurations and remote access facilities. It uses SSL/TLS security for encryption and is capable of traversing network address translators (NATs) and firewalls. It was written by James Yonan and is published under the GNU General Public License (GPL).” (Cited from Linux Security).

So with OpenVPN you can create a secure private network using an internet connection. OpenVPN uses the OpenSSL library to provide encryption of both the data and control channels and transmitted data. OpenVPN works on multiple platforms. So once the server is set up and configured (I suggest using Linux), the client can connect from any platform (Windows, Mac OS, and Linux).

To install OpenVPN on Ubuntu:

sudo apt-get install openvpn libssl-dev openssl

OpenVPN Configuration:

1. Copy easy-rsa to the openvpn folder:

cd /etc/openvpn/
cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa/
chown -R $USER /etc/openvpn/easy-rsa/

2. Create the server certificates:

cd /etc/openvpn/easy-rsa/
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 dh1024.pem ta.key /etc/openvpn/

3. Create the client certificates:

cd /etc/openvpn/easy-rsa/
source vars
./pkitool hostname
cd ..

Change hostname to your client hostname.

4. Compress the client certificate:

tar czf keys.tgz ca.crt ta.key easy-rsa/keys/hostname.crt easy-rsa/keys/hostname.key

5. Download the keys.tgz and extract it under your OpenVPN client.

6. Configure /etc/openvpn/server.conf:

cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
gzip -d /etc/openvpn/server.conf.gz

Edit server.conf:

dev tun
server 10.10.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
push "route 10.10.0.0 255.255.255.0"
push "redirect-gateway"
comp-lzo
keepalive 10 60
ping-timer-rem
persist-tun
persist-key
user nobody
group nobody
daemon

7. Start the OpenVPN server:

echo 1 > /proc/sys/net/ipv4/ip_forward #enable ip forwarding
iptables -t nat -A POSTROUTING -s 10.10.0.0/24 -o venet0 -j MASQUERADE
iptables-save > /etc/iptables.conf
echo "#!/bin/sh" > /etc/network/if-up.d/iptables
echo "iptables-restore < /etc/iptables.conf" >> /etc/network/if-up.d/iptables
chmod +x /etc/network/if-up.d/iptables
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf

Then:

/etc/init.d/openvpn start

The OpenVPN server configuration is done. The next step is to configure the client. In this example I’m using Windows Vista with the OpenVPN client installed.

OpenVPN Client Configuration:

  1. Download the keys.tgz with an FTP client.
  2. Extract it in C:Program FilesOpenVPNconfig
  3. Run openvpn-gui, and press connect.
  4. You are connected to the OpenVPN, and you can share with the other client just like using a LAN network over the internet.

Even though there are many ways and configuration options to make your OpenVPN work as you need, this is just a basic example of what I did to create my own OpenVPN so I can test my programs. I hope this article is useful for you.

Thanks to: Configure OpenVPN Ubuntu vpsnoc.com