Running OpenVPN on Ubuntu 8.10 Server   June 19th, 2009

Running OpenVPN on Ubuntu 8.10 Server

By niels | Published: February 13, 2009

When I’m attending classes i can access the internet using the wireless network at my school. Unfortunately you can only do generic tasks like browsing the web, receiving and sending e-mail and MSN chat, everything else is blocked: no RDP, VNC, secure SMTP (port 587), games or anything that uses custom ports/protocols.

I can’t get to my servers unless i run SSH on allowed ports like 25, 80, 443, etc. To get around this I’ve been looking into running my own OpenVPN server on an allowed port so i can get unrestricted access to the internet using my server as a gateway. I’ll be connecting to the OpenVPN server using Viscosity.

OpenVPN

Get the OpenVPN binaries using the apt-get command:

1.$ apt-get install openvpn openssl

You’ll find everything you need in/usr/share/doc/openvpn/examples/

1.$ cd /usr/share/doc/openvpn/examples

Copy ./sample-config-files/server.conf.gz and ./easy-rsa/2.0/ to /etc/openvpn

1.$ cp ./sample-config-files/server.conf.gz /etc/openvpn
2.$ cp -r ./easy-rsa/2.0 /etc/openvpn

Go to /etc/openvpn

1.$ cd /etc/openvpn

Rename the 2.0 folder into easy-rsa and unpack the config file:

1.$ mv 2.0 easy-rsa
2.$ gzip -d server.conf.gz

Certificates

OpenVPN needs a number of certificates, you can create them using the easy-rsa tools.

1.$ cd /etc/openvpn/easy-rsa

Optional: Edit the vars file so it contains the correct default fields, this will save some time later.

1.$ vim ./vars

Edit the values at the bottom of the file to whatever you want.

1.# These are the default values for fields
2.# which will be placed in the certificate.
3.# Don’t leave any of these fields blank.
4.export KEY_COUNTRY=”US”
5.export KEY_PROVINCE=”CA”
6.export KEY_CITY=”SanFrancisco”
7.export KEY_ORG=”Fort-Funston”
8.export KEY_EMAIL=” me@myhost.mydomainThis e-mail address is being protected from spam bots, you need JavaScript enabled to view it

Save the vars file.

Generate the master Certificate Authority (CA) certificate and keys

1.$ . ./vars
2.$ ./clean-all
3.$ ./build-ca

Generate the certificate and key for the server

1.$ ./build-key-server server

Leave the common name set to its default value (server)

Generate the certificates and keys for clients

1.$ ./build-key client1
2.$ ./build-key client2

Leave the common name set to its default value.

Generate Diffie Hellman parameters

1.$ ./build-dh

Creating the server configuration file

Edit /etc/openvpn/server.conf

1.$ vim /etc/openvpn/server.conf

This is what i use (# = comment):

01.port 1194 # change this to whatever you need it to be
02.proto udp # tcp or udp, never use both in the same config
03.dev tun #routed VPN
04.# Certificates
05.ca ca.crt
06.cert server.crt
07.key server.key # This file should be kept secret
08.dh dh1024.pem
09.# Server settings
10.server 10.8.0.0 255.255.255.0 # Default VPN ip range.
11.push “redirect-gateway”
12.# OpenDNS settings
13.push “dhcp-option DNS 208.67.222.222″
14.push “dhcp-option DNS 208.67.220.220″
15.# Allow clients to see eachother
16.client-to-client
17.# Reduce the OpenVPN daemon’s privileges
18.user nobody
19.group nogroup

Copy the server certificates and keys to /etc/openvpn

1.$ cd /etc/openvpn/easy-rsa/keys
2.$ cp ca.crt server.crt server.key dh1024.pem /etc/openvpn

Copy the client certificates and keys to wherever you want (you need them on your clients)

1.$ cp client1.crt client1.key ca.crt /home/client1 # Change the target folder to whatever you need it to be

Restart the OpenVPN service

1.$ /etc/init.d/openvpn restart

Any .conf file in /etc/openvpn will be automatically loaded.

Making routes work

Before you can actually access the internet over your VPN you need to enable IPv4 forwarding and add some iptables rules.

Edit /etc/sysctl.conf

1.$ vim /etc/sysctl.conf

Uncomment net.ipv4.ip_forward=1 and save your changes.
At this point you can either reboot or run the following command.

1.$ sysctl -w net.ipv4.ip_forward=1

Confirm that ip_forward is actually enabled.

1.$ sysctl net.ipv4.ip_forward

Add the following rules to /etc/rc.local before the exit 0 statement

1.iptables -P FORWARD ACCEPT
2.iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

The address (10.8.0.0/24) is the default network used by the OpenVPN sample config, eth0 is the interface connected to the internet (change this if needed).
Run the rules manually, restart or /etc/init.d/rc.local start.

You’re done configuring the OpenVPN server. Make sure its running:

1.$ ps ax | grep openvpn
2.14454 ?        Ss     0:00 /usr/sbin/openvpn –writepid /var/run/openvpn.server.pid –daemon ovpn-server –cd /etc/openvpn –config /etc/openvpn/server.conf –script-security 2

Thanks to Author, source http://nielsvz.com/2009/02/running-openvpn-on-ubuntu-810-server/

This entry was posted on Friday, June 19th, 2009 at 9:41 pm and is filed under debian, linux, Networking, ubuntu. You can follow any responses to this entry through the RSS 2.0 feed.You can leave a response, or trackback from your own site.

No Responses

Leave a Reply

*


http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_bye.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_good.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_negative.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_scratch.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_wacko.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_yahoo.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_cool.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_heart.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_rose.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_smile.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_whistle3.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_yes.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_cry.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_mail.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_sad.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_unsure.gif 
http://blog.csatpk.com/wp-content/plugins/wp-monalisa/icons/wpml_wink.gif