RDP Monster

WireGuard Server on a Linux VPS: Setup Guide in 10 Minutes

WireGuard Server on a Linux VPS: Setup Guide in 10 Minutes

What a WireGuard server is and what you need

A WireGuard server is a Linux machine with the WireGuard kernel module, one virtual interface (conventionally wg0), a key pair, and a NAT rule that lets connected peers' traffic leave through its public IP. There is no daemon: the module has been in mainline Linux since 5.6 (Ubuntu 20.04 backported it), and the wg tool only configures it.

You need a Linux VPS with root access (commands target Ubuntu 22.04/24.04 and Debian 12; other distributions are in the install table), SSH access, ideally key-based since a VPN endpoint is a machine you keep for years (see enable SSH on Ubuntu and harden it), one reachable UDP port, 51820 by default, and about ten minutes.

Install WireGuard and generate the server keys

1. Install the package

DistributionCommand
Ubuntu 20.04+ / Debian 11+sudo apt update && sudo apt install -y wireguard
Fedorasudo dnf install -y wireguard-tools
Rocky / AlmaLinux 9sudo dnf install -y epel-release && sudo dnf install -y wireguard-tools
Archsudo pacman -S wireguard-tools

On Debian and Ubuntu the wireguard metapackage pulls in wireguard-tools (wg and wg-quick). Verify with sudo modprobe wireguard; silence means the module loaded. Everything below runs in a root shell (sudo -i).

2. Generate the key pair

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

umask 077 keeps the files readable by root only. Keys are 32 bytes encoded as 44 base64 characters; the private key never leaves the server, the public key goes into every client config. The same line on a client produces that client's pair.

Server config: wg0.conf, IP forwarding and NAT

1. Find the public interface

ip route show default

The output names the interface carrying the default route: eth0 on most VPS images, often ens3 or enp1s0. Substitute it for eth0 below.

2. Write /etc/wireguard/wg0.conf

