Install and Secure WireGuard VPN on Ubuntu 24.04 LTS (DNS, Kill Switch, Mobile QR Codes)

Overview

This step-by-step guide shows you how to install and secure a WireGuard VPN on Ubuntu 24.04 LTS. You will enable IP forwarding, add NAT, configure DNS, generate mobile-friendly QR codes, and set up a client kill switch on Linux. WireGuard is fast, modern, and simple—perfect for remote access, privacy, and self-hosted lab networks.

What you need

You need an Ubuntu 24.04 server with sudo, a public IP (or port-forwarded UDP 51820), and a basic understanding of the terminal. Replace interface names like eth0 with your actual WAN NIC (for example, ens3 or enp1s0), and replace placeholders like SERVER_PUBLIC_IP with your values.

1) Install WireGuard and tools

Update the package index, then install WireGuard, UFW (if you use it), and a small utility to generate QR codes for mobile clients.

sudo apt update
sudo apt install -y wireguard qrencode ufw

2) Generate server keys

Create a private and public key for the server. The private key must stay secret and readable only by root.

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

Copy the printed keys to use in the configuration files below. Do not share the private key with anyone.

3) Enable IP forwarding

Turn on IPv4 and IPv6 forwarding so the server can route traffic from clients to the Internet.

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

4) Create the WireGuard server config

Create /etc/wireguard/wg0.conf. Replace SERVER_PRIVATE_KEY with the contents of /etc/wireguard/server.key, and replace eth0 with your external interface.

sudo nano /etc/wireguard/wg0.conf
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
SaveConfig = true
MTU = 1420

# NAT and forwarding rules (iptables-nft works on Ubuntu 24.04)
# Replace eth0 with your WAN NIC (e.g., ens3)
PostUp   = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; \
           iptables -A FORWARD -i %i -j ACCEPT; \
           iptables -A FORWARD -o %i -m state --state RELATED,ESTABLISHED -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; \
           iptables -D FORWARD -i %i -j ACCEPT; \
           iptables -D FORWARD -o %i -m state --state RELATED,ESTABLISHED -j ACCEPT

Allow UDP 51820 on the firewall, then start and enable the service.

sudo ufw allow 51820/udp
sudo systemctl enable --now wg-quick@wg0
sudo wg

5) Add your first peer (client)

Generate a client keypair on the server (safe for a single user or a small team). Each client must have a unique address.

cd /root
umask 077
wg genkey | tee client1.key | wg pubkey > client1.pub
CLIENT_PRIV=$(cat client1.key)
CLIENT_PUB=$(cat client1.pub)
SERVER_PUB=$(cat /etc/wireguard/server.pub)

Append a [Peer] block for the client to /etc/wireguard/wg0.conf. This line assigns 10.8.0.2/32 to the client and restricts it tightly.

sudo bash -c 'cat >> /etc/wireguard/wg0.conf' << 'EOF'
[Peer]
# client1
PublicKey = REPLACE_WITH_CLIENT1_PUBLIC_KEY
AllowedIPs = 10.8.0.2/32
EOF

Apply the change without downtime:

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

6) Build the client config (with DNS)

Create a client configuration file that routes all traffic through the VPN and uses secure DNS. Replace SERVER_PUBLIC_IP or domain and keep port 51820/udp open. Linux, macOS, Windows, iOS, and Android all accept this format.

cat > client1.conf << EOF
[Interface]
Address = 10.8.0.2/32
PrivateKey = CLIENT1_PRIVATE_KEY
DNS = 1.1.1.1, 9.9.9.9
MTU = 1420

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

7) Show a QR code for mobile apps

Install the WireGuard app on iOS or Android, then scan this QR code displayed in your terminal to import the profile instantly.

qrencode -t ansiutf8 < client1.conf

If your terminal does not render Unicode well, save a PNG with qrencode -o client1.png < client1.conf and open it locally.

8) Optional: Linux client kill switch

A kill switch blocks all traffic outside the VPN. The rules below let only the WireGuard handshake to the server bypass the tunnel. Add these to the client’s client1.conf, replacing SERVER_PUBLIC_IP if you use an IP and not a domain.

# Allow the handshake, then drop everything not via wg
PreUp = iptables -I OUTPUT -d SERVER_PUBLIC_IP -p udp --dport 51820 -j ACCEPT
PreUp = iptables -I OUTPUT ! -o %i -m addrtype ! --dst-type LOCAL -j DROP
PreUp = ip6tables -I OUTPUT ! -o %i -m addrtype ! --dst-type LOCAL -j DROP
PostDown = iptables -D OUTPUT ! -o %i -m addrtype ! --dst-type LOCAL -j DROP
PostDown = ip6tables -D OUTPUT ! -o %i -m addrtype ! --dst-type LOCAL -j DROP
PostDown = iptables -D OUTPUT -d SERVER_PUBLIC_IP -p udp --dport 51820 -j ACCEPT

On Android, you can also enable “Block connections without VPN” in system settings after importing the profile.

9) Test the tunnel

Connect your client and verify that your public IP changes to the server. You should also be able to reach private services across the tunnel.

# On the client
wg
curl -s https://ifconfig.me
dig +short txt ch whoami.cloudflare @1.1.1.1

Troubleshooting tips

If the client does not connect, verify that UDP 51820 is open and forwarded, confirm your external interface name in PostUp/PostDown, and ensure AllowedIPs on the server exactly match each client’s single /32 address. Lower MTU (e.g., 1280) if you observe stalls, especially behind cellular or PPPoE links. If your provider uses CGNAT and you cannot forward UDP, host the server on a VPS with a public IP.

