If you want to connect a Raspberry Pi running on Raspberry Pi OS (formerly called Raspbian) as a client to a Wireguard VPN server, this article is for you.
In the current version of Raspberry Pi OS, the Wireguard package is already included. Hence, it is very easy to get it installed.
Install the Wireguard VPN software
In a first step, update the Raspberry Pi OS:
sudo apt update
sudo apt dist-upgrade
To install Wireguard:
sudo apt install wireguard
That's the program installation part already.
Obtain the Wireguard client profile from the Wireguard VPN server
To run the Raspberry Pi as a Wireguard client, you will need the VPN configuration profile. This profile or configuration file has to be generated on the VPN server.
Log into your server and create the client configuration file. When the Wireguard VPN server was installed using PiVPN, create a new client configuration:
You will be prompted to enter a name for your client. Pick anything you like and hit 'enter'. The script will assemble the client .conf file and place it in the directory 'configs' within your home directory.
You can then transfer this file from the server to the Raspberry Pi client or, maybe quicker, open the client configuration file on the server, copy all details and paste them into a new configuration file on the client.
On the client, the Wireguard configuration file can go into the directory /etc/wireguard
On the client, create the file (as example we use the client name 'vpnclient') with the text editor nano:
and paste the details from the server's client configuration file into the file on the client and save.
Start the Wireguard client on your Raspberry Pi client (always replace our example name vpnclient with the name you have picked) with:
wg-quick up vpnclient
Now, you are connected with your Raspberry Pi client to your VPN server (assuming that the Wireguard VPN server is configured and running).
To stop the VPN client, you can use the command:
wg-quick down vpnclient
To connect to the VPN every time the Raspberry Pi is turned on, enable it as a service (again, as always, vpnclient is our example name. Use the name you picked, instead):
sudo systemctl enable wg-quick@vpnclient
sudo systemctl start wg-quick@vpnclient
To check if the Wireguard client runs as a service, use the command:
systemctl status wg-quick@vpnclient
When checking the interfaces, using ifconfig, you will see a network interface under your vpnclient name created for Wireguard.
That's it, your Raspberry Pi is running as a Wireguard client and connected to your Wireguard VPN server.