Wireguard + policy routing for specific device

Hi there,

Thanks to this forum I was able to setup wireguard and route all traffic through the interface.
Due to some challenges, I am now trying to assign only two laptops to work with the Wireguard interface and the rest continue working on the direct WAN PPPoE connection.
First, I unset the wireguard default routing using
uci set network.@wireguard_PS1[0].route_allowed_ips="0"
Then, I installed vpn policy routing and assigned one of the laptop's LAN IP. Also added static route and added Firewall rule for the laptops to forward the connection. But that doesn't seem to work. Could anyone help me please with this?

Details:

cat /etc/config/vpn-policy-routing

config vpn-policy-routing 'config'
	option verbosity '2'
	option strict_enforcement '1'
	option src_ipset '0'
	option dest_ipset '0'
	option resolver_ipset 'dnsmasq.ipset'
	option ipv6_enabled '0'
	list ignored_interface 'vpnserver wgserver'
	option boot_timeout '30'
	option iptables_rule_option 'append'
	option procd_reload_delay '1'
	option webui_sorting '1'
	list webui_supported_protocol 'tcp'
	list webui_supported_protocol 'udp'
	list webui_supported_protocol 'tcp udp'
	list webui_supported_protocol 'icmp'
	list webui_supported_protocol 'all'
	option webui_enable_column '1'
	option webui_protocol_column '1'
	option webui_chain_column '1'
	option webui_show_ignore_target '1'
	option enabled '1'
	option PS1_dscp '3'

config include
	option path '/etc/vpn-policy-routing.netflix.user'
	option enabled '0'

config include
	option path '/etc/vpn-policy-routing.aws.user'
	option enabled '0'

config policy
	option name 'Laptop2Wg'
	option src_addr '192.168.1.177'
	option interface 'PS1'
	option dest_addr '0.0.0.0'
	option proto 'tcp'
	option chain 'FORWARD'

Firewall details

cat /etc/config/firewall

config defaults
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'REJECT'
	option synflood_protect '1'

config zone
	option name 'lan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	option network 'lan'

config zone
	option name 'wan'
	option input 'REJECT'
	option output 'ACCEPT'
	option forward 'REJECT'
	option masq '1'
	option mtu_fix '1'
	option network 'wan6'

config rule
	option name 'Allow-DHCP-Renew'
	option src 'wan'
	option proto 'udp'
	option dest_port '68'
	option target 'ACCEPT'
	option family 'ipv4'

config rule
	option name 'Allow-Ping'
	option src 'wan'
	option proto 'icmp'
	option icmp_type 'echo-request'
	option family 'ipv4'
	option target 'ACCEPT'

config rule
	option name 'Allow-IGMP'
	option src 'wan'
	option proto 'igmp'
	option family 'ipv4'
	option target 'ACCEPT'

config rule
	option name 'Allow-DHCPv6'
	option src 'wan'
	option proto 'udp'
	option src_ip 'fc00::/6'
	option dest_ip 'fc00::/6'
	option dest_port '546'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-MLD'
	option src 'wan'
	option proto 'icmp'
	option src_ip 'fe80::/10'
	list icmp_type '130/0'
	list icmp_type '131/0'
	list icmp_type '132/0'
	list icmp_type '143/0'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-ICMPv6-Input'
	option src 'wan'
	option proto 'icmp'
	list icmp_type 'echo-request'
	list icmp_type 'echo-reply'
	list icmp_type 'destination-unreachable'
	list icmp_type 'packet-too-big'
	list icmp_type 'time-exceeded'
	list icmp_type 'bad-header'
	list icmp_type 'unknown-header-type'
	list icmp_type 'router-solicitation'
	list icmp_type 'neighbour-solicitation'
	list icmp_type 'router-advertisement'
	list icmp_type 'neighbour-advertisement'
	option limit '1000/sec'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-ICMPv6-Forward'
	option src 'wan'
	option dest '*'
	option proto 'icmp'
	list icmp_type 'echo-request'
	list icmp_type 'echo-reply'
	list icmp_type 'destination-unreachable'
	list icmp_type 'packet-too-big'
	list icmp_type 'time-exceeded'
	list icmp_type 'bad-header'
	list icmp_type 'unknown-header-type'
	option limit '1000/sec'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-IPSec-ESP'
	option src 'wan'
	option dest 'lan'
	option proto 'esp'
	option target 'ACCEPT'

config rule
	option name 'Allow-ISAKMP'
	option src 'wan'
	option dest 'lan'
	option dest_port '500'
	option proto 'udp'
	option target 'ACCEPT'

config include
	option path '/etc/firewall.user'

config zone
	option name 'wireguard'
	option mtu_fix '1'
	option masq '1'
	option output 'ACCEPT'
	option input 'REJECT'
	option forward 'REJECT'
	option network 'PS1 wan'

