This post should be a small tutorial on how to install and configure a small VPN scenario with the RaspberryPi working as the VPN server within your local network.
Imagine a setup like shown below, where you want to connect to your RasPi (or any other host within your local network) from your notebook or mobile phone via an Open WiFi Access Point.
Since your ISP probably won't grant you a static IP address you first need to sign up to a dynamic DNS service provider and configure your router appropriately. Check the previous post on how to do so for the FritzBox 7240.
In my setup "Raspbian Wheezy" is installed as operating system on the Pi so it is easy to get the software packages needed for the OpenVPN server
In my setup "Raspbian Wheezy" is installed as operating system on the Pi so it is easy to get the software packages needed for the OpenVPN server
sudo apt-get install openvpnThis package needs to be installed on both, server and client system.
Server configuration
First of all we need to generate all the keys and certificates on the server. To do so, it is comfortable to use the easy-rsa key-management package based on openssl wich is already part of the OpenVPN installation.
So locate your easy-rsa folder an copy it to your openvpn location:
(For this and most of the following steps you root access)
cp -R /usr/share/doc/openvpn/examples/easy-rsa /etc/openvpn
export KEY_COUNTRY="US"
export KEY_PROVINCE="CA"
export KEY_CITY="SanDiego"
export KEY_ORG="OpenVPN"
export KEY_EMAIL="myemail@mydomain.com"
source /etc/openvpn/easy-rsa/vars
./clean-all
./build-ca
./build-key-server server
./build-key client1
./build-dh
Now it's time for the server configuration file. In /etc/openvpn a basic config file named server.conf should already exist. If not, you can extract it from /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz. Most of the basic settings are already fine, but it's crucial that you set the path for the keys and certificates:
ca ./easy-rsa/keys/ca.crt
cert ./easy-rsa/keys/server.crt
key ./easy-rsa/keys/server.key
dh ./easy-rsa/keys/dh1024.pem
In order to access the full local network (not only the hosts connected to the vpn) you have to insert the following line into the appropriate section in the same file:
push "route 192.168.178.0 255.255.255.0"
Furthermore you have to activate IP forwarding by inserting the following line into /etc/sysctl.conf
net.ipv4.ip_forward=1
This is all for the server side. To start the OpenVPN server daemon just run the initialization script:
/etc/init.d/openvpn start   # or 'restart' when it was already running
Router configuration (FritzBox)
Since the RasberryPi is probably not the default gateway of your local network you have to create a static route. To do so, open the FritzBox configuration pages in your browser and navigate to the local network section. Create a static route with the informations given below:
IP-Address 10.8.0.0
Subnetzmaske 255.255.255.0
Gateway 192.168.178.2
Make also sure that the FritzBox assigns always the same IP address to your RaspberryPi. Last thing you have to do, is to open port 1149 and forward it to 192.168.178.2 (the ip address of the Pi).
Client configuration
Because there are several clients and operating systems out, I will not go into detail here. Basically every client needs the key and certificate files created before:
client1.crt
client1.key
ca.crt
If Ubuntu is your operating system, you can use the OpenVPN plugin for NetworkManager available in the repositories. Have a look at http://wiki.ubuntuusers.de/OpenVPN for further instructions.
Have fun connecting to your home network in a secure manner!

 
Can I use this with other router instead of FritzBox? Another Question the Raspberry Pi is the Default Gateway instead the Router?
AntwortenLöschenCan I use this with other router instead of FritzBox? Another Question the Raspberry Pi is the Default Gateway instead the Router?
AntwortenLöschen