Security and maintenance

Rotate keys periodically, remove unused peers, and keep Ubuntu updated. Use strong DNS resolvers or your own recursive resolver for privacy. For teams, restrict each peer with precise AllowedIPs and consider splitting traffic by adding only the subnets you need. Monitor sudo wg output to audit connected peers and data transferred.

You now have a modern, efficient WireGuard VPN on Ubuntu 24.04 with DNS, mobile QR onboarding, and an optional kill switch. This setup is fast enough for home labs and secure enough for remote teams.

How to Install and Secure WireGuard VPN on Ubuntu 24.04 (IPv6, UFW, and Mobile QR Codes)

Overview

WireGuard is a modern VPN that is fast, secure, and simple to manage. In this step-by-step guide, you will install a WireGuard server on Ubuntu 24.04 LTS, enable IPv4/IPv6 routing, lock it down with UFW firewall, and create a mobile-friendly client using a QR code. This setup is ideal for remote access, secure public Wi‑Fi, and self-hosted lab environments.

Prerequisites

You need an Ubuntu 24.04 server (root or sudo), a public IP or DNS record pointing to your server, and one open UDP port (default: 51820). Update your system and note the name of your Internet-facing interface (e.g., eth0 or ens3).

1) Install WireGuard and tools

Install core packages and utilities used for key generation and QR export.

sudo apt update && sudo apt -y install wireguard qrencode resolvconf

2) Enable IP forwarding (IPv4 and IPv6)

Allow the server to route traffic from VPN clients to the Internet. Create a sysctl drop-in so the setting persists across reboots.

sudo tee /etc/sysctl.d/99-wireguard-routing.conf >/dev/null <<'EOF'
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
EOF
sudo sysctl --system

3) Generate server keys

WireGuard uses public-key cryptography. Generate a private key, derive the public key, and keep the private key secret.

umask 077
wg genkey | tee /etc/wireguard/server.key | wg pubkey | tee /etc/wireguard/server.pub
SERVER_PRIV=$(cat /etc/wireguard/server.key)

4) Create the server interface configuration

In this example, clients will use the subnets 10.8.0.0/24 (IPv4) and fd86:ea04:1111::/64 (IPv6). Replace eth0 with your real outbound interface. PostUp/PostDown rules enable NAT and forwarding for both stacks.

sudo tee /etc/wireguard/wg0.conf >/dev/null <<'EOF'
[Interface]
Address = 10.8.0.1/24, fd86:ea04:1111::1/64
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
# NAT and forwarding for IPv4/IPv6
PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; \
         iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; \
         ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; \
         ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -A FORWARD -o %i -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; \
           iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; \
           ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; \
           ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -D FORWARD -o %i -j ACCEPT
SaveConfig = false
EOF
sudo sed -i "s|SERVER_PRIVATE_KEY|$SERVER_PRIV|" /etc/wireguard/wg0.conf

If your server uses another outbound interface name, replace eth0 in PostUp/PostDown accordingly. If you prefer nftables, you can translate these rules to nft syntax.

5) Open the firewall

Allow UDP 51820 so peers can reach your VPN. If you use UFW, run:

sudo ufw allow 51820/udp
sudo ufw status verbose

6) Start WireGuard and enable on boot

The wg-quick helper reads the configuration and brings up the interface. Enable the service to auto-start on reboot.

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

7) Create your first client (peer)

Generate keys for a client, define which subnets to route through the tunnel (0.0.0.0/0 and ::/0 for full-tunnel), and set DNS to prevent leaks. Replace vpn.example.com with your server’s public IP or domain. PersistentKeepalive helps mobile devices behind NATs maintain connectivity.

umask 077
wg genkey | tee ~/alice.key | wg pubkey | tee ~/alice.pub
ALICE_PRIV=$(cat ~/alice.key)
ALICE_PUB=$(cat ~/alice.pub)
SERVER_PUB=$(cat /etc/wireguard/server.pub)
SERVER_ENDPOINT="vpn.example.com:51820"

Add the client as a peer on the server and assign an IP:

sudo tee -a /etc/wireguard/wg0.conf >/dev/null <<EOF
[Peer]
# Alice
PublicKey = $ALICE_PUB
AllowedIPs = 10.8.0.2/32, fd86:ea04:1111::2/128
EOF
sudo systemctl restart wg-quick@wg0
sudo wg show

Build the client configuration file:

cat > ~/alice.conf <<EOF
[Interface]
PrivateKey = $ALICE_PRIV
Address = 10.8.0.2/32, fd86:ea04:1111::2/128
DNS = 1.1.1.1, 2606:4700:4700::1111

[Peer]
PublicKey = $SERVER_PUB
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = $SERVER_ENDPOINT
PersistentKeepalive = 25
EOF

Tip: For privacy, you can run a resolver like Unbound on the server and set DNS = 10.8.0.1, fd86:ea04:1111::1.

8) Import on mobile via QR code

The WireGuard apps for Android and iOS can import a profile from a QR code. Print it in the terminal and scan it with the app.

qrencode -t ansiutf8 < ~/alice.conf

Alternatively, transfer the file securely and import it in the desktop or mobile WireGuard client.

9) Test your connection

Connect the client and verify your public IP changes. You can use curl ifconfig.io or any IP check site. Also test DNS and IPv6.

# On the client after connecting
curl -4 ifconfig.io
curl -6 ifconfig.io
nslookup example.org
ping -c 3 10.8.0.1

Troubleshooting