config forwarding
	option dest 'wireguard'
	option src 'lan'

config forwarding
	option dest 'wan'
	option src 'lan'

config rule
	option name 'Laptop2wg'
	list src_ip '192.168.1.177'
	list src_ip '192.168.1.237'
	option dest 'wireguard'
	option target 'ACCEPT'
	list proto 'tcp'
	option src 'lan'
ip route show
default via 10.234.0.1 dev pppoe-wan proto static
10.234.0.1 dev pppoe-wan proto kernel scope link src 10.234.78.95
150.203.26.247 via 10.234.0.1 dev pppoe-wan proto static
192.168.1.0/24 dev br-lan proto kernel scope link src 192.168.1.1

Network details

cat /etc/config/network

config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option ula_prefix 'fdad:a5f8:c80c::/48'

config interface 'lan'
	option type 'bridge'
	option ifname 'eth0.1'
	option proto 'static'
	option ipaddr '192.168.1.1'
	option netmask '255.255.255.0'
	option ip6assign '60'

config device 'lan_eth0_1_dev'
	option name 'eth0.1'
	option macaddr '98:fa:c4:6e:6d:49'

config interface 'wan'
	option ifname 'eth0.2'
	option proto 'pppoe'
	option password ''
	option ipv6 'auto'
	option username ''
	list dns '8.8.8.8'
	list dns '8.8.4.4'
	option peerdns '0'

config device 'wan_eth0_2_dev'
	option name 'eth0.2'
	option macaddr '98:da:c4:6e:6d:4a'

config interface 'wan6'
	option ifname 'eth0.2'
	option proto 'dhcpv6'
	option reqaddress 'try'
	option reqprefix 'auto'
	list dns '2001:4860:4860::8888'
	list dns '2001:4860:4860::8844'
	option peerdns '0'

config switch
	option name 'switch0'
	option reset '1'
	option enable_vlan '1'

config switch_vlan
	option device 'switch0'
	option vlan '1'
	option ports '1 2 3 4 6t'

config switch_vlan
	option device 'switch0'
	option vlan '2'
	option ports '0 6t'

config interface 'PS1'
	option proto 'wireguard'
	option listen_port ‘61820'
	list addresses '10.110.0.2/32'
	option private_key ''
	option delegate '0'

config wireguard_PS1
	list allowed_ips '0.0.0.0/0'
	list allowed_ips '::/0'
	option endpoint_port ‘61820'
	option persistent_keepalive '25'
	option endpoint_host '150.203.26.247'
	option preshared_key ''
	option public_key ‘’
	option route_allowed_ips '0'

config route
	option source '10.110.0.2'
	option table '202'
	option netmask '0.0.0.0'
	option target '0.0.0.0'
	option interface 'PS1'

LUCI/OpenWrt version

LuCI openwrt-19.07 branch (git-21.044.30835-34e0d65) / OpenWrt 19.07.7 r11306-c4a6851c72
uci -q delete vpn-policy-routing.@policy[0].proto
uci set vpn-policy-routing.@policy[0].src_addr="192.168.1.177 192.168.1.237"
uci set vpn-policy-routing.@policy[0].dest_addr="!192.168.1.0/24"
uci commit vpn-policy-routing
/etc/init.d/vpn-policy-routing restart
1 Like

Thank you @vgaetera . Now the vpn policy routing has changed to

config policy
	option name 'Laptop2Wg'
	option chain 'FORWARD'
	option interface 'PS1'
	option src_addr '192.168.1.177 192.168.1.237'
	option dest_addr '!192.168.1.0/24'

However, the connection is still not going trough Wireguard.

1 Like
uci -q delete firewall.@zone[1].network
uci add_list firewall.@zone[1].network="wan"
uci add_list firewall.@zone[1].network="wan6"
uci -q delete firewall.@zone[2].network
uci add_list firewall.@zone[2].network="PS1"
uci -q delete firewall.@rule[9]
uci commit firewall
/etc/init.d/firewall restart
/etc/init.d/vpn-policy-routing restart
/etc/init.d/vpn-policy-routing support

Here is the output

 /etc/init.d/vpn-policy-routing support
vpn-policy-routing 0.3.2-20 running on OpenWrt 19.07.7.
============================================================
Dnsmasq version 2.80  Copyright (c) 2000-2018 Simon Kelley
Compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP no-DHCPv6 no-Lua TFTP no-conntrack no-ipset no-auth no-nettlehash no-DNSSEC no-ID loop-detect inotify dumpfile
============================================================
Routes/IP Rules
default         10.234.0.1      0.0.0.0         UG    0      0        0 pppoe-wan

IPv4 Table 201: default via 10.234.0.1 dev pppoe-wan
192.168.1.0/24 dev br-lan proto kernel scope link src 192.168.1.1
IPv4 Table 201 Rules:
32763:	from all fwmark 0x10000/0xff0000 lookup wan

