A WireGuard Ubuntu setup turns a small server into your own private VPN. A VPN is a locked tunnel between two devices, so nobody in the middle can read your data. Imagine Maya, who sits in a busy cafe. She needs a document from her home computer. The cafe Wi-Fi is open to everyone, so she does not trust it. She wants a private path back home, and she wants it today.
WireGuard is a good fit. It stays quiet and only sends packets when a peer has data, as the WireGuard quickstart explains. A peer is one device in the tunnel, such as your phone or your server. The tool is small, so the steps are short. But one wrong move on a remote machine can lock you out.
So this guide puts a “Did it work?” check after each step. You also keep a second terminal and a root console open. We checked each command against the official server documentation.
WireGuard Ubuntu basics and what you need first

Think of the setup as a private tunnel under a busy street. Each device in the tunnel is a peer, and each peer owns a keypair. A keypair is one private secret and one public partner. You share the public part freely, but you never share the private part. It works like a house key and a lock. Anyone may look at the lock, but only you carry the key.
Before you start, gather four things:
- A server you control, such as a cheap VPS or a spare machine at home.
- A user account that can run sudo.
- One UDP port you can open. This guide uses 51820 and the 10.8.0.0/24 range as examples.
- A second terminal window, so you can test without closing your first session.
If the server sits at home, your router must forward that UDP port to it. No home machine yet? Then set up a home server first and come back.
Install WireGuard on Ubuntu and make the keys

Sign in to your server. If you have not done that safely yet, learn to log in with SSH keys first, because a password login is the weak spot. Installing takes two short commands:
sudo apt update
sudo apt install wireguardDid it work? Ask the shell where the tool lives:
command -v wgIf you see a path, the tool is ready. If you see nothing, read the last lines of the apt output for an error. For other systems, the official install page lists the right command.

Next, make the server’s keypair. Open a root shell, move to the WireGuard folder and set umask 077. That makes each new file readable by you alone, like a drawer that locks itself.
sudo -i
cd /etc/wireguard
umask 077
wg genkey | tee server.priv | wg pubkey > server.pubThe last line makes the private half, saves it, and then builds the public half from it. Did it work? Run cat server.pub and you should see one short line of text. Copy it into a note, because your devices will need it. Never share server.priv, and never post it anywhere.
Create the WireGuard config and open the firewall
Your WireGuard Ubuntu server reads one small file, /etc/wireguard/wg0.conf. Open it with nano, paste these lines and swap in your private key:
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = PASTE-SERVER-PRIVATE-HERE
PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADEAddress gives the server its place inside the tunnel. ListenPort is the door your devices knock on. The PostUp and PostDown lines switch on NAT when the tunnel goes up and off when it goes down. Match eth0 to your real network card, shown by ip route. Then lock the file:
chmod 600 /etc/wireguard/*.conf
exitA VPN server must also pass traffic on to the internet, like a post office that sorts mail for other towns. So turn on forwarding and make it stay on after a reboot:
sudo sysctl -w net.ipv4.ip_forward=1
echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/99-wireguard.confDid it work? Run cat /proc/sys/net/ipv4/ip_forward, and the answer should be 1. Now open the door. Beginners often lock themselves out here, so allow your SSH port first:
sudo ufw allow 22/tcp
sudo ufw allow 51820/udp
sudo ufw statusTest from your second terminal before you close the first one. Your host’s own panel firewall needs the same UDP rule.
Start the server and add your devices
One command starts your WireGuard Ubuntu server now and at each reboot:
sudo systemctl enable --now wg-quick@wg0Did it work? Run sudo wg show. You should see your port and public key, with no peers yet. If it fails, look for a typo in the config.
Each client needs its own keypair, made the same way. Then give Maya’s laptop a config like this:
[Interface]
Address = 10.8.0.2/24
PrivateKey = PASTE-LAPTOP-PRIVATE-HERE
[Peer]
PublicKey = PASTE-SERVER-PUBLIC-HERE
Endpoint = YOUR-SERVER-IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25AllowedIPs decides which traffic uses the tunnel. The value 0.0.0.0/0 sends everything, which hides your traffic on public Wi-Fi. Use 10.8.0.0/24 to send only home traffic.
Now add the laptop to the server’s file, then restart the service:
[Peer]
PublicKey = PASTE-LAPTOP-PUBLIC-HERE
AllowedIPs = 10.8.0.2/32For an Android phone, install the WireGuard app. Then show the client config as a QR code on the server and scan it. Clear your screen afterwards.
sudo apt install qrencode
qrencode -t ansiutf8 < client.confOn Windows, import the same text into the official app. Want no open port at all? Then try Tailscale, which needs no port forwarding.
Check that your WireGuard Ubuntu tunnel works
Bring the tunnel up on the laptop. Then run sudo wg show on the server. A working peer shows a latest handshake line. That is the moment the two devices say hello. The troubleshooting guide adds a trick: run watch wg for live status. Next, ping the server through the tunnel:
ping -c 3 10.8.0.1Replies mean the tunnel carries data. Last, search for “what is my IP” in a browser. With the full tunnel, you should see your server’s address, not the cafe’s.
If the handshake never appears, go down this list and test after each fix:
- Each side keeps its own private key and holds the other side’s public key.
- AllowedIPs match on all peers, because a wrong range drops traffic silently.
- Forwarding is on, and it stays on after a reboot.
- The UDP port is open in your host’s cloud panel or your home router.
- The card name in PostUp matches the real one, such as enp3s0.
A missing handshake points at keys, ports or the firewall. A handshake with no ping points at addresses or forwarding.
Your WireGuard Ubuntu tunnel is ready
Back in the cafe, Maya taps one switch on her phone, and the tunnel wakes up. Seconds later she opens the home document she needed. The cafe Wi-Fi did not change, but the road between her and home is now a private tunnel.
That is the quiet power of your own server. You installed one package, made a keypair, wrote a short config and opened one port. Keep that habit: change one thing, check it, and then move on.
One honest note. A VPN does not make you anonymous. It moves your trust from the cafe to the company that hosts your server, so pick that host with care.
Next, set up each device you own and give each one its own address in the 10.8.0.0/24 range. Save a copy of your config somewhere safe, away from the server. Then your WireGuard Ubuntu tunnel is ready for any public place.
Frequently Asked Questions
The steps in this guide use only apt and the wg tools, and none of them asks you to pay for software. A VPS or a home server may still cost money.
Run sudo systemctl restart wg-quick@wg0.
Stop and disable the service the same way you started it, using disable instead of enable. Then run sudo apt remove wireguard.
The ListenPort line in the config sets it. This guide uses 51820 over UDP as an example, and any port works if the firewall matches.










































