Skip to content
Wallet live · USDT TRC20 · USDT BEP20 · BTC · ETH · SOL · XMR Free SSL · Malware scan · Instant image 24/7 desk · @rexahost
RexaHostRexaHost

VPS

Self-Hosted VPN on a VPS: WireGuard Setup Guide

· 6 min read

Self-Hosted VPN on a VPS: WireGuard Setup Guide

WireGuard turns a small VPS into your own fast, private VPN for secure public Wi-Fi, remote access to your servers and a stable IP. Complete setup and the trade-offs to understand.

Key takeaways

  • WireGuard is a fast, modern VPN protocol with a small codebase and simple configuration.
  • A 1 vCPU, 1 GB VPS is enough for personal or small team use.
  • Main uses: safe public Wi-Fi, a stable IP for allowlists and private access to your own servers.
  • A self-hosted VPN is not anonymity. Your traffic exits from an IP tied to your account.
  • All traffic from your server is your responsibility under the host's abuse policy.

WireGuard has become the go-to protocol for self-hosted VPNs. It is built into the Linux kernel, uses modern cryptography and needs only a few lines of configuration. In about twenty minutes, a small VPS can become your personal VPN endpoint. This guide covers why you might want one, how to set it up, and the honest limits of what it gives you.

Why run your own VPN?

  • Safer public Wi-Fi: traffic between your device and the VPS is encrypted, so others on a café or hotel network cannot read or tamper with it.
  • A stable, dedicated IP: useful for allowlisting access to admin panels, databases or company tools.
  • Private access to your servers: put SSH, databases and dashboards behind the VPN instead of exposing them to the internet.
  • Control: you decide on logging, DNS and configuration.
  • Linking sites: connect an office network to cloud servers with a site-to-site tunnel.

What a self-hosted VPN does not do

Be clear about the limits. A self-hosted VPN moves trust from your local network to your VPS, but:

  • It is not anonymous. All traffic exits from one IP registered to your account. Websites see that IP; your host knows who rents it.
  • It does not protect against malware or phishing on your device.
  • Websites still identify you through logins, cookies and browser fingerprinting.
  • You are responsible for its use. Abuse from your VPN IP, such as spam, attacks or fraud, is treated as abuse from your server, on every hosting track.

Choosing a VPS and location

WireGuard is very efficient, so CPU and RAM needs are small. Bandwidth matters more, since every byte you browse passes through the server twice (in and out).

UsePlanSpecsTransferPrice
Personal, few devicesVPS Starter1 vCPU / 1 GB1 TB$2.78
Household or small teamVPS Basic1 vCPU / 2 GB3 TB$5.98
Privacy-focused jurisdictionAnchor Starter (DMCA track)1 vCPU / 1 GB1 TB$3.28

Pick a location close to you for speed, or a specific country if you need an IP there for legitimate testing or access. Standard plans offer ten locations; the DMCA track offers locations such as the Netherlands, Romania and Bulgaria. A different jurisdiction changes which copyright notice process applies, but it is not a licence for illegal activity, and the abuse policy is identical everywhere.

Step 1: Prepare the server

Deploy Ubuntu 24.04 or Debian 12, create a sudo user, use SSH keys and enable UFW. Our VPS security checklist explains each step.

Step 2: Install WireGuard

sudo apt update
sudo apt install wireguard qrencode

Because RexaHost VPS plans run on KVM with their own kernel, the WireGuard kernel module works out of the box.

Step 3: Generate keys

cd /etc/wireguard
umask 077
wg genkey | tee server.key | wg pubkey > server.pub
wg genkey | tee phone.key | wg pubkey > phone.pub

Step 4: Configure the server

Find your public network interface with ip route (often eth0 or ens3). Create /etc/wireguard/wg0.conf:

