Setting up a Raspberry Pi as a VPN router (Updated)

I’ve decided to update the VPN router on my home network using a Raspberry Pi 2, I’m quite impressed at how well it works. I was previously using a HomePlug AV adapter but found this to be a bit of a network bottleneck. So now my Raspberry Pi 2 is connected directly to my router using an ethernet cable.

Previously, I installed a DNS server (Unbound) as a caching recursive DNS server, this service resided on the same machine that I ran my VPN router on. Now however, after a bit of research I’ve decided to let my VPN’s DNS servers answer all the requests from my VPN connected devices.

I now run a separate DHCP/DNS server on my home network (DNSMasq) with a DNSCrypt wrapper that encrypts all the DNS requests that don’t go through my VPN Router.

Home VPN Setup

What you need

You will need some knowledge of networking and/or some IT knowledge.
A Raspberry Pi 2 or 3 running the current Raspian Jessie Lite – 2016-03-18.

Configure a static IP address

The new version of of the dhcpcd daemon included in the Jessie image doesn’t seem to read /etc/network/interfaces as it used to So if you configure a static IP in the usual way, you’ll end up with 2 IP addresses.

The workaround is to configure a static IP address as you would normally, then disable dhcpcd daemon. Then if you decide later to provision your Pi for something else, it’s easily reversible.

The above shows that the router’s IP address (Gateway) is, yours may be different, so remember to change it to suite your circumstances. You may well have to changing the network address if your network address differs from mine, which is

Setting up your VPN server

Next, you need to install openvpn on your raspberry pi and test it, I’ve provided an extensive list of VPN providers in the references section (right at the bottom) feel free to choose one after installing openvpn (make sure the VPN provider you choose, support openvpn).

First off, you need to install openvpn. You can do this by typing the following at the prompt.

After you’ve installed openvpn, you’ll need to choose a VPN provider. Ensure that the one you choose, supports Linux and Openvpn. If it’s a good provider, they will provide you with the option of downloading an OpenVPN configuration file, which should have the extension (.ovpn). After you’ve downloading the file to your Raspberry Pi, change the extension to a (.conf) extension and copy it to the “/etc/openvpn/” directory of your Raspberry Pi.

Test that the VPN actually works.

If it’s working as expected, then press ctrl-c to exit.

Enable VPN after reboot

You should get a message similar to this (see below), the “your_vpn_provider@” will of course be what you’ve called your file.

Fire-walling the interface and enabling forwarding

Below is the shell script that I wrote (with the help of online resources). What it does is firewall the tunnel interface and the internal eth0 interface. In the event of the openvpn daemon shutting down, or the connection to your VPN provider going down, all traffic stops being forwarded.

