LINUXMIND.DEVTHE GNU/LINUX WORLD

WireGuard on Linux: set up your own VPN in ten minutes

Flat editorial illustration of two laptops at either end of an encrypted tunnel drawn across a simple globe grid, with a padlock floating above

WireGuard is the VPN that finally made “set up a VPN” a ten-minute job. It has been in the Linux kernel since 5.6, it is small enough to audit, and its configuration is a handful of lines you can read in one sitting. This guide wires up one small server and one client — the pattern you then extend to a whole fleet.

Everything here is plain text config; there is no web UI and no certificate authority to run.

Why WireGuard and not the old stacks

OpenVPN and IPsec work, but they carry decades of options and failure modes. WireGuard does one thing: an encrypted UDP tunnel between peers identified by public keys. There is no cipher negotiation to misconfigure and no CA to keep alive. It is fast because it runs in the kernel, and the config is short enough that you can actually understand what every line does.

1. Install it

# Debian / Ubuntu
sudo apt install wireguard

# Fedora
sudo dnf install wireguard-tools

# Arch / CachyOS
sudo pacman -S wireguard-tools

Kernel modules ship with the kernel on all recent versions; the package only adds the wg and wg-quick tools.

2. Generate keys

Do this on each machine. Private keys never leave the host they belong to:

umask 077
wg genkey | tee privatekey | wg pubkey > publickey
cat privatekey publickey

Captura: la salida de wg genkey muestra dos claves base64 largas, una privada y otra pública.

3. The server config

Create /etc/wireguard/wg0.conf on the server:

[Interface]
Address = 10.7.0.1/24
ListenPort = 51820
PrivateKey = <server private key>

[Peer]
# laptop
PublicKey = <client public key>
AllowedIPs = 10.7.0.2/32

Bring it up and enable it at boot:

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

4. The client config

On the laptop, in /etc/wireguard/wg0.conf:

[Interface]
Address = 10.7.0.2/24
PrivateKey = <client private key>

[Peer]
PublicKey = <server public key>
Endpoint = server.example.com:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

Setting AllowedIPs = 0.0.0.0/0, ::/0 routes all traffic through the tunnel. Use 10.7.0.0/24 instead if you only want to reach the private network and keep normal browsing on your own connection.

5. Open the port and check the tunnel

# on the server firewall
sudo ufw allow 51820/udp

# on either side
sudo wg show

Once the client connects you will see a latest handshake line and running transfer counters. If that line never appears, the UDP port is blocked or the keys do not match.

6. Full tunnel: forward and NAT

To send all client traffic out through the server, enable forwarding:

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

Then add NAT to the [Interface] block with a PostUp/PostDown pair — for example, on a server whose uplink is eth0:

PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

7. Adding more peers

Each new device gets its own key pair and its own [Peer] block on the server, with a unique AllowedIPs = 10.7.0.N/32. That is the whole “user management” story: no database, no expiry, just a key per device. Revoke one by deleting its block and reloading:

sudo wg syncconf wg0 <(wg-quick strip wg0)

Split tunnel or full tunnel

The AllowedIPs line on the client decides this. Set it to 0.0.0.0/0, ::/0 and every packet goes through the tunnel — a full tunnel, good on untrusted Wi-Fi but slower and it sends even your local traffic out. Set it to 10.7.0.0/24 and only traffic to the private network is tunnelled while everything else uses your normal connection — a split tunnel, which is usually what you want on a laptop.

Testing that it really works

# on the client, after wg-quick up
ping -c3 10.7.0.1        # reach the server's tunnel IP
curl ifconfig.me         # with a full tunnel, this shows the server's IP
sudo wg show             # latest handshake and transfer counters

If the ping works but the IP check does not change, you have a split tunnel — expected. If neither works, the UDP port is blocked or the keys are mismatched.

Troubleshooting

  • No handshake. The most common cause is a firewall dropping UDP 51820; open it on the server.
  • Handshake but no traffic. Check AllowedIPs on both ends — a mismatch silently drops packets.
  • Works, then dies. A changing client IP behind NAT needs PersistentKeepalive = 25, which the client config above already sets.

What changes for you

The reason to care is not only privacy on public Wi-Fi. A WireGuard tunnel turns a scattered set of machines into one flat private network you can reach from anywhere, with a config you can back up in a text file and reproduce in minutes. If you have ever fought an OpenVPN .ovpn profile you did not write, the difference is obvious the first time you read a working wg0.conf end to end.

Sources




Leave a Reply

Your email address will not be published. Required fields are marked *