ADVERTISEMENT

How I built my own VPN (and what I learned)

How I made my own VPN
Karolis Tiškevičius
Karolis Tiškevičius Content Researcher
September 9, 2025 7 min read

Why even build your own VPN?

How to make VPN on Google Trends
Term how to make a VPN on Google Trends

Choosing a server and getting WireGuard running

Installation of WireGuard package on Linux
Installation of the WireGuard package on Linux

Generating the keys

Wireguard-tools installation on Mac terminal
Wireguard-tools installation on Mac terminal
Generation of private/public keys on the Mac terminal

Building the server configuration

[Interface]
PrivateKey =
Address = 10.0.0.1/24ListenPort = 51820
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A
POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j
ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D
POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FOWARD -i wg0 -j
ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

[Peer]
PublicKey =
AllowedIPs = 10.0.0.2/32
  • iptables -A FORWARD -i wg0 -j ACCEPT allows traffic coming from the VPN tunnel (wg0) to be forwarded out to other networks. Without this, the server would drop packets from VPN clients.
  • iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE turns on network‑address translation (NAT) for outgoing traffic. MASQUERADE rewrites the source address of packets from your private VPN network so they appear to come from the server’s public IP. This “hides” all of your clients behind one address and allows them to browse the internet normally.
ADVERTISEMENT
Opened wg0.conf file with the above-mentioned configuration template on the VPS side
Opened wg0.conf file with the above-mentioned configuration template on the VPS side
  • PublicKey is the client’s public key (from publickey_client)
  • AllowedIPs defines which IP address(es) on the VPN are assigned to that client. 10.0.0.2/32 means the client will use only the single IP 10.0.0.2

Setting up IP forwarding and the firewall

Opened sysctl.conf file with IPv4 and IPv6 forwarding enabled on the VPS side
  • ufw allow 51820/udp to allow incoming WireGuard connections
  • ufw allow ssh so you can still manage your server
  • ufw enable to activate the firewall
VPN is being launched with the wg-quick up wg0 command
VPN is being launched with the wg-quick up wg0 command and the systemctl enable wg-quick@wg0 command, enabling the VPN to start on boot

Connecting to your new VPN

WireGuard app on Mac with no configuration files added
WireGuard app on my Mac with no configuration files added
[Interface]
PrivateKey =
Address = 10.0.0.2/24
DNS = 1.1.1.1, 1.0.0.1

[Peer]
PublicKey =
Endpoint = :51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
WireGuard app after adding a configuration file
wg command on the VPS side showing a successful connection
IPleak.net shows that I'm routing my traffic through the VPS IP

IP leak shows that I'm routing my traffic through the VPS IP

dnsleaktest.com shows the same VPS IP with several Cloudflare DNS servers

DNS leak test shows the same VPS IP with several Cloudflare DNS servers

What I gained – and what I didn’t

Lessons learned and final thoughts

ADVERTISEMENT