Securely connect to your home

Nowadays we all have many connected devices at home for a plethora of reasons: SmartHome, AdBlocker, DNS, Storage. Furthermore we maybe want to connect to our home environment on the road to use home backup or geo-blocked services.
And maybe we also have systems somewhere else, where we want to connect securely. Like the cloud…

What is a virtual private network(VPN)

A virtual private network let’s you access remote resources, as if you would be connected to the same network. Hence the name virtual private network (VPN)

There are many protocols and provider out there. Some of the more noteworthy:

Connecting to a VPN is mainly used to connect to private networks of your own, so you don’t have to directly connect to the services over the internet directly.
Another main use case is to reach the internet in a privacy minded fashion. If you connect to a VPN and then open a website, the Website will only see the IP of the VPN provider and your ISP will only see the connection to the VPN provider.

Why Wireguard

I won’t cover here in detail the concepts and inner workings of wireguard. The author himself explains it on his own homepage really well:

Some of the noteworthy advantages:

  • Direct kernel integration (from 5.6 onward)
  • Modern cryptography
  • Easy to use
  • Available for Windows, macOS, BSD, iOS and Android

It’s important to note, that Wireguard is mainly a VPN protocol, and not a full blown VPN service. Just as OpenVPN is a protocol and the OpenVPN Access Server is a service. However, you can use the base functionality of Wireguard quite easy. But that only applies to the server, there are already nice clients available for all platforms for a ease of use. You’ll see that in the configuration section later.

However enterprise integrations are not yet created. For instance, you can’t properly manage users, network access control, public keys etc for a Wireguard server instance. But those will probably come pretty soon. Would be nice to see Wireguard in Windows integrated as well…

Is Wireguard secure

Wireguard is now considered pretty secure, although it just recently reached version 1.0 and completed an independent penetration test:

However, if you use Wireguard as a service from a provider, keep in mind, that your ip in the VPN is locked to your public key and your latest connected public IP is also stored in the log.

These aspects are not very relevant in your own small private environment, but they would matter greatly when you use Wireguard as an interface to a VPN service provider.

Wireguard Installation

Installation is pretty straightforward. Either you have already a kernel 5.6, then you basically don’t need to do anything.
If you have a more or less modern environment, it might very well be, that wireguard is in the backports section of the distribution (like Debian and thus Raspbian).
There is a nice installation guide for Debian/Raspbian:

  1. The current Debian Buster 10 does not have the wireguard packages yet, but the package is already included in the backports repository:
echo "deb buster-backports main" | sudo tee --append /etc/apt/sources.list
  1. Next, install the Debian distro keys:
sudo apt-key adv --keyserver --recv-keys 04EE7237B7D453EC
sudo apt-key adv --keyserver --recv-keys 648ACFD622F3D138
  1. Update your package list:
sudo apt update
  1. Install WireGuard:
sudo apt -t buster-backports install wireguard

Configuration Client

In our example we install the mobile app. Just go to the app store of your choice and install the app. Find the direct links also on the wireguard homepage:

When you start the app, just create a new manual config:

  • Name -> Your Client Name
  • Private Key -> Press the reload button on the right
  • Public Key -> copy the public key, after you have created the private one
  • Address -> Choose an address in the same block as your server. In our example:
  • DNS -> Your DNS server in your local net, or a good one in the internet: or
  • Press the save icon on the top right

Now you can transport the client key to the server.

Configuration Server

First we need to create our public/private pairs for our server. You should create the client key pair on the client. Most apps actually do support that and you can write down the public key actually anywhere.

sudo su
cd /etc/wireguard
umask 077
wg genkey | tee server_private_key | wg pubkey > server_public_key

You can see the generated keys with:

cat server_private_key
cat server_public_key

Next we create the WireGuard Server configuration with:

nano wg0.conf

And add the following:
(change the server private and client public keys, and adapt the network and port if you want)

Address =
SaveConfig = true
PrivateKey = <insert server_private_key>
ListenPort = 51900

PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

PublicKey = <insert client_public_key>
AllowedIPs =

Edit sysctl.conf on the Raspberry Pi and uncomment the line with “net.ipv4.ip_forward=1” and save.

nano /etc/sysctl.conf

Reboot your RPi for all of your changes to take effect.


Set up WireGuard to start automatically on reboot:

systemctl enable wg-quick@wg0
chown -R root:root /etc/wireguard/
chmod -R og-rwx /etc/wireguard/*

You can check the status via:

sudo wg show

NextDNS Storage Location

Thanks for reading and feedback is welcome!

Tags: ,