If the interface fails to start, check for typos in wg0.conf and ensure the outbound interface name is correct. Review logs with: sudo journalctl -u wg-quick@wg0 -e. If clients connect but have no Internet, verify IP forwarding (sysctl), NAT rules (PostUp), and that UDP 51820 is open. For DNS leaks or resolution failures, confirm the DNS entries in the client and that your resolver is reachable through the tunnel.

Security Tips

Use a non-default port if your ISP is restrictive, limit SSH access with UFW and key-based auth, keep the kernel and packages updated, and remove peers you no longer need. Consider enabling automatic security updates: sudo apt install unattended-upgrades.

You now have a fast, dual-stack WireGuard VPN on Ubuntu 24.04 with clean routing, firewall rules, and mobile-friendly onboarding via QR codes.

3.

Deploy a Private WireGuard VPN with Docker Compose (QR Codes for Mobile)

Why this guide

WireGuard is a modern VPN that is fast, secure, and simple to manage. Running it in Docker keeps your host clean, makes upgrades trivial, and allows you to back up your configuration as plain files. In this tutorial, you will deploy a production-ready WireGuard VPN with Docker Compose on an Ubuntu server, generate QR codes for easy mobile onboarding, and enable best-practice settings like IPv6 forwarding and DNS control.

Prerequisites

You need an Ubuntu 22.04/24.04 host (cloud VM or home server), a public DNS name for the server (e.g., vpn.example.com), and permission to forward UDP port 51820 on your router if you are behind NAT. You will also need a non-root user with sudo privileges. Windows or macOS clients can connect too, but we will demonstrate mobile setup using QR codes as it is the quickest way to get started.

Step 1 — Install Docker and Compose Plugin

Update your host, install Docker, and add your user to the docker group so you can run it without sudo.

sudo apt update && sudo apt -y upgrade
sudo apt -y install docker.io docker-compose-plugin
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
# Re-log or run: newgrp docker

Step 2 — Create the project structure

We will store compose files in /srv/wireguard and persist configuration in /srv/wireguard/config. The container will keep keys and peer files under this directory, which makes backups easy.

sudo mkdir -p /srv/wireguard/config
sudo chown -R $USER:$USER /srv/wireguard

Step 3 — Write docker-compose.yml

Create a Compose file that uses the well-maintained LinuxServer.io WireGuard image. Replace vpn.example.com with your DNS name and adjust timezone and peer names to your needs.

nano /srv/wireguard/docker-compose.yml

version: "3.8"
services:
  wireguard:
    image: lscr.io/linuxserver/wireguard:latest
    container_name: wireguard
    cap_add:
     - NET_ADMIN
     - SYS_MODULE
    ports:
     - 51820:51820/udp
    volumes:
     - ./config:/config
     - /lib/modules:/lib/modules:ro
    environment:
     - PUID=1000
     - PGID=1000
     - TZ=Etc/UTC
     - SERVERURL=vpn.example.com
     - SERVERPORT=51820
     - PEERS=phone,laptop
     - PEERDNS=1.1.1.1
     - INTERNAL_SUBNET=10.13.13.0
     - ALLOWEDIPS=0.0.0.0/0,::/0
    sysctls:
     - net.ipv4.conf.all.src_valid_mark=1
     - net.ipv4.ip_forward=1
     - net.ipv6.conf.all.forwarding=1
    restart: unless-stopped

A few notes: PEERS seeds the initial clients; you can add more later. ALLOWEDIPS controls routing. With 0.0.0.0/0,::/0 the client routes all traffic through the VPN (full tunnel). For a split tunnel to only reach the VPN subnet, set 10.13.13.0/24 (and optionally fd00:13:13::/64 if you use IPv6).

Step 4 — Open the firewall and forward the port

If UFW is enabled on the host, allow UDP 51820. Also forward UDP 51820 on your router to the server’s LAN IP. If you use a cloud VM, open the UDP port in your provider’s security group.

sudo ufw allow 51820/udp

Step 5 — Start the stack

Bring the container up and follow logs. On the first start, it creates server keys and peer files under config/.

cd /srv/wireguard
docker compose up -d
docker compose logs -f

Step 6 — Get peer configs and QR codes

The image includes helper scripts. To display a peer config and its QR code, run:

docker exec -it wireguard /app/show-peer phone

Install the WireGuard app on iOS or Android, tap the plus button, choose “Scan from QR code,” and scan the code from your terminal. For Windows/macOS/Linux clients, copy the text config printed by the command above into a file like phone.conf and import it in the WireGuard desktop app.

To add a new peer at any time, use:

docker exec -it wireguard /app/add-peer tablet

Step 7 — Verify the connection

Activate the tunnel on your device. From the server, confirm the handshake:

docker exec wireguard wg show

You should see latest handshake times and transfer counters increase as you pass traffic. From the client, visit https://ifconfig.io to confirm your public IP matches the server and that DNS resolves as expected.

Optional: Tune routing, MTU, and DNS

If you only want to reach resources on your home network and keep general browsing on the local internet, change ALLOWEDIPS in the peer config to the private ranges you care about (for example, 10.13.13.0/24,192.168.1.0/24). For mobile networks with strict NAT, enable a keepalive in the peer config by adding PersistentKeepalive = 25. If you notice slow speeds, set MTU = 1280 in the peer config to avoid fragmentation on cellular carriers.

For ad blocking, set PEERDNS to your Pi-hole or AdGuard Home address reachable through the tunnel, e.g., 10.13.13.2. You can also use privacy resolvers like 1.1.1.1 or 9.9.9.9.

Backups and updates

The critical state lives in /srv/wireguard/config. Back it up regularly with your favorite tool (rsync, Restic, Borg). To upgrade safely, pull the new image and recreate the container; your config remains intact.