The only part that will need changed, is the “Home_Network” variable which is currently set to my home network ( and the VPN_DNS variable, which are the DNS servers supplied by your VPN provider. Download the script (or cut and paste) to your pi.

To change permission on the script (make it executable), type the following.

Run the script and apply the firewall.

I want to make the firewall rules persistent, so I’m going to install a package called iptables-persistent.

Make the rules apply at startup

If at any time you re-run the script after updating or changing it, then you will have to re-run the iptables-persistent program, to apply the updated rules after reboot. The command for that is.

Enable IPv4 forwarding

Edit the sysctl.conf file to enable IPv4 forwarding.

Uncomment the following.

Save the changes and run the following to make the change permanent.

You should get the following output.

Start VPN now

Testing your VPN Connection

IP Address:
Subnet :      
Default Gateway: (IP address of your now working Raspberry Pi VPN Router)
DNS Server :       (The IP address of your VPN provider’s DNS Servers)

Here’s a screenshot of my Windows 10 virtual machine with the static IP of the details above.

Windows 10 Network Settings

As you can see below, I’m currently in Canada (hurahh!), the DNS leak test shows one ip which is the same as my exit node IP.

VPN Connection

Here’s a good resource, with instructions on setting up a PC with a static IP address.


You can either install ntopng from the Raspberry Pi repository or you can install the new version, using the instructions provided on the ntopng website.

Installing ntopng (using the repository – Current Version 1.2.1 (r1.2.1)

Update repository

Upgrade software

Install ntopng from the repository

Installing ntopng from the ntopng website

Got to the ntop website and follow the instructions provided.

I got the following error message when I tried to run the program.

To fix this, I had to install a couple of libraries, instructions to fix the issue below.

Restart ntopng

Change the default ntopng login

Fire up your favorite browser and point it at the IP address of your new VPN router. For me that would be

Your may have used a different IP address, all you need to do is append the port number to the IP address.

After installing ntopng, I would suggest that you change the admin password after you login, the default login are as follows.

Default login – admin
Default password – admin

Screenshots of ntopng.

All hosts currently using my VPN router on my home network.

List of hosts using my VPN router.

Showing  one host on my network, and as you can see, you can look at the traffic type, ports, peers and protocols. It’s a great addition if you’re sharing your VPN with others in your family or friends. It allows you to see if someone is hogging your bandwidth or doing something a bit suspect.

It’s a really great program and if you find it useful then I would definitely buy a licence, because the paid version has a lot more functionality. If you want to see what the paid version looks like, restart your VPN router and connect to ntop, it runs the pro version for 10 minutes before defaulting to the community version.Host on ntopIf you like it they you can purchase a licence for the pro version from here. Alternatively, if you have a little cash you can also make a donation to the project.


Simple Stateful Firewall – ArchLinux
OpenVPN – Open Source – Website
How To Use Systemctl to Manage Systemd Services and Units – DigitalOcean
Wikipedia – Virtual Private Network
Networking – Pi as a VPN Router
15 best VPN Providers
Geospoofing with the Raspberry Pi
VPN Provider shuts down after Lavabit case undermines security
How do I know if my VPN provider is trustworthy? (Lifehacker)
How NSA Proof Are VPN Providers?
How (and why) to set up VPN today
Electronic Frontier Foundation
VPN Creative – What is my IP address
DNS Leak Test
IP and DNS Detect
Selective VPN routing : [Solution – DSVR]
iptables ipv4 firewall – Debian Firewall Wiki

Draft investigatory Powers Bill

GCHQ Mass Surveillance
Theresa May unveils UK surveillance measures in wake of Snowden claims
UK cyber-spy law takes Snowden’s revelations of mass surveillance and sets them in stone
UN privacy head slams ‘worse than scary’ UK surveillance bill
Investigatory Powers Bill: what’s in it, and what does it mean?
Don’t spy on us

Setting up a Raspberry Pi as an IPv6 gateway using Hurricane Electric.

First thing you’ll need to do is register at the Hurricane Electric Website and create your own tunnel. I’m not going to go over that since there’s a lot of help on the Hurricane Electric Website about it. These instructions only apply to you, after you’ve registered as a user, and set up your tunnel on their website.

Take a note of your Tunnel details from the Hurricane Electric website, you’ll need them to set up your Linux IPv6 Gateway. The IPv6 addresses are used for documentation purposes only, see RFC 3849 (no point showing everyone on the Internet my home IPv6 address range).

HE Server IPv4 Endpoint
Static IPv6 assignment from my routable range 2001:DB8:8:7aa::1
Client IPv6 Endpoint 2001:DB8:7:7aa::2

Ok first thing to do is enable IPv6 support on your raspberry pi, at the prompt type.

To make the change permanent, you will have to edit the modules file and have your pi load it at start-up (reboot). To do this edit the modules file, type the following.

Your modules file should look similar to this after to append the “ipv6” line at the end.

You need to edit /etc/network/interfaces and add your own data to the bottom of the file. Two bits of data, the first bit goes after your own network adaptor (usually eth0). and the second part after that.

  • Adding static IPv6 address from my routable range.
  • Adding the Hurricane Electric Tunnel interface (called he-ipv6)
  • Please note that the IP’s are on different networks.

The IPv6 and IPv4 setting below will of course be yours and not the ones I’ve made up for the purpose of showing how it’s done 🙂

Now we’ll deal with DNS, you have two options, you can either use your ISP’s DNS server and hope that it’s set up to deal with IPv6 resolution, or you can use free public recursive DNS servers. I’m going to use Google’s public recursive DNS servers which I know work.

To set this up, you’ll need to edit the /etc/resolv.conf file and add the DNS servers in. Type the following at the prompt.

Add the following and save.

Testing the Tunnel

Before we go any further, were going to bring the tunnel up and test it.

At the prompt, type the following.

To test, type the following.

You should get similar results to me.

If your results are similar to above then your raspberrypi is connected to the IPv6 Internet (Hurrah!) :-). If not then check your IPv6 settings and ask for help on the HE forum here.

Now we need to bring the interface down, we’ll bring it back up again after we’ve firewalled it.


Continue reading

Setting up your Raspberry Pi (headless)

Raspberry Pi Hardware List

Continue reading

Billion 7800N SNMP OID’s

I’ve decided to graph my small home network, so I thought I would see if I could find the OID’s for my Billion 7800n Router, first I tried the Billion website, I was surprised not to find them there. I managed to find some information on other websites (not a huge lot), but it seems that Billion have changed the format of the information between firmware revision.

Billion 7800n SNMP Page

Billion 7800n SNMP Page

Assuming you’ve set up your router and installed snmp tools on your Linux workstation, this command will give you a list of all the OID’s.

If you can’t be bothered to install SNMP tools then feel free to grab the zip file of the results from the following Software Version 1.06e

[code lang=”bash”]snmpwalk -v1 -c public[/code]

As it happens, I’ll only be graphing a few of the salient attributes of the router, using either Cacti or Nagios in a home environment.

ADSL Status.

Upstream Speed (Gauge32): .
Downstream Seed (Gauge32): .

Upstream SNR (Integer): .
Downstream SNR (Integer): .

Upstream Line Attenuation (Gauge32): .
Downstream Line Attenuation (Gauge32): .

System Uptime (Timeticks): .

Interface Statistics.

Ethernet interface eth0
String: “eth0” .
RX bytes (String): .
TX bytes (String): .

Ethernet interface eth1
String: “eth1” .
RX bytes (String): .
TX bytes (String): .

Ethernet interface eth2
String: “eth2” .
RX bytes (String): .
TX bytes (String): .

Ethernet interface eth3
String: “eth3” .
RX bytes (String): .
TX bytes (String): .

Wireless interface ra0
String: “ra0” .
RX bytes (String): .
TX bytes (String): .

Bridge interface br0
String: “br0” .
RX bytes (String): .
TX bytes (String): .

Backing up your wordpress mysql file and encrypting it for offsite storage.

This is reminder to myself (but if it’s usefull, then feel free).

Forgot the name of the database (Duh!) 😀

Backup wordpress MySQL database

Encrypt using gpg for offsite storage, remember your not using your (or someone’s) public key to encrypt the file, your using a specific password so…

Hint: Keep a note of the password. 😀

The encryted file will have a gpg extension, so in my case it’s called “wordpress.sql.gpg”.

How to Decrypt the file

Will give you 2 files, the original encrypted wordpress.sql.gpg file, and the unencryped wordpress.sql file.

Encrypting and decrypting documents
Backup and Restore MySQL Databases

Installing Wireshark on Ubuntu 12.04 LTS

Installing wireshark on Ubuntu 12.04 LTD and limiting packet capture to one group, in this case the group wireshark. I’m sure you can use these instructions for other debian based distributions.

Although you’ll have to take it as read that I’ve only tested it on Ubuntu, feel free to let me know if it doesn’t and I’ll amend the instructions to suit.

First, we install Wireshark from the terminal.
Continue reading