Skip to content

AniQ.eu – Tutorials for Tinkerers: Linux, VPN, OpenWRT & More.



Menu
  • Home
  • Blog
  • News
  • Categories
  • About
  • Contact
Menu

🔧 Installing WireGuard VPN Server on OpenWRT 24.x

Posted on May 18, 2025

Step 1: Install Required Packages

opkg update
opkg install wireguard luci-proto-wireguard luci-app-wireguard

Step 2: Generate Keys for the Server

umask 077  # Ensures the keys are created with correct permissions

# (Optional) Create WireGuard directory
mkdir -p /etc/wireguard
cd /etc/wireguard

# Generate server private key
wg genkey > server_private.key

# Generate server public key
cat server_private.key | wg pubkey > server_public.key

Step 3: Generate Keys for the Client

# Generate client private key
wg genkey > client_private.key

# Generate client public key
cat client_private.key | wg pubkey > client_public.key

Step 4: Configure the Network – /etc/config/network

config interface 'wg0'
option proto 'wireguard'
option private_key 'SERVER_PRIVATE_KEY' # Replace with your server’s private key
option listen_port '51820'
list addresses '10.8.0.1/24' # Server IP in the VPN tunnel

config wireguard_wg0
option public_key 'CLIENT_PUBLIC_KEY' # Replace with client's public key (e.g., from Windows)
option description 'Windows PC'
list allowed_ips '10.8.0.2/32' # Client's IP in the tunnel

Step 5: Configure the Windows Client (WireGuard App)

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

[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = YOUR_PUBLIC_IP:51820
AllowedIPs = 192.168.0.0/24 # Your home LAN network
PersistentKeepalive = 25

Step 6: Configure Firewall – /etc/config/firewall

config zone
option name 'vpn'
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'ACCEPT'
list network 'wg0'

config forwarding
option src 'vpn'
option dest 'lan'

config rule
option name 'Allow-WireGuard-Inbound'
option src 'wan'
option dest_port '51820'
option proto 'udp'
option target 'ACCEPT'

Step 7: Restart Network and Firewall

/etc/init.d/network restart
/etc/init.d/firewall restart

📌 NOTE:

Why can you access local devices but not browse the internet through the VPN?

Because:

  • Your WireGuard config allows routing to the LAN (e.g., 192.168.1.0/24), so you can reach devices at home.
  • But your client only routes specific subnets through the VPN (AllowedIPs = 192.168.1.0/24).
  • And your OpenWRT doesn’t do NAT/MASQUERADE, so traffic from VPN to internet is not translated to your public IP.

🌍 Want to appear on the internet as if you’re behind the OpenWRT router?

1. Modify the WireGuard Client Config:

Change AllowedIPs to:

AllowedIPs = 0.0.0.0/0

This means: “Route all internet traffic through the VPN.”

2. Enable NAT on OpenWRT

Run this command via SSH:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

⚠️ Replace eth0 with your actual WAN interface (commonly wan or eth1).
You can find it with:

ip route | grep default

3. (Optional) Make NAT Rule Persistent

Add to /etc/firewall.user:

# Allow NAT for WireGuard
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Save the file and restart the firewall:

/etc/init.d/firewall restart

4. Enable Forwarding from VPN to WAN

Make sure /etc/config/firewall contains:

config zone
option name 'vpn'
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'ACCEPT'
list network 'wg0'

config forwarding
option src 'vpn'
option dest 'wan'

✅ Result:

All your traffic will be routed through the VPN tunnel.
You’ll appear on the internet under your OpenWRT router’s IP address.

Share files with each other: pairdrop.aniq.eu, upload.aniq.eu

Leave a Reply Cancel reply

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

Recent Posts

  • 🔧 Installing WireGuard VPN Server on OpenWRT 24.x
  • phpMyAdmin Installation Guide for Debian 12
  • Installation and configuration of a web server with PHP, MySQL, and HTTPS (SSL) support using Let’s Encrypt. (Debian 12)
  • Welcome to AniQ.eu – Where IT Curiosity Comes to Life

Categories

  • ℹ️ General information
  • 🌐Networking
  • 💻 Web Server Setup
pairdrop.aniq.eu
upload.aniq.eu
Log in

DID YOU KNOW?

In 1969, humans first walked on the Moon during NASA's Apollo 11 mission. Neil Armstrong’s iconic words, “That’s one small step for man, one giant leap for mankind,” marked a new era in space exploration.

A LOOK INTO THE FUTURE

By 2035, autonomous vehicles are expected to make up over 25% of all road traffic. With AI-driven transport systems, the world is moving closer to safer, more efficient, and eco-friendly mobility.

HISTORY MEETS INNOVATION

The Library of Alexandria, once the largest and most significant library of the ancient world, inspired the creation of modern digital archives. Today, entire civilizations’ knowledge can be stored on a single chip smaller than a fingernail.

©2025 AniQ.eu – Tutorials for Tinkerers: Linux, VPN, OpenWRT & More. | Design: Newspaperly WordPress Theme