How to Self-Host a VPN with WireGuard
Why this matters
A commercial VPN is a company in the middle. They see the metadata of everything you do, they can change what the exit node sees, and they can go out of business.
WireGuard is the other approach: a few kilobytes of configuration and a UDP socket, with the cryptography in the kernel. There is no daemon to supervise, no certificate authority, no user management system. The server knows a list of public keys and the addresses allowed through each one.
The trade is that you are the operations team. Nothing here is automatic, and a misconfiguration does not announce itself — the tunnel comes up and quietly carries nothing.
What I tested on
- OS: OpenCloudOS 9.6 (kernel 6.6.119-49.23.oc9.x86_64)
- WireGuard: kernel module, with wireguard-tools v1.0.20210914
- Hardware: 2 vCPU / 3.5 GB RAM / 60 GB xfs
- Duration: set up in October 2026

How I tested
I brought the interface up on the server that runs this site and read the state back with wg show — the screenshot is that output, with the public key and the peer. The masquerade rule was installed by the interface’s own PostUp hook, which is how it is supposed to work rather than something I added by hand afterwards.
Step 1: Install the tools
sudo dnf install -y wireguard-tools
wg --version
The tools are small — wg for configuration and wg-quick for the rest. The protocol itself is in the kernel module, and on a current distribution kernel it is already there:
modinfo wireguard | head -2
# filename: /lib/modules/6.6.119-49.23.oc9.x86_64/kernel/drivers/net/wireguard/wireguard.ko.xz
If modinfo finds nothing, you are on a kernel older than 5.6 and need to install wireguard-dkms or upgrade. Check this before you start configuring, because it changes what you do next.
Step 2: Generate the keys
sudo mkdir -p /etc/wireguard
sudo chmod 700 /etc/wireguard
cd /etc/wireguard
umask 077
wg genkey | tee server.key | wg pubkey > server.pub
wg genkey | tee client.key | wg pubkey > client.pub
umask 022
The umask matters. wg genkey writes to standard output, and without it the private key lands in a file that anyone on the box can read. Check the result:
ls -l /etc/wireguard/
# -rw------- 1 root root 64 server.key
Only the public keys go into configuration files that you might paste into a chat window. The private key stays on the machine that owns it.
Step 3: The server configuration
# /etc/wireguard/wg0.conf
[Interface]
Address = 10.7.0.1/24
ListenPort = 51820
PrivateKey = <contents of server.key>
PostUp = iptables -t nat -A POSTROUTING -s 10.7.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -s 10.7.0.0/24 -o eth0 -j MASQUERADE
[Peer]
PublicKey = <contents of client.pub>
AllowedIPs = 10.7.0.2/32
Two things in that file are worth explaining.
AllowedIPs on the server is the list of addresses that peer is allowed to use as a source. It is not a filter in the way a firewall rule is; it is what the server will accept as the source address of a packet from that peer. Set it to /32 for one client. If you set it to 0.0.0.0/0 you are telling the server that this peer may claim any source address, which means two peers can end up with conflicting routes and the tunnel breaks in a way that is hard to read.
PostUp and PostDown are the NAT rules. Without the masquerade, packets arrive from 10.7.0.2 with a source address the rest of the internet has never seen, and they are dropped. With it, the server rewrites the source to its own address on the way out and the replies find their way back.
eth0 is your server’s public interface. Check the name:
ip -brief address
On a cloud server it is often eth0; on some it is ens3 or ens5. Getting it wrong means the tunnel comes up and no traffic leaves.
Step 4: Bring it up
sudo chmod 600 /etc/wireguard/wg0.conf
sudo wg-quick up wg0
sudo wg show wg0
That last command is the one to remember:
interface: wg0
public key: dOXhe42wZfwKxSoK9PpeN+ufb0KKkYjKCbbukUtNCi4=
private key: (hidden)
listening port: 51820
peer: ndrES2DR7AApq+CvSo72J963QmAaMZ5lQ8h570o6zTY=
allowed ips: 10.7.0.2/32
A peer with no latest handshake line has never connected. The screenshot shows the interface and its socket listening on 51820, which is the server side of a tunnel that is ready but has not yet been used.
wg-quick down wg0 takes it back down and removes the NAT rule.
Step 5: The client
# client.conf
[Interface]
PrivateKey = <contents of client.key>
Address = 10.7.0.2/32
DNS = 1.1.1.1
[Peer]
PublicKey = <contents of server.pub>
Endpoint = your-server.example.com:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
AllowedIPs = 0.0.0.0/0 on the client is what sends everything through the tunnel. It is the mirror image of the server’s setting and it means something different on each side, which is where most mistakes happen.
PersistentKeepalive = 25 sends a packet every 25 seconds when the tunnel is idle. NAT tables on consumer routers expire after about a minute, and without it a tunnel that has been quiet falls off the map and needs a manual poke to come back.
The DNS line matters more than it looks. Without it, the tunnel carries your traffic but not your name lookups, so you get the connectivity of a VPN with none of the privacy.
The two mistakes that look like success
The firewall blocks UDP. This is the common one. WireGuard is UDP only, and a default iptables ruleset that drops everything not explicitly allowed will drop the handshake while leaving TCP services working. Your client will report a handshake that never completes. Check what is listening and what the firewall thinks:
ss -ulnp | grep 51820
sudo iptables -L INPUT -n | grep 51820
If the socket is listening and the firewall has no rule for the port, that is your problem. On a cloud server the security group is a second place to check — the host firewall and the provider’s firewall are separate things, and a rule in one does nothing for the other.
The route points the tunnel at itself. If the client routes the endpoint’s own address through the tunnel, the packet leaves, comes back, and leaves again. The symptom is that the tunnel handshake succeeds and then everything times out. The fix is a host route that exempts the endpoint:
sudo ip route add your-server.example.com/32 via 192.168.1.1
This matters most when the endpoint is on the same network the tunnel is trying to reach.
What you reach through the tunnel is usually a web service, and that is a separate job from the tunnel itself — the certificate and the proxy live on the server side, and the reverse proxy guide covers it.
Pros and cons
Pros:
- The cryptography is in the kernel, so there is no userland process in the data path
- Configuration is a handful of lines and the whole file is readable
- Cryptography from libsodium, with a small enough codebase to audit
- A peer is one public key and one allowed address
wg showtells you the state of every tunnel
Cons:
- No user management — every device is a peer entry you add by hand
- No dynamic DNS built in; you need something else to update the endpoint
- WireGuard is UDP only, and networks that block UDP break it
- A configuration mistake usually results in silence rather than an error
- No built-in way to revoke a single peer without editing the file and reloading
Best for / Skip if
Best for: connecting your own devices to your own server, and reaching services that are not published to the internet. Most of what you reach that way is an admin page or a dashboard, and Homer is the cheapest way to put those in one place.
Skip if: you need a commercial VPN for streaming or for anonymity from your own provider, or you need a GUI to manage users.
Alternatives
- Tailscale — the same protocol underneath, with a coordination server, device management and a much easier setup; the cost is that someone else runs the part that maps names to addresses. The whole trade-off is measured in WireGuard vs Tailscale
- OpenVPN — older, heavier, and still the right answer where UDP is blocked
Verdict
WireGuard is the shortest path to owning your VPN that exists. Thirty lines of configuration and no daemon, and once it is up it stays up — but you have to get the NAT rule and the firewall right yourself, and the failure modes are quiet.
References
- WireGuard quick start — the official walkthrough
- WireGuard configuration — the meaning of every option
FAQ
Is it really that fast?
Yes. It is a kernel module and a UDP socket, so there is no userland process to route packets through.
Do I need a static IP?
You need an address clients can reach. On a cloud server that is the address you already have; at home it means a port forward or a dynamic DNS name.
What happens to my traffic if the tunnel goes down?
Nothing useful. With AllowedIPs set to 0.0.0.0/0 the client sends everything through the tunnel, so a failed handshake leaves you with no connection rather than a slow one. The firewall and routing mistakes described in this guide both end that way.