WireGuard is a modern, lightweight VPN solution built into the Linux kernel by default, and it’s much easier to configure than older protocols like OpenVPN. In this article, you’ll set up a WireGuard server step by step: install the software, generate key pairs, create a server configuration, add a client, and test the connection. The result is an encrypted tunnel between your devices and your server.
What is WireGuard and when do you use it
WireGuard builds an encrypted point-to-point tunnel between two devices based on public and private keys, similar to SSH. You might use it, for example, to securely log in to a server without exposing your management ports publicly, to route traffic between multiple servers over a private network, or as a user to safely browse the internet through your own server instead of a commercial VPN service. Because WireGuard has no session management and uses minimal code, it’s quick to set up and easy to maintain.
Installing WireGuard
Most modern Linux distributions include WireGuard in their default package manager. Log in to your server via SSH and install the package.
Install the package
On Debian or Ubuntu: sudo apt update && sudo apt install wireguard. On RHEL- or AlmaLinux-based systems, use sudo dnf install wireguard-tools.
Enable IP forwarding
In /etc/sysctl.conf, set the line net.ipv4.ip_forward=1 and apply it with sudo sysctl -p, so the server is allowed to forward traffic between the tunnel and the internet.
Generate key pairs
On both the server and the client, generate a private and public key with wg genkey | tee privatekey | wg pubkey > publickey. Keep the private key secret and only share the public key.
Configuring server and client
On the server, create the file /etc/wireguard/wg0.conf with an [Interface] section for the server itself and a [Peer] section per client. In the interface section, set the private IP range of the tunnel (for example 10.0.0.1/24), the listening port, and the server’s private key. In the peer section, fill in the client’s public key and the allowed IP within the tunnel.
On the client, create a similar file, with the client as the interface and the server as the peer. Here, specify the server’s public IP or hostname, the port, and in AllowedIPs the range that should be routed through the tunnel (0.0.0.0/0 for all traffic, or just the tunnel subnet if you only want communication between server and client).
Start the tunnel on the server with sudo wg-quick up wg0 and make sure it starts automatically on reboot with sudo systemctl enable wg-quick@wg0. Then open the chosen UDP port in your firewall so clients can connect.
Testing and managing the connection
On the client, start the tunnel with sudo wg-quick up wg0 and check with ping to the server’s internal IP whether the tunnel works. With sudo wg show you can see on both devices the active peers, the latest handshake, and the amount of data sent and received, which is useful for verifying that traffic is actually going through the tunnel.
If you also manage a web server with Plesk alongside WireGuard, you’ll find a clear overview there of firewall settings and open ports, so you can neatly isolate the WireGuard port from your websites and email. If you have questions about server configuration, check the knowledge base or contact support.
Also make sure your VPN server and the services running on it, such as your web hosting and business email, continue to function independently: a misconfigured firewall rule for WireGuard should never block other services.
Frequently Asked Questions
Does WireGuard work on every Linux distribution?
Most current distributions support WireGuard by default. Older kernels may need a separate kernel module or dkms package.
Is WireGuard more secure than OpenVPN?
WireGuard uses modern cryptography and a much smaller codebase, making it easier to audit and less prone to errors. Both protocols, when configured correctly, are suitable for encrypted connections.
Can I connect multiple clients at once?
Yes, add a separate [Peer] section for each client with its own public key and a unique IP within the tunnel subnet.
Which port does WireGuard use by default?
There’s no fixed default port, but UDP port 51820 is commonly used. You can choose a different port yourself and open it in your firewall.
Do I need to change my domain for WireGuard?
No, WireGuard works independently of your domain configuration. If you use a hostname instead of an IP address for the server, make sure it points correctly via your domain names management.
Conclusion
With WireGuard, you can quickly set up a lightweight, secure VPN tunnel between your server and your devices: install the package, generate key pairs, configure the server and client, and open the right port in your firewall. Use wg show to easily verify everything keeps working.