Install WireGuard on Raspberry Pi Zero W

Raspberry Pi Logo

Installing WireGuard on a Raspberry Pi Zero is slightly different to the normal Install WireGuard on Raspberry Pi Raspbian method.

Update System

sudo apt update && sudo apt upgrade -y

Hit:1 http://archive.raspberrypi.org/debian buster InRelease
Get:2 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]
Fetched 15.0 kB in 3s (4,911 B/s)
Reading package lists… Done
Building dependency tree
Reading state information… Done
All packages are up to date.
Reading package lists… Done
Building dependency tree
Reading state information… Done
Calculating upgrade… Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

On these RPi’s you need to compile manually. Why? The Raspberry Pi’s CPU doesn’t have some of the features of the armhf arch in Debian, if you download and install the armhf package, it will crash (Segmentation fault).

Install Prerequisites

sudo apt install raspberrypi-kernel-headers libmnl-dev libelf-dev build-essential git -y

Reading package lists… Done
Building dependency tree
Reading state information… Done
build-essential is already the newest version (12.6).
libmnl-dev is already the newest version (1.0.4-2).
The following additional packages will be installed:
git-man libcurl3-gnutls liberror-perl
Suggested packages:
git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs
git-mediawiki git-svn
The following NEW packages will be installed:
git git-man libcurl3-gnutls libelf-dev liberror-perl raspberrypi-kernel-headers
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 31.1 MB of archives.
After this operation, 196 MB of additional disk space will be used.
Preparing to unpack …/0-libcurl3-gnutls_7.64.0-4+deb10u1_armhf.deb …
Unpacking libcurl3-gnutls:armhf (7.64.0-4+deb10u1) …
Selecting previously unselected package liberror-perl.
Preparing to unpack …/1-liberror-perl_0.17027-2_all.deb …
Unpacking liberror-perl (0.17027-2) …
Selecting previously unselected package git-man.
Preparing to unpack …/2-git-man_1%3a2.20.1-2+deb10u1_all.deb …
Unpacking git-man (1:2.20.1-2+deb10u1) …
Selecting previously unselected package git.
Preparing to unpack …/3-git_1%3a2.20.1-2+deb10u1_armhf.deb …
Unpacking git (1:2.20.1-2+deb10u1) …
Selecting previously unselected package libelf-dev:armhf.
Preparing to unpack …/4-libelf-dev_0.176-1.1_armhf.deb …
Unpacking libelf-dev:armhf (0.176-1.1) …
Selecting previously unselected package raspberrypi-kernel-headers.
Preparing to unpack …/5-raspberrypi-kernel-headers_1.20200212-1_armhf.deb …
Unpacking raspberrypi-kernel-headers (1.20200212-1) …
Setting up libcurl3-gnutls:armhf (7.64.0-4+deb10u1) …
Setting up liberror-perl (0.17027-2) …
Setting up raspberrypi-kernel-headers (1.20200212-1) …
Setting up libelf-dev:armhf (0.176-1.1) …
Setting up git-man (1:2.20.1-2+deb10u1) …
Setting up git (1:2.20.1-2+deb10u1) …
Processing triggers for man-db (2.8.5-2) …
Processing triggers for libc-bin (2.28-10+rpi1) …

Clone WireGuard Repository

git clone https://git.zx2c4.com/WireGuard

Cloning into ‘WireGuard’…
warning: redirecting to https://git.zx2c4.com/wireguard-monolithic-historical/
remote: Enumerating objects: 11550, done.
remote: Counting objects: 100% (11550/11550), done.
remote: Compressing objects: 100% (2662/2662), done.
remote: Total 11550 (delta 8638), reused 11533 (delta 8638)
Receiving objects: 100% (11550/11550), 2.39 MiB | 406.00 KiB/s, done.
Resolving deltas: 100% (8638/8638), done.

Compile WireGuard

cd WireGuard/src
sudo make

