WireGuard VPN Policy Routing on OpenWRT
Tested on GL-AX1800 with OpenWRT 21.02
Install vpn-policy-routing plugin
- Go to OpenWRT -> System -> Software
- Update lists
- Install
vpn-policy-routing
andluci-app-vpn-policy-routing
- Refresh the page. There will be a new
VPN
tab on header
Add Firewall zone
- Go to
Network
->Firewall
- Under
Zones
section, click theAdd
button - I use
WGZONE
as the name. - Choose
accept
forOutput
- Choose
drop
forInput
andForward
- Check
Masquerading
andMSS clamping
- Choose
WAN
forAllowed forward to destination zones
- Choose
LAN
andGUEST
(if any or if you want) forAllow forward from source zones
Add WireGuard interface
- Prepare your WireGuard connection information
- Go to
Network
->Interfaces
- Click
Add new interface
- In the popup dialog, choose
WireGuard VPN
asProtocol
- On
General Settings
tab, enterPrivate Key
andIP Address
- On
Advanced Settings
tab, checkForce Link
- If you want to use the DNS from your VPN service provider, uncheck
use DNS servers advertised by peer
, and enter the DNS IP provided manually - On
Firewall Settings
, chooseWGZONE
- On
Peers
tab, clickAdd peer
. EnterPublic Key
,Preshared Key
(if any),Endpoint Host
andEndpoint Port
. Enter0.0.0.0/0
forAllowed IPs
. Do not checkRoute Allowed IPs
. - Repeats the steps if you want any more VPN connections.
Config on linux kernal
- Setup SSH in
System
->Administration
->SSH Access
if needed - SSH to
OpenWRT
- Type
ifconfig
and find out the WireGuard interface name - Modify
/etc/sysctl.d/90-wireguard.conf
(this file does not exist originally). For other hardware models there may not be/etc/sysctl.d/
, modify on/etc/sysctl.conf
- Put
net.ipv4.conf.WIREGUARD_INTERFACE_NAME.rp_filter=2
in the file. Replace
with your WireGuard interface name found in the previous step. Each WireGuard interface requires its own line.WIREGUARD_INTERFACE_NAME
- Save the file
- Reboot router
Setup policies
- Go to
VPN
->VPN Policy Routing
- Click
Enable
- Configure according to the official guide https://docs.openwrt.melmac.net/vpn-policy-routing