How to Install WireGuard VPN on Ubuntu 22.04

It all started on a rainy Saturday morning…
I sat at my desk, looking at my newly set up Ubuntu 22.04 VPS, and thought it was time to install WireGuard VPN on Ubuntu for my personal projects. After a bit of Googling, one name kept popping up WireGuard. People said it was fast, lightweight, and way easier than OpenVPN.
But honestly? I wasn’t sure where to start.
So, I opened my terminal and thought, “Alright, let’s figure this out.
Step 1: Preparing My Server (and My Nerves)
First, I updated my system. I always do this—it’s like making sure your tools are sharp before you start building:
sudo apt update && sudo apt upgrade -y
Done. No errors. Good start.
Then I installed WireGuard. Surprisingly, it was just one command:
sudo apt install wireguard -y
That’s it. No compiling, no headaches. It felt… too easy?
Step 2: Generating the Keys
Next, I had to create the keys. Honestly, I wasn’t exactly sure how it worked at first—but I knew I needed a private key for the server and a public key for the client.
I ran this command:
wg genkey | tee privatekey | wg pubkey > publickey
That gave me two files in the current directory:
privatekey
publickey
No fancy output, no prompts—just those files.
I kept the private key safe. The public key? That’s the one I’ll utilize for my client’s setup afterward.
Nothing too crazy so far.
Step 3: The Config File – My VPN Blueprint
I opened the config file:
sudo nano /etc/wireguard/wg0.conf
And this is what I wrote:
[Interface] PrivateKey = (my private key here) Address = 10.0.0.1/24 ListenPort = 51820 [Peer] PublicKey = (client public key here) AllowedIPs = 10.0.0.2/32
Simple. Clear. This file was like a map for my VPN.
Step 4: Making It Work
I had to enable IP forwarding—I didn’t know what that was, but a quick search told me it lets my server route traffic. So I did this:
sudo nano /etc/sysctl.conf
Uncommented:
net.ipv4.ip_forward=1
And reloaded:
sudo sysctl -p
Then the magic moment:
sudo wg-quick up wg0
No errors. Just… working.
I even enabled it on boot:
sudo systemctl enable wg-quick@wg0
Felt like a pro.
Step 5: Firewall? Don’t Forget the Firewall!
I almost forgot:
sudo ufw allow 51820/udp
sudo ufw allow ssh
And enabled UFW:
sudo ufw enable
Step 6: Testing – The Best Part
Ran:
sudo wg
I could see the handshake waiting for my client.
Pinged the server:
ping 10.0.0.1
It replied!
Then I checked my public IP:
curl ifconfig.me
And it showed the VPN’s IP. That moment? Pure magic.
What I Learned (And You Can Too)
Setting up WireGuard on Ubuntu 22.04 wasn’t as scary as I thought. It’s mostly about following the steps update, install, generate keys, write config, enable IP forwarding, start the VPN, and test.
If I can do it, so can you.
Oh, and one tip: If you don’t want to mess up your local machine, get a clean VPS. I used Eldernode Germany Linux VPS super easy to spin up, and it keeps your VPN separate from your personal stuff.