CC [M] /home/pi/WireGuard/src/main.o
CC [M] /home/pi/WireGuard/src/noise.o
CC [M] /home/pi/WireGuard/src/device.o
CC [M] /home/pi/WireGuard/src/peer.o
CC [M] /home/pi/WireGuard/src/timers.o
CC [M] /home/pi/WireGuard/src/queueing.o
CC [M] /home/pi/WireGuard/src/send.o
CC [M] /home/pi/WireGuard/src/receive.o
CC [M] /home/pi/WireGuard/src/socket.o
CC [M] /home/pi/WireGuard/src/peerlookup.o
CC [M] /home/pi/WireGuard/src/allowedips.o
CC [M] /home/pi/WireGuard/src/ratelimiter.o
CC [M] /home/pi/WireGuard/src/cookie.o
CC [M] /home/pi/WireGuard/src/netlink.o
CC [M] /home/pi/WireGuard/src/crypto/zinc/chacha20/chacha20.o
PERLASM /home/pi/WireGuard/src/crypto/zinc/chacha20/chacha20-arm.S
AS [M] /home/pi/WireGuard/src/crypto/zinc/chacha20/chacha20-arm.o
AS [M] /home/pi/WireGuard/src/crypto/zinc/chacha20/chacha20-unrolled-arm.o
CC [M] /home/pi/WireGuard/src/crypto/zinc/poly1305/poly1305.o
PERLASM /home/pi/WireGuard/src/crypto/zinc/poly1305/poly1305-arm.S
AS [M] /home/pi/WireGuard/src/crypto/zinc/poly1305/poly1305-arm.o
CC [M] /home/pi/WireGuard/src/crypto/zinc/chacha20poly1305.o
CC [M] /home/pi/WireGuard/src/crypto/zinc/blake2s/blake2s.o
CC [M] /home/pi/WireGuard/src/crypto/zinc/curve25519/curve25519.o
AS [M] /home/pi/WireGuard/src/crypto/zinc/curve25519/curve25519-arm.o
LD [M] /home/pi/WireGuard/src/wireguard.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/pi/WireGuard/src/wireguard.mod.o
LD [M] /home/pi/WireGuard/src/wireguard.ko
CC /home/pi/WireGuard/src/tools/wg.o
CC /home/pi/WireGuard/src/tools/config.o
CC /home/pi/WireGuard/src/tools/show.o
CC /home/pi/WireGuard/src/tools/terminal.o
CC /home/pi/WireGuard/src/tools/ipc.o
CC /home/pi/WireGuard/src/tools/encoding.o
CC /home/pi/WireGuard/src/tools/curve25519.o
CC /home/pi/WireGuard/src/tools/setconf.o
CC /home/pi/WireGuard/src/tools/genkey.o
CC /home/pi/WireGuard/src/tools/showconf.o
CC /home/pi/WireGuard/src/tools/pubkey.o
CC /home/pi/WireGuard/src/tools/mnlg.o
CC /home/pi/WireGuard/src/tools/set.o
LD /home/pi/WireGuard/src/tools/wg

sudo make install

INSTALL /home/pi/WireGuard/src/wireguard.ko
DEPMOD 4.19.97+
Warning: modules_install: missing ‘System.map’ file. Skipping depmod.
depmod -a 4.19.97+
‘wg’ -> ‘/usr/bin/wg’
‘man/wg.8’ -> ‘/usr/share/man/man8/wg.8’
‘completion/wg.bash-completion’ -> ‘/usr/share/bash-completion/completions/wg’
‘wg-quick/linux.bash’ -> ‘/usr/bin/wg-quick’
install: creating directory ‘/etc/wireguard’
‘man/wg-quick.8’ -> ‘/usr/share/man/man8/wg-quick.8’
‘completion/wg-quick.bash-completion’ -> ‘/usr/share/bash-completion/completions/wg-quick’
‘systemd/wg-quick@.service’ -> ‘/lib/systemd/system/wg-quick@.service’

Updating WireGuard

cd WireGuard/
git pull
cd src
sudo make
sudo make install

Auto Start:

sudo systemctl enable wg-quick@wg0

Created symlink /etc/systemd/system/multi-user.target.wants/wg-quick@wg0.service → /lib/systemd/system/wg-quick@.service.

Check Status

sudo systemctl status wg-quick@wg0

Stop Service

sudo systemctl stop wg-quick@wg0

Disable Auto Start

sudo systemctl disable wg-quick@wg0

Generating Keys

Covered in WireGuard Essentials

Commands Only

sudo apt update && sudo apt upgrade -y
sudo apt install raspberrypi-kernel-headers libmnl-dev libelf-dev build-essential git -y
git clone https://git.zx2c4.com/WireGuard
cd WireGuard/src
sudo make
sudo make install
sudo systemctl enable wg-quick@wg0

  • https://www.raspberrypi.org/products/raspberry-pi-zero/
,