Back to articles
Security & Anti-DDoS

Self-Host Personal VPN on VPS with WireGuard to Bypass Geo-Blocks and Secure Web Browsing in 3 Months

A guide to setting up a personal VPN on a VPS using WireGuard, enabling geo-block bypass, secure web browsing, and full system control within three months. The solution leverages...

DPTCloud Engineering4 min read
Self-Host Personal VPN on VPS with WireGuard to Bypass Geo-Blocks and Secure Web Browsing in 3 Months

Setting up a personal VPN on a VPS using WireGuard allows users to bypass geo-restrictions, protect web browsing data, and maintain privacy without relying on commercial VPN services. With its lightweight architecture, high performance, and strong customization capabilities, WireGuard is ideal for deploying secure, self-hosted VPNs on Linux-based VPS platforms. This guide provides detailed steps from basic setup to advanced security configurations, suitable for users seeking full control over their systems within a three-month deployment window.

Requirements and Preparations Before Deployment

To self-host a personal VPN on a VPS using WireGuard, you need a root-accessible VPS, a Linux operating system (Ubuntu 22.04 or Debian 11 and above), and a stable internet connection. The VPS must have a public IP address and the ability to open port 51820/UDP for WireGuard. Below is a list of required components:

  • Cloud VPS with L3/L4/L7 Anycast Anti-DDoS protection at DPTCloud
  • Linux operating system (Ubuntu 22.04)
  • WireGuard software installed on both VPS and client devices
  • Public/private key pairs for each connecting device
  • WireGuard client software on personal devices (Windows, macOS, Linux, Android, iOS)

Ensure your VPS is secured with firewall rules, safe routing, and regular system updates. You can learn more about the network security and 99.98% SLA infrastructure at DPTCloud.

Setting Up WireGuard on VPS

Begin by logging into your VPS via SSH and updating the system:

sudo apt update && sudo apt upgrade -y

Install WireGuard:

sudo apt install wireguard -y

Generate a public/private key pair for the server:

wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey

Create a WireGuard configuration file at /etc/wireguard/wg0.conf:

[Interface]
PrivateKey = <private_key>
Address = 10.0.0.1/24
ListenPort = 51820
SaveConfig = true

[Peer]
PublicKey = <client_public_key>
AllowedIPs = 10.0.0.2/32

Replace <private_key> with the value from /etc/wireguard/privatekey and <client_public_key> with the client’s public key. Enable the service:

sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0

Ensure port 51820/UDP is open on the firewall and VPS:

sudo ufw allow 51820/udp
sudo ufw reload

Client Configuration and Connection

On your personal device, install the appropriate WireGuard client. In the client configuration file, add the following:

[Interface]
PrivateKey = <client_private_key>
Address = 10.0.0.2/24
DNS = 1.1.1.1, 8.8.8.8

[Peer]
PublicKey = <server_public_key>
Endpoint = <vps_ip>:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

Replace <client_private_key> with the client’s private key, <server_public_key> with the VPS public key, and <vps_ip> with the VPS’s public IP. Activate the connection and verify:

wg show

To verify the connection, visit whatismyip.com to confirm your IP has changed to the VPS’s IP.

Security and Customization

To enhance security, configure the firewall to allow only authorized devices to connect. Use the firewall and ip_forward features to route traffic securely. Configure iptables to forward traffic through the VPS:

sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -A FORWARD -i wg0 -j ACCEPT
sudo iptables -A FORWARD -o wg0 -j ACCEPT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

To ensure configuration persists after reboot, add the commands to /etc/rc.local or use systemd. You can also integrate Cloudflare Access and JWT validation in Caddy for additional protection of internal services.

Verification and Troubleshooting

To verify the VPN is working, check the connection status:

wg show

If the connection fails, check for common issues:

  • Port 51820/UDP is blocked by the VPS provider or ISP
  • Public/private keys do not match between server and client
  • Incorrect ip_forward or iptables configuration
  • Firewall blocking the connection

Restart the service:

sudo systemctl restart wg-quick@wg0

To test network connectivity, use ping or traceroute to public IPs. If issues persist, review the logs:

sudo journalctl -u wg-quick@wg0

For additional protection, consider deploying Coraza WAF with Traefik v3 reverse proxy on the same VPS to block remote attacks.

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478