IPv4 Table 202: default via 10.100.0.2 dev PS1
192.168.1.0/24 dev br-lan proto kernel scope link src 192.168.1.1
IPv4 Table 202 Rules:
32762:	from all fwmark 0x20000/0xff0000 lookup PS1
============================================================
Mangle IP Table: PREROUTING
-N VPR_PREROUTING
-A VPR_PREROUTING -m dscp --dscp 0x03 -c 0 0 -g VPR_MARK0x020000
============================================================
Mangle IP Table: FORWARD
-N VPR_FORWARD
-A VPR_FORWARD -s 192.168.1.177/32 ! -d 192.168.1.0/24 -m comment --comment Laptop2Wg -c 1184 272113 -g VPR_MARK0x020000
-A VPR_FORWARD -s 192.168.1.237/32 ! -d 192.168.1.0/24 -m comment --comment Laptop2Wg -c 37 9525 -g VPR_MARK0x020000
============================================================
Mangle IP Table MARK Chain: VPR_MARK0x010000
-N VPR_MARK0x010000
-A VPR_MARK0x010000 -c 0 0 -j MARK --set-xmark 0x10000/0xff0000
-A VPR_MARK0x010000 -c 0 0 -j RETURN
============================================================
Mangle IP Table MARK Chain: VPR_MARK0x020000
-N VPR_MARK0x020000
-A VPR_MARK0x020000 -c 1221 281638 -j MARK --set-xmark 0x20000/0xff0000
-A VPR_MARK0x020000 -c 1221 281638 -j RETURN
============================================================
Current ipsets
============================================================
1 Like
uci -q delete network.@route[0]
uci commit network
/etc/init.d/network restart

uci -q delete vpn-policy-routing.config.PS1_dscp
uci -q delete vpn-policy-routing.@policy[0].chain
uci commit vpn-policy-routing
/etc/init.d/vpn-policy-routing restart

nope, still nothing.

1 Like

Completely reset the router and reinstalled wireguard.
tried the traceroute , the connection is going through the ISP

traceroute openwrt.org
traceroute to openwrt.org (139.59.209.225), 64 hops max, 52 byte packets
 1  openwrt (192.168.1.1)  2.196 ms  1.506 ms  1.501 ms
 2  10.234.0.1 (10.234.0.1)  2.578 ms  2.347 ms  2.603 ms
 3  broadband.actcorp.in (202.83.20.43)  6.867 ms * *
 4  14.141.145.5.static-bangalore.vsnl.net.in (14.141.145.5)  2.966 ms  5.524 ms  3.095 ms
 5  172.31.47.5 (172.31.47.5)  22.821 ms  22.982 ms  22.863 ms
 6  ix-ae-0-100.tcore2.mlv-mumbai.as6453.net (180.87.39.25)  18.750 ms  18.721 ms  22.096 ms
 7  if-ae-2-2.tcore1.mlv-mumbai.as6453.net (180.87.38.1)  142.517 ms  142.796 ms  142.669 ms
 8  if-ae-5-2.tcore1.wyn-marseille.as6453.net (80.231.217.29)  150.055 ms  148.154 ms *
 9  if-ae-2-2.tcore2.wyn-marseille.as6453.net (80.231.217.2)  147.173 ms  149.651 ms  146.906 ms
10  if-ae-7-3.tcore2.fnm-frankfurt.as6453.net (195.219.87.33)  146.930 ms
    if-ae-7-6.tcore2.fnm-frankfurt.as6453.net (195.219.87.168)  147.103 ms
    if-ae-47-5.tcore2.fnm-frankfurt.as6453.net (195.219.87.208)  151.317 ms
11  if-ae-59-2.tcore1.fr0-frankfurt.as6453.net (195.219.87.195)  147.057 ms
    if-ae-4-2.tcore1.fr0-frankfurt.as6453.net (195.219.87.18)  144.953 ms  148.488 ms
12  wiki-01.infra.openwrt.org (139.59.209.225)  148.205 ms  145.389 ms  142.861 ms

i think i fixed it by setting the config to PREROUTING instead of FORWARD

============================================================
Mangle IP Table: PREROUTING
-N VPR_PREROUTING
-A VPR_PREROUTING -s 192.168.1.177/32 ! -d 192.168.1.0/24 -m comment --comment Laptop2Wg -c 82 32755 -g VPR_MARK0x020000
-A VPR_PREROUTING -s 192.168.1.237/32 ! -d 192.168.1.0/24 -m comment --comment Laptop2Wg -c 1 52 -g VPR_MARK0x020000
============================================================
1 Like

Change to:

config policy
	option name 'Laptop2Wg'
	option src_addr '192.168.1.177'
	option interface 'PS1'

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.