cd /srv/wireguard
docker compose pull
docker compose up -d

Troubleshooting

No handshake? Verify the UDP port forward and make sure your DNS record points to the right public IP. On mobile networks behind Carrier Grade NAT, incoming connections may be blocked—host the server on a cloud VM or use a home ISP with a public IP. If the tunnel connects but no traffic flows, confirm IP forwarding is enabled (the Compose file includes sysctls) and that ALLOWEDIPS is correct on both ends. For double NAT routers, enable a full-cone/endpoint-independent NAT if available, or use an alternate UDP port like 51821.

You are done

With Docker Compose and WireGuard, you now have a lightweight, fast VPN that you can maintain in minutes. Add peers with one command, scan a QR code on your phone, and enjoy a private, encrypted tunnel wherever you are. Keep your system updated, back up the config folder, and you will have a reliable VPN for the long run.

WireGuard on Ubuntu 24.04: A Zero‑Trust VPN Setup with Windows and Mobile Clients

Overview

WireGuard is a modern VPN protocol that is fast, secure, and simple to deploy. In this tutorial, you will build a production-ready WireGuard server on Ubuntu 24.04 and connect Windows and mobile clients. You will configure routing, firewall rules, auto-start, and testing. The guide uses clear steps and SEO-friendly terms to help you go from zero to a working zero-trust VPN in minutes.

Prerequisites

You need an Ubuntu 24.04 server (cloud VPS or on-prem) with a public IP, sudo access, and UDP port 51820 open on any external firewall. If the server is behind a home router, forward UDP 51820 to the server’s LAN address. For clients, you need a Windows 10/11 PC and an Android or iOS device.

Step 1: Install WireGuard on Ubuntu 24.04

Update packages and install WireGuard tools:
sudo apt update && sudo apt install -y wireguard qrencode

Create a configuration directory and restrict permissions:
sudo mkdir -p /etc/wireguard && sudo chmod 700 /etc/wireguard

Step 2: Generate keys and base server config

Generate the server keypair:
cd /etc/wireguard
sudo wg genkey | sudo tee server_private.key | sudo wg pubkey | sudo tee server_public.key
sudo chmod 600 server_private.key

Set your VPN subnet and interface variables (eth0 is common on cloud VMs; adjust if yours differs):
export WG_IFACE=wg0
export WG_SUBNET=10.7.0.0/24
export SERVER_ADDR=10.7.0.1/24
export WAN_IFACE=eth0

Create the server configuration file:
sudo bash -c 'cat >/etc/wireguard/wg0.conf' <<EOF
[Interface]
Address = 10.7.0.1/24
ListenPort = 51820
PrivateKey = $(cat /etc/wireguard/server_private.key)
# Accept forwarding and NAT to the Internet
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o ${WAN_IFACE} -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o ${WAN_IFACE} -j MASQUERADE
EOF'

Step 3: Enable IP forwarding and open the port

Enable IPv4 forwarding persistently:
echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/99-wireguard.conf
sudo sysctl --system

If you use UFW, allow the WireGuard port:
sudo ufw allow 51820/udp

Start and enable the VPN interface:
sudo systemctl enable --now wg-quick@wg0

Check status and listen port:
sudo wg show

Step 4: Add a Windows client

On the server, generate a keypair for your Windows PC (you can also generate on the PC inside the app):
sudo wg genkey | sudo tee win_private.key | sudo wg pubkey | sudo tee win_public.key

Add the Windows peer to the server:
sudo bash -c 'cat >>/etc/wireguard/wg0.conf' <<EOF
[Peer]
PublicKey = $(cat /etc/wireguard/win_public.key)
AllowedIPs = 10.7.0.2/32
EOF'

Then restart the interface:
sudo systemctl restart wg-quick@wg0

On Windows, install the WireGuard app from the official site or Microsoft Store. Create a new tunnel with this configuration (replace placeholders):
[Interface]
PrivateKey = <win_private_key>
Address = 10.7.0.2/32
DNS = 1.1.1.1

[Peer]
PublicKey = <server_public_key>
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = <server_public_ip>:51820
PersistentKeepalive = 25

Copy values:
<server_public_key> is the content of /etc/wireguard/server_public.key.
<win_private_key> is the content of win_private.key if you generated it on the server, otherwise use the private key generated by the Windows app.
AllowedIPs set to 0.0.0.0/0, ::/0 routes all traffic through the VPN (full tunnel). For split tunnel, use 10.7.0.0/24 only.

Step 5: Add a mobile client (Android/iOS)

On the phone, install the WireGuard app. Creating keys on the device is the most secure method: add a new tunnel, let the app generate keys, and copy the public key.

Add the mobile peer on the server (replace with the phone’s public key and desired IP):
sudo bash -c 'cat >>/etc/wireguard/wg0.conf' <<EOF
[Peer]
PublicKey = <mobile_public_key>
AllowedIPs = 10.7.0.3/32
EOF'
sudo systemctl restart wg-quick@wg0

On the mobile app, create or import a config like this (adjust placeholders):
[Interface]
PrivateKey = <mobile_private_key>
Address = 10.7.0.3/32
DNS = 1.1.1.1

[Peer]
PublicKey = <server_public_key>
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = <server_public_ip>:51820
PersistentKeepalive = 25

Optional: if you prefer generating the mobile config on the server and scanning a QR code, create a file (for example /etc/wireguard/mobile1.conf) with the contents above and show a QR in the terminal:
sudo qrencode -t ansiutf8 < /etc/wireguard/mobile1.conf

Step 6: Auto-start, verify, and test

