What is WireGuard VPN and how does it work?
Wireguard is a modern Virtual Private Network (VPN) protocol that enables secure, encrypted connections between devices. With a simple codebase and high performance, it has established itself as a powerful and resource-efficient alternative to older VPN protocols such as IPsec and OpenVPN. In this article, you will learn what sets Wireguard apart, how it works, and how to install this VPN solution on your own system.
What is Wireguard?
Wireguard is an open-source VPN protocol used to establish encrypted tunnels between devices. Data streams are routed through this tunnel and are thus protected from unauthorized access. In addition to focusing on strong encryption, Wireguard also offers optimizations for mobile systems and the Internet of Things (IoT). The software is licensed as free software under the GPLv2 license and is available across platforms. Wireguard is written in C and Go and runs on Windows, macOS, BSD, iOS, and Android.
Since 2020, Wireguard has been directly integrated into the Linux kernel. Because Linux runs as the standard operating system on billions of connected devices worldwide, Wireguard can be used almost anywhere. Thanks to its simple configuration and low system load, Wireguard is increasingly being used by VPN services and businesses.
What features does Wireguard have?
A central feature of Wireguard is the so-called Cryptokey Routing. In this process, the IP address ranges allowed within a tunnel are assigned to a peer’s public key. Incoming packets from a peer are decrypted using the public key. After decryption, an incoming packet is delivered only if it originates from an IP address that corresponds to the key. Otherwise, the packet is discarded.
In contrast to older VPN protocols such as IPsec and OpenVPN, Wireguard uses a fixed set of modern cryptographic primitives without negotiation. While established protocols negotiate the cryptographic foundations during the handshake, Wireguard relies on a fixed, versioned combination of algorithms. If a cryptographic primitive is deemed insecure in the future, a new version of the protocol will be released that includes an updated and secure algorithm selection.
The protocol uses modern and highly secure encryption algorithms, including:
- Noise Protocol Framework for handshake and key exchange processes
- Curve25519 for secure key exchange
- ChaCha20 for symmetric encryption
- Poly1305 for authentication
- BLAKE2 for a fast cryptographic hash function
- SipHash24 for generating cryptographically secure hashes
- HKDF for the secure key derivation process
What are the advantages of Wireguard?
Wireguard offers many advantages that make it a preferred choice for modern VPN connections. The key benefits at a glance:
- Lean code base: Wireguard has a significantly smaller code base, with only about 4,000 lines of code compared to OpenVPN or IPsec (around 100,000 to 600,000 lines). This reduction makes the protocol more secure, since bugs are easier to find, and more resource-efficient, since it requires less computing power.
- Higher performance: Due to its lower complexity, Wireguard delivers higher transfer speeds and lower latency than many competing protocols. This makes it ideal for applications that require a fast and stable connection, such as streaming, online gaming, and video conferencing.
- Energy efficiency: Wireguard is only active when data is actually being transmitted. This power saving is especially beneficial for mobile devices, as it extends battery life.
- Roaming support: Wireguard supports seamless switching between Wi-Fi and mobile networks without losing the connection. If the connection does drop, it is usually re-established faster than with other VPN protocols.
- Easy configuration: Compared to other VPN protocols, Wireguard does not require manual configuration of a large number of cryptographic options. It uses a fixed, well-defined configuration that is accessible to both experienced users and beginners.
How does Wireguard work?
Wireguard is a decentralized peer-to-peer VPN protocol that does not require a central server. Instead, a tunnel can be established directly between two devices (“peers”). In this case, a “Wireguard server” is simply a device that contains configuration data for multiple peers.
The connection setup works similarly to Secure Shell (SSH): Peers generate public and private key pairs, exchange them, and use them for authenticating and encrypting the transmitted data. The encryption is based on modern cryptographic methods that ensure a high level of security.
In addition to creating the cryptographic keys, you need to set network and routing settings on the peers (see our guide below). This includes configuring the allowed IP address ranges, which are linked to the public keys. Only packets from these IP addresses are accepted.
Data transmission runs over the User Datagram Protocol (UDP), which is preferred because of its speed and efficiency. It does not require extensive error correction like the Transmission Control Protocol (TCP), enabling faster transfers.
Configuration is usually done using the Wireguard command-line tool and standard networking tools. For less experienced users, commercial VPN providers offer user-friendly apps for easy setup.
How to get started with Wireguard
In principle, Wireguard can be installed and configured on a Linux system with little effort. On newer Ubuntu versions (from 20.04 LTS), Wireguard is already integrated as a kernel module, so there is no need to install additional Personal Package Archive (PPA) repositories. Simply run the following command:
sudo apt install wireguardbash
How to install Wireguard on your own system
Installing Wireguard on your own system is simple and can be done with just a few commands.
For Ubuntu 20.04 LTS or newer:
Wireguard is already integrated as a kernel module, so no additional PPA repositories are required. Simply run the following command:
sudo apt update
sudo apt install wireguardbashFor older Ubuntu versions:
Here you need to add the Wireguard PPA to perform the installation:
sudo add-apt-repository ppa:wireguard/wireguard
sudo apt-get update
sudo apt-get install wireguardbashGenerating Wireguard keys
As with many other modern VPN protocols, Wireguard is also based on the use of cryptographic keys to establish secure connections between peers. Each peer needs a private and a public key pair. The private key always remains secret, while the public key is shared with other peers.
Run the following commands on the command line to generate a private and public Wireguard key:
# Create key directory and set permissions
sudo mkdir -p /etc/wireguard/keys
sudo chmod 700 /etc/wireguard/keys
cd /etc/wireguard/keys
# Set umask so only root can read/write
umask 077
# Generate private key and save it to file
wg genkey | sudo tee privatekey | wg pubkey | sudo tee publickey
# Check the output of the generated keys
sudo cat privatekey
sudo cat publickeybashThe keys should be created and stored in a secure environment. The commands above are suitable for testing purposes. In a production environment, additional security measures should be taken, such as using secure directories and access controls.
Configuring network settings for Wireguard
After the cryptographic keys have been generated, certain network and routing settings must be configured on each peer. This configuration is crucial to enable secure communication between the peers.
Essentially, a configuration file is created that contains, among other things, the following information:
- Private and public keys of the peers
- Allowed IP addresses (the IP ranges the peer is allowed to communicate with)
- Peer addresses that are associated with the respective public keys
An example of the basic configuration of a Wireguard connection might look like this:
[Interface]
# Internal VPN IP of the server
Address = 10.0.0.1/24
# Private key (of the server)
PrivateKey = <SERVER_PRIVATE_KEY>
# UDP port where Wireguard accepts connections
ListenPort = 51820
# Client peer
[Peer]
# Public key of the client
PublicKey = <CLIENT_PUBLIC_KEY>
# Internal VPN IP assigned to the client
AllowedIPs = 10.0.0.2/32txtTesting the connection and activating Wireguard
After Wireguard has been installed and configured on your system, it’s time to test the connection and activate the network interface. This can be done from the command line by running the following commands:
1. Activate network interface
First, you need to activate the Wireguard interface you just configured:
sudo systemctl enable --now wg-quick@wg0bashThis command activates the Wireguard interface (wg0) that you created earlier. If this command runs successfully, the connection should be ready to send data.
2. Test the connection
To make sure the connection is working, you can use the ping command to check whether the remote device is reachable. For example:
ping 192.168.1.2bashReplace the IP address with that of the remote peer you are connected to. If the ping is successful, it means the VPN connection is working.
3. Troubleshooting
If the connection is not working as expected, check the following points:
- Make sure the IP addresses are configured correctly.
- Check whether the public and private keys have been exchanged correctly.
- Make sure the firewall on both devices is configured to allow Wireguard traffic (usually over port 51820).
If problems persist, you can also restart the Wireguard service:
sudo systemctl restart wg-quick@wg0bash

