Create A VPN With The Raspberry Pi
Create A VPN With The Raspberry Pi
Create a
VPN with the
Raspberry Pi
Resources
A Raspberry Pi with all necessary
peripherals :
www.raspberrypi.org
52 www.linuxuser.co.uk
Advisor
Configure the Pi as a VPN server that you can access from anywhere
TUTORIal
01
02
03
04
05
06
cd /etc/network.d
nano bridge
Then fill in the bridge configuration to look
as follows and save the changes (swapping our
network values for your own):
INTERFACE=br0
CONNECTION=bridge
DESCRIPTION=VPN Bridge connection
BRIDGE_INTERFACES=eth0
IP=static
ADDR=192.168.1.215
NETMASK=24
GATEWAY=192.168.1.254
DNS=(192.168.1.254)
Once done, save the file using Ctrl+O followed
by Enter, then exit nano using Crl+X. Well add
the VPN adaptor to the bridge later on.
We now need to configure what profiles
netcfg should load by editing /etc/conf.d/netcfg
NETWORKS=(bridge)
Save the changes, exit nano and then run
the following commands to disable DHCP and
enable the Ethernet interface and the bridge
with a static IP permanently:
07
08
09
53 www.linuxuser.co.uk
Tutorial
cp -r /usr/share/openvpn/easy-rsa/ /etc/
openvpn
and then change to that directory.
Were going to be making a template to base
our certificates on. Edit the vars file with nano
and change the following lines at the bottom of
the file from something like:
export
export
export
export
export
export
export
export
export
KEY_COUNTRY=US
KEY_PROVINCE=CA
KEY_CITY=SanFrancisco
KEY_ORG=Fort-Funston
[email protected]
[email protected]
KEY_CN=changeme
KEY_NAME=changeme
KEY_OU=changeme
to
export
export
export
export
export
export
export
export
KEY_COUNTRY=UK
KEY_PROVINCE=
KEY_CITY=Ormskirk
KEY_ORG=Home
[email protected]
KEY_CN=liamvpn-ca
KEY_NAME=liamvpn-ca
KEY_OU=None
source ./vars
and then clean any previous configuration with:
./clean-all
10
./build-ca
Following that, we want to generate a server
certificate with:
./build-dh
./build-key liam-laptop
Simply do what you did during the buildkey-server script and then youll have all the
certificates you need.
11
;dev tap
dev tun
to:
dev tap0
;dev tun
because we are using a network tap adaptor
which allows us to bridge the networks, rather
than create a tunnel.
Replace the certificates here with the ones
you created:
ca ca.crt
cert server.crt
key server.key # This file should be
kept secret
dh dh1024.pem
12
INTERFACE=tap0
CONNECTION=tuntap
MODE=tap
USER=nobody
GROUP=nobody
We then need to add the tap0 interface to
our bridge, so edit /etc/network.d/bridge and
change the bridge interfaces line to look like:
BRIDGE_INTERFACES=eth0 tap0
Finally, change the networks line in /etc/
conf.d/netcfg to:
NETWORKS=(tap bridge)
Notice that the tap network needs to be
started first, so that it can be added to the
bridge successfully.
13
Enabling OpenVPN
14
ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/liamvpn.
crt
key /etc/openvpn/easy-rsa/keys/liamvpn.
key
dh /etc/openvpn/easy-rsa/keys/dh1024.pem
Comment out the line:
54 www.linuxuser.co.uk
;user nobody
;group nobody
Congure the Pi as a VPN server that you can access from anywhere
TUTORIAL
15
Configure No-IP
Run the command
noip2 -C -Y
to be taken through interactive conguration
of the No-IP client. We left the update interval
to the default 30 minutes, meaning the client
will check every 30 minutes for an IP address
change. Once done, start the daemon with:
/etc/rc.d/noip start
After a minute or two, your IP address will be
accessible via your No-IP hostname. However,
its likely that trying it from inside your house
will simply take you to your routers homepage.
16
17
18
19
20
Advanced settings
21
Route settings
22
cd /etc/openvpn
sudo mkdir keys
cd keys
sudo scp root@[Pis IP address]:/etc/
openvpn/easy-rsa/keys/ca.crt .
sudo scp root@[Pis IP address]:/etc/
openvpn/easy-rsa/keys/[client].crt .
sudo scp root@[Pis IP address]:/etc/
openvpn/easy-rsa/keys/[client].key .
sudo chmod +r *
55 www.linuxuser.co.uk