Ensure the interface starts on boot:
sudo systemctl enable wg-quick@wg0

Verify that peers handshaked and received IPs:
sudo wg show

Test connectivity from a client: open a browser and check your public IP (it should show the server’s IP if using a full tunnel). Also, ping the server’s VPN IP:
ping 10.7.0.1

Troubleshooting quick wins

No handshake? Confirm UDP 51820 is open and reachable. Use:
sudo ss -ulpn | grep 51820 on the server to see if it is listening, and sudo tcpdump -ni any udp port 51820 to check if packets arrive.

Wrong interface name? Replace eth0 with your actual outbound interface (check with ip route get 1.1.1.1). Update PostUp/PostDown accordingly and restart the service.

Double NAT issues? Set PersistentKeepalive = 25 on clients and ensure router port forwarding is correct.

Can’t access the Internet from the VPN? Confirm IPv4 forwarding is enabled and that NAT rules exist (see iptables -t nat -S). Also verify AllowedIPs values on both sides.

Security and best practices

Rotate keys periodically and remove stale peers from wg0.conf. Keep Ubuntu and WireGuard updated. Use strong SSH hygiene on the server and restrict management access by IP if possible. For compliance-driven environments, log changes to /etc/wireguard with version control (without committing private keys).

You now have a fast, modern WireGuard VPN on Ubuntu 24.04 with Windows and mobile clients. This layout is minimal yet production-ready and can scale by adding more peers with unique /32 addresses inside the same VPN subnet.

3.

How to Build a Zero-Config Mesh VPN with Tailscale for Secure Remote Access

Overview

Tired of port forwarding, dynamic DNS, and brittle VPN configs? Tailscale gives you a zero-config mesh VPN built on WireGuard, letting your devices talk to each other securely from anywhere. In this step-by-step guide, you will install Tailscale on Linux, Windows, and macOS, enable MagicDNS, set up an exit node, publish LAN subnets, and lock everything down with access controls. By the end, you will have a private, encrypted network for your home lab or remote team that takes minutes to deploy and scales without hassle.

Prerequisites

You need a Tailscale account (Google, Microsoft, GitHub, or email sign-in), admin access to your devices, and a stable internet connection. For subnet routing and exit nodes, a Linux or always-on device is recommended. Enable multi-factor authentication in your identity provider for best security.

Step 1: Create Your Tailnet

Go to the Tailscale website and sign in to create your tailnet. This is your private network. Open the Admin Console and confirm your tailnet name. Under Settings, enable device approvals if you want manual approval before new devices join. This is useful for production and shared environments.

Step 2: Install Tailscale

Linux (Debian/Ubuntu)
Run:
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up
When prompted, sign in to link the device. If your distro uses a service, ensure tailscaled is running.

Linux (Fedora/RHEL derivatives)
Install and start:
sudo dnf install tailscale -y
sudo systemctl enable --now tailscaled
sudo tailscale up

Windows
Download the Windows client from Tailscale, install it, and sign in. The client will assign a 100.x Tailscale IP and show your hostname in the Admin Console.

macOS
Install the app from the Mac App Store or from Tailscale’s website. Sign in to connect the Mac to your tailnet.

iOS/Android
Install the mobile app and sign in. You can toggle the VPN on/off and optionally route all traffic through an exit node.

Step 3: Turn On MagicDNS (Human-Friendly Names)

In the Admin Console, open Settings → DNS and enable MagicDNS. This lets you reach devices by name, for example builder.tailnet-name.ts.net, instead of by 100.x IPs. Keep “Override local DNS” enabled on clients so name resolution just works across platforms.

Step 4: Enable Tailscale SSH (Passwordless, Keyless)

In Settings → Tailscale SSH, enable it for your tailnet. On servers, run:
sudo tailscale up --ssh
You can now SSH between devices using identity-based auth, e.g.:
ssh ubuntu@server-name
Access is controlled by the tailnet policy (ACLs) rather than managing per-host SSH keys.

Step 5: Use an Exit Node (Full-Tunnel Internet)

An exit node routes all internet traffic from a device through a trusted peer (great for coffee shops and travel). On the machine that will be the exit node, run:
sudo tailscale up --advertise-exit-node
In the Admin Console, approve the exit node. On the client, open the Tailscale app and choose “Use exit node” → select your device. Optionally enable “Allow LAN access” to still reach your local network while tunneling the internet.

Step 6: Publish Your LAN with a Subnet Router

A subnet router lets remote devices reach a private LAN (e.g., 192.168.1.0/24) through Tailscale. On a Linux host connected to that LAN, enable IP forwarding:
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv6.conf.all.forwarding=1
Persist these settings in /etc/sysctl.d/99-tailscale.conf. Then advertise routes:
sudo tailscale up --advertise-routes=192.168.1.0/24
In the Admin Console → Machines, approve the advertised routes. Clients can now access printers, NAS devices, and servers on that LAN using IP or hostnames (with your DNS). If needed, add --snat=false to preserve client IPs for upstream firewall logs.

Step 7: Lock It Down with ACLs and Tags

Open the Admin Console → Access Controls and edit the policy. Use groups and tags to define who can reach what. Example: allow helpdesk to RDP to Windows servers, and engineers to SSH into Linux hosts. A minimal snippet could look like:
{ "groups": { "group:helpdesk": ["[email protected]"] }, "tagOwners": { "tag:server": ["group:helpdesk", "group:eng"] }, "acls": [ { "action": "accept", "src": ["group:helpdesk"], "dst": ["tag:server:3389"] }, { "action": "accept", "src": ["group:eng"], "dst": ["tag:server:22"] } ] }
Apply tags on devices by running:
sudo tailscale up --advertise-tags=tag:server
Only tagged and authorized devices will accept those connections.