[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT; iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT; iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

Then chmod 600 /etc/wireguard/wg0.conf. 10.8.0.0/24 exists only inside the tunnel; pick a range your clients' networks do not use. ListenPort must be set on the server, otherwise WireGuard picks a random port at each start. PostUp lets packets from the tunnel be forwarded, lets the replies back in, and rewrites their source address to the VPS public IP (MASQUERADE) so answers find their way back; PostDown removes the same rules. On current Debian and Ubuntu, iptables is the nftables-backed iptables-nft, so this needs no backend change.

3. Enable IP forwarding

echo 'net.ipv4.ip_forward = 1' > /etc/sysctl.d/99-wireguard.conf
sysctl --system

Without this the kernel silently drops the peers' packets: the handshake succeeds and nothing else works. Add net.ipv6.conf.all.forwarding = 1 if you route IPv6 through the tunnel.

4. nftables instead of iptables (optional)

With native nftables (and no other table dropping forwarded traffic), use PostUp = nft -f /etc/wireguard/wg0.nft and PostDown = nft delete table inet wg instead, and create that file:

table inet wg {
    chain forward {
        type filter hook forward priority filter; policy accept;
        iifname "wg0" accept
        oifname "wg0" ct state related,established accept
    }
    chain postrouting {
        type nat hook postrouting priority srcnat; policy accept;
        ip saddr 10.8.0.0/24 oifname "eth0" masquerade
    }
}

5. Open the port and start the interface

ufw allow 51820/udp                       # if UFW is enabled
ufw route allow in on wg0 out on eth0     # UFW forwards nothing by default
wg-quick up wg0
wg show
wg-quick down wg0
systemctl enable --now wg-quick@wg0

wg-quick up is the manual test; bring the interface down before enabling the unit, because wg-quick@wg0 refuses to start when wg0 already exists. The tunnel now comes up at every boot. Only UDP is needed: WireGuard has no TCP mode.

Add a client: config file, QR code, apps

1. Client keys and config

Generate a key pair for the client (on the client if you can, on the server for a phone), then write its config as vps.conf; on Linux the file name becomes the interface name.

[Interface]
PrivateKey = CLIENT_PRIVATE_KEY
Address = 10.8.0.2/24
DNS = 1.1.1.1

[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = SERVER_PUBLIC_IP:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

PersistentKeepalive = 25 sends an empty packet every 25 seconds so NAT routers and mobile carriers keep the UDP mapping alive; without it the server loses the way back to an idle client. DNS is optional in the protocol, not in practice: a full tunnel without it keeps the previous resolver, on a laptop usually the home router, reached outside the tunnel: a DNS leak. To keep resolution inside the tunnel, run Unbound on the VPS bound to 10.8.0.1 and use that address.

2. Register the peer on the server

wg set wg0 peer CLIENT_PUBLIC_KEY allowed-ips 10.8.0.2/32
wg-quick save wg0

The first command adds the peer live, without disturbing anyone connected; the second writes it into wg0.conf (regenerated from the live state, so comments are lost). If you prefer appending a [Peer] block with PublicKey and AllowedIPs = 10.8.0.2/32 by hand, reload without restarting the interface:

wg syncconf wg0 <(wg-quick strip wg0)

On the server, AllowedIPs means "which source addresses may this key send from": one /32 and one key pair per device. Sharing a config between two devices makes the server flip its endpoint between them, and both stall.

3. Phones: QR code

apt install -y qrencode
qrencode -t ansiutf8 < /root/vps.conf

Scan the code from the add-tunnel menu of the WireGuard app on iOS or Android, then delete the phone's private key from the server.

4. Windows, macOS, Linux

  • Windows: install the client from wireguard.com, Add Tunnel, import vps.conf, Activate.
  • macOS: the App Store client imports the same file, or brew install wireguard-tools for wg-quick.
  • Linux: sudo wg-quick up ./vps.conf, or copy the file to /etc/wireguard/ and run sudo wg-quick up vps. The DNS line needs resolvconf or openresolv on the client.

Full tunnel or split tunnel: AllowedIPs and DNS

On the client, AllowedIPs is both a filter and a routing table: wg-quick installs a route for every prefix listed, and the interface only accepts packets from those prefixes.

ModeClient AllowedIPsThrough the VPSTypical use
Full tunnel0.0.0.0/0, ::/0Everything, DNS included if DNS = is setPublic Wi-Fi, hiding traffic from the ISP
Split tunnel10.8.0.0/24 plus chosen subnetsOnly the tunnel network and those subnetsReaching the VPS or a private network
IPv4-only full tunnel0.0.0.0/0IPv4 only; native IPv6 keeps its normal pathAvoid: IPv6 bypasses the VPN

Listing ::/0 even when the tunnel carries no IPv6 is deliberate: IPv6 is then black-holed rather than sent around the VPN, the safer failure mode. One trap: if the client is itself a server you reach over RDP or SSH, a full tunnel routes the replies to your own session through the VPN and drops it; using a VPN on an RDP server without losing the connection covers the routing exception you need.

Test the tunnel and fix the usual failures

# on the server
wg show
ss -ulnp | grep 51820

# on the client
curl -4 https://ifconfig.me

wg show lists every peer with latest handshake and transfer counters; a recent handshake means keys and endpoint are right, and curl should print the VPS address.

  • No handshake: a public key pasted where a private one belongs, an Endpoint port that differs from ListenPort, or UDP 51820 blocked. ss confirms the server is listening; for the firewall side, see how to check open ports on Linux. WireGuard never answers unauthenticated packets, so an external UDP scan cannot prove the port is open; only a handshake can.
  • Handshake, but no internet: ip_forward still 0, a MASQUERADE rule on the wrong interface, or a FORWARD policy of DROP (UFW, Docker). iptables -t nat -L POSTROUTING -n -v shows whether the rule counts packets.
  • Some sites hang: MTU. Add MTU = 1280 to the client [Interface]; the default 1420 is too large on some mobile and PPPoE links.

The server-side log is journalctl -u wg-quick@wg0; WireGuard itself logs nothing by default.

What a self-hosted VPN hides, and from whom

Be precise about the threat model: "VPN" gets sold as anonymity, and this is not that.

  • Hidden from the local network and your ISP: destinations and content. They see encrypted UDP to one IP address and nothing else. This is the real win on hotel Wi-Fi, behind a censoring network, or on an ISP that logs DNS history.
  • Hidden from websites: your home IP, replaced by the VPS IP. Cookies, logins and browser fingerprint still identify you.
  • Not hidden from the VPS provider: traffic leaves the VPS with the tunnel encryption removed, so the host can see every destination your peers talk to, and any content not encrypted end to end, exactly as your ISP could before. A single-hop VPN does not remove the observer; it moves it from your ISP to the hosting company. And since you are the only user of that IP, everything it does is attributable to the account paying for it.

What matters, then, is who runs the host, what they log and what they know about you. A commercial VPN with many users per exit IP gives crowd cover a personal VPS cannot; in exchange, a personal VPS gives you the configuration, the logs and the resolver.

If the weak point is the account behind the server, the Anonymous VPS from rdp.monster is built for this setup: no KYC, paid in crypto, full root access, dedicated CPU and RAM, unlimited (fair-use) bandwidth, from $8.99 per month, online about 10 seconds after payment confirms. The provider still sees where the traffic goes; what it does not hold is an identity document to attach it to.

Frequently Asked Questions

Is WireGuard better than OpenVPN for a VPS?

For most VPS setups yes: simpler config, in-kernel, modern crypto; OpenVPN keeps an edge only where UDP is blocked.
WireGuard is a far smaller codebase than OpenVPN, runs inside the Linux kernel, uses a fixed modern cipher suite (ChaCha20-Poly1305, Curve25519, BLAKE2s) and reconnects immediately when a phone changes network. Configuration is one file and two keys, with no certificate authority to maintain. OpenVPN still matters where you need a TCP transport: some hotel and corporate networks block UDP entirely, and OpenVPN over TCP 443 passes through them. If UDP works from where you are, WireGuard is the sensible default.

What port does WireGuard use?

UDP 51820 by default; any UDP port works, and there is no TCP mode.
WireGuard listens on UDP 51820 unless ListenPort says otherwise, and there is no TCP mode. Any port is fine, including 53/udp or 443/udp on networks that only let those through, but moving the port is not a security measure: the protocol already gives no reply to unauthenticated packets, which is why a port scan cannot even tell that a WireGuard server is running. Open the port in the VPS firewall and in the provider's security group if one exists, and set the client's Endpoint to match.

Can several devices use the same WireGuard server at once?

Yes, as long as every device has its own key pair and its own tunnel address.
A WireGuard server handles as many peers as you add, each with its own [Peer] block, public key and AllowedIPs such as 10.8.0.3/32, 10.8.0.4/32 and so on. What does not work is copying one client config to two devices: they would share an address and a key, the server would keep switching its endpoint between them, and both would drop packets. Generate a new pair per device, hand out the next free address, register it with wg set, and save the config.

Why does WireGuard connect but give me no internet?

The handshake only proves the keys; internet access depends on forwarding, NAT and DNS on the server side.
A recent handshake in wg show means encryption is fine and the failure is in routing. Check in this order: sysctl net.ipv4.ip_forward must return 1; iptables -t nat -L POSTROUTING -n -v must show a MASQUERADE rule on the real public interface with a packet count that grows; the FORWARD chain must accept traffic from wg0 (UFW and Docker both default it to DROP); and the client needs a working DNS entry, because a tunnel that carries packets but cannot resolve names looks exactly like no internet.

Adrien Roche, Infrastructure & Hosting Editor

Systems engineer with 10+ years operating Windows Server and Linux fleets. Adrien runs the rdp.monster infrastructure documentation and writes our guides on RDP, VPS hosting, server administration, networking and privacy tooling.

Register to our reseller program

Your information

If you have any question, contact us by clicking here !
Name(Required)
Enter your email address, you must have an account on dashboard.rdp.monster !

Your company

Enter your website address if you have one
Quickly explain how you're going to sell services to your customers. For example, talk to people on forums.

Even monsters love cookies!

We use cookies to enhance your browsing experience, serve personalized ads or content, and analyze our traffic. By clicking "Accept", you consent to our use of cookies.