[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <contents of server.key>
PostUp = iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

[Peer]
# phone
PublicKey = <contents of phone.pub>
AllowedIPs = 10.8.0.2/32

Step 5: Enable forwarding and the firewall

echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/99-wireguard.conf
sudo sysctl --system
sudo ufw allow 51820/udp
sudo ufw route allow in on wg0 out on eth0

Step 6: Start WireGuard

sudo systemctl enable --now wg-quick@wg0
sudo wg show

Step 7: Create the client configuration

[Interface]
PrivateKey = <contents of phone.key>
Address = 10.8.0.2/32
DNS = 1.1.1.1

[Peer]
PublicKey = <contents of server.pub>
Endpoint = YOUR_SERVER_IP:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

Save it as phone.conf and display a QR code with qrencode -t ansiutf8 < phone.conf. Scan it in the WireGuard mobile app. On desktop, import the file into the WireGuard client.

AllowedIPs = 0.0.0.0/0, ::/0 routes all traffic through the VPN. To route only traffic for your private servers (split tunnelling), list just the private range, such as 10.8.0.0/24.

Step 8: Test

  1. Connect from your device and run sudo wg show on the server to see a recent handshake.
  2. Check your public IP on a "what is my IP" site; it should show the VPS address.
  3. Run a DNS leak test to confirm DNS queries use the resolver you set.

Adding more devices

Each device needs its own key pair and a unique address (10.8.0.3, 10.8.0.4 and so on). Add a [Peer] block on the server for each, then run sudo systemctl restart wg-quick@wg0. Remove a peer to revoke a lost device instantly.

Using the VPN to protect admin access

One of the best uses of WireGuard is hiding management interfaces. Once connected, restrict SSH and admin panels to the VPN subnet:

sudo ufw allow from 10.8.0.0/24 to any port 22 proto tcp

Keep a fallback (such as the provider's console) before removing public SSH access, so a VPN mistake does not lock you out.

Maintenance and security

  • Keep the OS updated; WireGuard updates come with the kernel.
  • Protect private keys; anyone with a client key can connect as that device.
  • Monitor bandwidth use against your plan's transfer allowance.
  • Decide on logging deliberately. WireGuard keeps minimal state by default, but your firewall and system logs may record connections.

Troubleshooting

SymptomLikely causeFix
No handshakeUDP port blocked or wrong endpointCheck UFW rule and server IP in client config
Handshake but no internetForwarding or NAT missingCheck ip_forward, MASQUERADE rule and interface name
Websites slow to loadDNS issueSet a working DNS server in the client config
Connection drops on mobileNAT timeoutKeep PersistentKeepalive = 25
Some sites fail, others workMTU problemsTry MTU = 1380 in the client Interface section

WireGuard compared with OpenVPN

OpenVPN is the older, widely deployed alternative. It is flexible and can run over TCP port 443, which helps on restrictive networks. WireGuard is simpler to configure, generally faster and uses less CPU, which matters on small VPS plans and for mobile battery life. For most personal and small team setups, WireGuard is the better default; OpenVPN remains useful when you need TCP transport or compatibility with older equipment.

Responsible use

Running a VPN is legal in most countries but restricted in some, so check local laws. More importantly, whatever leaves your VPN leaves from your server. Malware distribution, phishing, spam, fraud, attacks and illegal content are removed and lead to suspension on every RexaHost track, including privacy-focused locations. If you plan to share access with others, you are responsible for their traffic too. Our article on what DMCA-ignored hosting really means explains how jurisdiction and abuse policy interact.

Is it worth it?

For a few dollars a month you get an encrypted tunnel you control, a stable IP and a private network for your servers. Set it up once, back up the configuration, and it will quietly do its job.

Get started

A Linux VPS from $2.78 a month is all you need for a personal WireGuard server. Deploy in your preferred location, pay with crypto and follow the steps above.

Frequently asked questions

Is a self-hosted VPN more private than a commercial VPN?

It gives you control over logging and configuration, but all your traffic exits from one IP that is linked to your account. It protects you on untrusted networks; it does not make you anonymous.

How much does a WireGuard VPS need?

Very little. WireGuard is lightweight, so a 1 vCPU, 1 GB plan handles a household or small team. Bandwidth allowance matters more.

Which port does WireGuard use?

WireGuard uses a UDP port you choose. 51820 is the common default.

Can I use the VPN on my phone?

Yes. Official WireGuard apps for Android and iOS can import a configuration by QR code.

Is it legal to run a VPN?

In most countries, yes. Some countries restrict VPN use. Check the laws where you are and where your server is, and remember that your host's abuse policy applies to traffic from your server.

#wireguard#self-hosted vpn#vpn vps#privacy#remote access

Plans in this article

Servers mentioned here

VPS Starter

Standard
$1.89 /mo
$2.50Save 24% billed monthly
  • 1 vCPU
  • 1 GB RAM
  • 25 GB NVMe
  • 1 TB traffic
  • Root access · dedicated IPv4
  • Ashburn · London · Amsterdam · Frankfurt +6

VPS Basic

Standard
$2.79 /mo
$5.38Save 48% billed monthly
  • 1 vCPU
  • 2 GB RAM
  • 60 GB NVMe
  • 3 TB traffic
  • Root access · dedicated IPv4
  • Ashburn · London · Amsterdam · Frankfurt +6
Offshore

Anchor Starter

DMCA Ignored
Rare · Hard to find
$2.19 /mo
$6.70Save 67% billed monthly
  • 1 vCPU
  • 1 GB RAM
  • 25 GB NVMe
  • 1 TB traffic
  • Root access · dedicated IPv4
  • Amsterdam · Bucharest · Sofia · Chisinau +3

Keep reading

Related articles

Live Chat