Step 8: Headless and Auto-Join with Auth Keys

For servers and containers, create a reusable or short-lived auth key in the Admin Console → Keys. On the device, run:
sudo tailscale up --authkey=tskey-abcdef --hostname=ci-runner-01 --advertise-tags=tag:server
Use ephemeral keys for throwaway CI agents, and rotate long-lived keys on a schedule. You can also inject TS_AUTHKEY as an environment variable in Docker or systemd units.

Step 9: Troubleshooting Essentials

If a device looks offline, first check the local service:
sudo systemctl status tailscaled (Linux). Then test reachability:
tailscale status
tailscale ping device-name
tailscale netcheck
Ensure outbound UDP 41641 is open; Tailscale falls back to relays (DERP) if direct NAT traversal fails. On Linux firewalls, allow UDP/41641 and established/related traffic. If routes are not working, confirm “Accept routes” is enabled and IP forwarding is on. For deep diagnostics, run tailscale bugreport and review logs in the Admin Console.

Security Best Practices

Require SSO and MFA for all users. Enable device approval and machine key expiry. Use groups and tags to enforce least privilege in ACLs. Restrict exit node usage to trusted admins. Regularly prune unused devices, rotate auth keys, and audit connections in the logs. Avoid exposing services publicly; instead, use MagicDNS, Tailscale SSH, or consider Tailscale Funnel selectively with HTTPS for public endpoints.

What You Can Do Next

With your mesh VPN live, map drives to a NAS over the tailnet, RDP into Windows servers from anywhere, tunnel VS Code SSH to a remote lab, or back up endpoints securely to a central repository. Tailscale scales from a weekend project to a production-ready fabric without the usual VPN pain. Most changes are policy-driven, so you can iterate quickly and keep operations clean.

How to Set Up and Secure a WireGuard VPN Server on Ubuntu 22.04

Introduction

Virtual Private Networks (VPNs) are essential for securing internet connections, especially when accessing confidential data or bypassing geo-restrictions. WireGuard is a modern, fast, and secure VPN protocol that has gained popularity for its simplicity and performance. In this tutorial, you will learn how to install, configure, and secure a WireGuard VPN server on Ubuntu 22.04.

Prerequisites

Before you begin, ensure that you have a server running Ubuntu 22.04 with root or sudo access. You will also need a client device (Windows, Linux, or mobile) to connect to the VPN. Make sure your system is up to date by running sudo apt update && sudo apt upgrade.

Step 1: Install WireGuard

WireGuard is included in the default Ubuntu repositories. To install it, open your terminal and run the following command:

sudo apt install wireguard

This will install both the server and client components. Once the installation is complete, you can proceed to generate the keys required for your VPN setup.

Step 2: Generate Server and Client Keys

WireGuard uses public and private keys for authentication. Generate the server keys with the following commands:

umask 077
wg genkey | tee server_private.key | wg pubkey > server_public.key

Repeat the process on your client machine to generate a separate pair of keys (client_private.key and client_public.key).

Step 3: Configure the WireGuard Server

Create the main configuration file for WireGuard on the server:

sudo nano /etc/wireguard/wg0.conf

Add the following content, replacing the keys and IP addresses accordingly:

[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = <server_private.key contents>

[Peer]
PublicKey = <client_public.key contents>
AllowedIPs = 10.0.0.2/32

Save and close the file. The AllowedIPs option specifies which IP addresses are allowed to be routed through the VPN.

Step 4: Enable IP Forwarding and Firewall Rules

To allow traffic to flow between the VPN and the internet, enable IP forwarding:

sudo sysctl -w net.ipv4.ip_forward=1

Make this change permanent by editing /etc/sysctl.conf and un-commenting or adding net.ipv4.ip_forward=1.

Adjust your firewall to allow WireGuard traffic:

sudo ufw allow 51820/udp

Step 5: Start and Enable WireGuard

To start the WireGuard service and ensure it runs on boot, use:

sudo systemctl start [email protected]
sudo systemctl enable [email protected]

Verify the status with sudo systemctl status [email protected].

Step 6: Configure the Client

On your client device, create a configuration file (e.g., wg0-client.conf):

[Interface]
PrivateKey = <client_private.key contents>
Address = 10.0.0.2/24

[Peer]
PublicKey = <server_public.key contents>
Endpoint = <your_server_ip>:51820
AllowedIPs = 0.0.0.0/0

Install the WireGuard client on your device and import this configuration. Connect to test the VPN setup.

Security Tips

For enhanced security, use strong keys and restrict SSH to trusted IPs only. Regularly monitor your server logs and keep your system updated. Consider using fail2ban for added protection against brute-force attacks.

Conclusion

WireGuard offers a fast and secure VPN solution for modern networks. By following this guide, you have set up and secured a WireGuard server on Ubuntu 22.04. This will help protect your data and maintain privacy when accessing the internet or corporate resources remotely.

3.

How to Set Up a Secure VPN with WireGuard on Ubuntu 20.04

Introduction

Setting up a Virtual Private Network (VPN) is crucial for enhancing your digital security and privacy. WireGuard is a modern VPN protocol that offers state-of-the-art cryptography and is easier to set up compared to older counterparts. This tutorial will guide you through installing and configuring WireGuard on a Ubuntu 20.04 server.

Step 1: Installing WireGuard

First, update your system's package index: sudo apt update Then install WireGuard using the following command: sudo apt install wireguard This command installs the WireGuard software and all necessary dependencies.

Step 2: Configuring WireGuard

WireGuard works by creating a network interface on each peer, identified by a private and public key pair. Start by generating these keys: wg genkey | tee privatekey | wg pubkey > publickey Ensure to secure the access to the private key: chmod 600 privatekey Next, create and edit the WireGuard configuration file: sudo nano /etc/wireguard/wg0.conf Replace 'wg0' with your desired interface name. Add the following configuration, replacing placeholders with actual values:

[Interface]
PrivateKey = <your-private-key>
Address = 10.0.0.1/24
ListenPort = 51820
SaveConfig = true
This configuration sets the VPN interface, listening port, and IP address.

Step 3: Starting WireGuard

Enable and start the WireGuard service with the following commands: sudo systemctl enable wg-quick@wg0 sudo systemctl start wg-quick@wg0 Replace 'wg0' with the name of your WireGuard interface. You can check the status to ensure it's running properly: sudo systemctl status wg-quick@wg0

Step 4: Configuring Firewall and Forwarding

It's important to configure the firewall to allow VPN traffic. If you’re using UFW, use the following commands: sudo ufw allow 51820/udp Also, enable IP forwarding to allow traffic to flow through the VPN: echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf sudo sysctl -p This updates your system's IP forwarding settings immediately.

Conclusion

You now have a functioning WireGuard VPN on your Ubuntu 20.04 server. WireGuard provides a secure and easy-to-manage VPN solution that is perfect for personal use or small businesses. Remember to regularly update your server and WireGuard to maintain security and performance.

3.

How to Set Up a Secure VPN with WireGuard on Ubuntu 20.04

Setting up a virtual private network (VPN) is crucial for enhancing your digital security and privacy, especially when you're on a public network. Today, we'll explore how to set up WireGuard, a simple yet powerful VPN solution, on Ubuntu 20.04. WireGuard offers better performance and a more straightforward setup process compared to older VPN protocols. Let’s dive into setting up WireGuard to secure your internet connection.

Step 1: Installing WireGuard

First, you need to install WireGuard on your Ubuntu system. Open your terminal and run the following commands to update your package list and install WireGuard: sudo apt update and sudo apt install wireguard. This will install the necessary WireGuard packages on your system.

Step 2: Configuring WireGuard

Once installed, you need to configure the WireGuard server and client. Start by generating a private and public key pair using the command: wg genkey | tee privatekey | wg pubkey > publickey. Keep these keys secure as they will be used to set up the server and client configuration files.

Create a new configuration file for your WireGuard server by typing sudo nano /etc/wireguard/wg0.conf in your terminal. Insert the following configuration details into the file, replacing your_server_public_key, your_client_public_key, and your_server_private_key with the appropriate keys:

[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = your_server_private_key
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
SaveConfig = true

[Peer]
PublicKey = your_client_public_key
AllowedIPs = 10.0.0.2/32

Step 3: Starting WireGuard

After configuring the server, enable and start the WireGuard service using the commands: sudo systemctl enable wg-quick@wg0 and sudo systemctl start wg-quick@wg0. These commands make sure that WireGuard starts automatically on boot and is currently running.

To ensure everything is set up correctly, use the command sudo wg to check the status of the WireGuard interface. If everything is configured correctly, you will see the interface details and the peer connection status.

Congratulations! You have successfully set up a secure VPN server using WireGuard on your Ubuntu 20.04 system. This setup not only enhances your network security but also ensures that your internet connection is private and encrypted.

3.

How to Set Up a Secure VPN with WireGuard on Ubuntu Server

Introduction: In the era of remote work and increased concerns for digital privacy, setting up a Virtual Private Network (VPN) has become more crucial than ever. WireGuard is a modern VPN protocol featuring high security and better performance compared to older protocols. This tutorial will guide you through the process of setting up WireGuard on an Ubuntu Server.

Prerequisites: Before starting, ensure you have the following: an Ubuntu Server (20.04 or later) with root access, a basic understanding of Linux commands, and a public IP address for your server.

Step 1: Install WireGuard

Firstly, you need to install WireGuard on your Ubuntu Server. Open your terminal and run the following commands:

sudo apt update
sudo apt install wireguard
These commands update your package list and install WireGuard.

Step 2: Configure WireGuard

After installation, you need to configure the VPN server settings. Start by generating the private and public keys:

cd /etc/wireguard/
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
Note the key outputs as you will need them later.

Create a new configuration file for your VPN server:

nano wg0.conf
In this file, input the following configuration, adjusting the IP addresses as necessary:
[Interface]
PrivateKey = [Your Server's Private Key]
Address = 10.200.200.1/24
ListenPort = 51820
SaveConfig = true

[Peer]
PublicKey = [Your Peer's Public Key]
AllowedIPs = 10.200.200.2/32
Replace "[Your Server's Private Key]" and "[Your Peer's Public Key]" with the appropriate keys you generated earlier.

Step 3: Enable and Start WireGuard

To enable and start the WireGuard service, use the following commands:

sudo systemctl enable [email protected]
sudo systemctl start [email protected]
This sets the WireGuard service to start at boot and runs it immediately.

Conclusion: You now have a basic WireGuard VPN set up on your Ubuntu Server. This setup provides a secure and private tunnel for your internet traffic. For further customization and security, consider adding firewall rules and configuring additional peers.

Note: Always ensure you comply with local laws and regulations when configuring network services like VPNs.

3.

How to Set Up a Secure Home Office VPN Using WireGuard on Ubuntu

Introduction

With the increasing need for remote work solutions, setting up a secure VPN has become a necessity for many professionals. In this tutorial, we will walk through the process of setting up a WireGuard VPN on an Ubuntu server. WireGuard is known for its simplicity and faster performance compared to other VPN protocols. This guide will help you establish a secure connection between your home and the office network.

Step 1: Installing WireGuard

First, you need to install WireGuard on your Ubuntu server. Open your terminal and run the following commands: sudo apt update and sudo apt install wireguard. These commands update your package list and install WireGuard, respectively.

Step 2: Configuring WireGuard

Once WireGuard is installed, the next step is to configure it. Begin by generating private and public keys using wg genkey | tee privatekey | wg pubkey > publickey. Keep these keys secure as they will be used to authenticate your connection.

Create a new configuration file for your WireGuard interface using sudo nano /etc/wireguard/wg0.conf. Replace 'wg0' with whatever you prefer for your interface name. In this file, input the following configuration, replacing placeholders with actual values:

[Interface]
PrivateKey = <your-private-key>
Address = 10.200.200.1/24
ListenPort = 51820
SaveConfig = true

[Peer]
PublicKey = <peer-public-key>
AllowedIPs = 10.200.200.2/32
Endpoint = <peer-ip-address>:51820
This sets up your server's VPN interface and specifies the client that can connect to it.

Step 3: Enabling the VPN

After configuring WireGuard, enable and start the VPN interface by running sudo wg-quick up wg0. To ensure WireGuard starts on boot, use sudo systemctl enable wg-quick@wg0.

Step 4: Configuring Firewall and Forwarding

For security and functionality, configure the UFW firewall to allow VPN traffic and enable IP forwarding. Run the following commands: sudo ufw allow 51820/udp and echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf followed by sudo sysctl -p.

Step 5: Setting Up a Client

On the client side, install WireGuard using the same installation steps. Generate keys for the client and set up a configuration file similar to the server's, but adjust the [Interface] and [Peer] sections to reflect the client's role. Transfer the client's public key to the server and vice versa.

Conclusion

You now have a secure, high-performance VPN set up with WireGuard on your Ubuntu server. This setup not only enhances your remote work capabilities but also ensures that your data remains secure during transmission between your home and office networks.

3.

How to Setup a Secure Home VPN Server

How to Setup a Secure Home VPN Server

In an era where data privacy is more important than ever, setting up your own VPN (Virtual Private Network) server at home is a great way to secure your internet traffic and protect sensitive information. In this guide, we’ll walk you through the process step-by-step, ensuring a seamless and secure setup.

Why Set Up a VPN at Home?

A VPN encrypts your internet traffic, making it nearly impossible for hackers or unauthorized users to intercept your data. While commercial VPNs are widely available, hosting your own VPN ensures complete control over your data and eliminates subscription fees.

Requirements

  • Reliable internet connection
  • A spare computer or Raspberry Pi
  • OpenVPN or WireGuard software
  • Static IP address or dynamic DNS service

Step 1: Install the VPN Software

Download and install OpenVPN or WireGuard on your server device. Both are free and open-source tools that provide robust security. Follow the installation instructions specific to your operating system (Windows, Linux, or macOS).

Step 2: Configure the VPN Server

Once installed, configure the server by generating encryption keys and setting up user profiles. For OpenVPN, use the EasyRSA tool to create certificates. If using WireGuard, generate public and private keys using the built-in key management tool.

Step 3: Port Forwarding

Access your router settings and forward the necessary ports (e.g., 1194 for OpenVPN or 51820 for WireGuard) to your VPN server's local IP address. This ensures that external devices can connect to your VPN.

Step 4: Set Up a Static IP or Dynamic DNS

To make your VPN accessible from anywhere, configure a static IP address or use a dynamic DNS service like No-IP or DuckDNS. This step links your VPN to a domain name or fixed address.

Step 5: Configure Client Devices

Download the corresponding VPN client software on your devices (PC, smartphone, tablet) and import the configuration file generated by your VPN server. Test the connection to ensure proper functionality.

Step 6: Enable Firewall and Security

Set up a firewall on your VPN server to block unauthorized access. Additionally, regularly update the software to patch any security vulnerabilities.

Conclusion

Setting up a home VPN server provides unparalleled security and control over your internet traffic. While the process may seem complex at first, following these steps ensures a smooth and secure setup. Take the time to secure your data today and enjoy the peace of mind that comes with it.

Visual Representation:

Home VPN


Popular Posts

Install Ollama and Open WebUI on Ubuntu 24.04 with NVIDIA GPU Acceleration (Step-by-Step)

Install Ollama + Open WebUI on Ubuntu 24.04 with NVIDIA GPU Acceleration (Step-by-Step)

Install a Local AI Chatbot on Ubuntu 24.04 with Ollama and Open WebUI (Step-by-Step)

Trending Now

Debian Adoption at CERN Signals Strong Momentum for Enterprise Linux

By the end of this article readers will understand the implications of CERN’s migration of 2,200 control systems to Debian 13, the performance enhancements in Firefox 155, and recent developments across several Linux distributions that affect system administration and user experience. Debian 13 Deployment at CERN: Scale and Significance The European Organization for Nuclear Research (CERN) has announced the migration of 2,200 of its control systems to Debian 13. This move represents one of the largest coordinated deployments of a Debian release in a scientific research environment. Control systems at CERN are responsible for monitoring and managing critical hardware, from accelerator components to detector subsystems. Their reliability hinges on a stable operating system with long‑term support, predictable update cycles, and a robust package ecosystem. Debian’s reputation for stability and its extensive testing process make it a natural fit for such mission‑critical workloads. Debia...