Pbr: what should be set a default gateway in multiple vpn setup

just trying to understand how pbr manages default gateways.

this is my setup:

I have two different vpn interfaces a wireguard interface which is the default gateway. every device on the network ]goes through wireguard interface.

an ovpn interface connected to another vpn

I have installed pbr and added two rules one to go through wan... no vpn at all.. (it is a nas and it only connects to the internet when i need to download files from an external sftp server to have max bandwith. )

my question is as follows..
if i configure a device to use the ovpn interface.. will it also go through the wireguard interface which is the default gateway? so i will have double vpn for that device?

device > ovpn network > wireguard network > internet?

should i set the wan as default gateway but then how do i configure pbr to route all the devices on the network via wireguard except the ones i need to route without vpn or through the ovpn interface?

this is my pbr config:

root@OpenWrt:~# cat /etc/config/pbr

config pbr 'config'
	option verbosity '2'
	option strict_enforcement '1'
	option resolver_set 'none'
	option ipv6_enabled '0'
	list ignored_interface 'vpnserver'
	list ignored_interface 'wgserver'
	option boot_timeout '30'
	option rule_create_option 'add'
	option procd_reload_delay '1'
	option webui_show_ignore_target '0'
	list webui_supported_protocol 'all'
	list webui_supported_protocol 'tcp'
	list webui_supported_protocol 'udp'
	list webui_supported_protocol 'tcp udp'
	list webui_supported_protocol 'icmp'
	option enabled '1'

config include
	option path '/usr/share/pbr/pbr.user.aws'
	option enabled '0'

config include
	option path '/usr/share/pbr/pbr.user.netflix'
	option enabled '0'

config policy
	option name 'Plex/Emby Local Server'
	option interface 'wan'
	option src_port '8096 8920 32400'
	option enabled '0'

config policy
	option name 'Plex/Emby Remote Servers'
	option interface 'wan'
	option dest_addr 'plex.tv my.plexapp.com emby.media app.emby.media tv.emby.media'
	option enabled '0'

config policy
	option interface 'wan'
	option name 'synology'
	option src_addr '192.168.1.12'

config policy
	option name 'test co '
	option src_addr '192.168.1.185'
	option interface 'ovpn'
root@OpenWrt:~# /etc/init.d/pbr status
============================================================
pbr - environment
pbr 1.0.1-16 running on OpenWrt 22.03.2. WAN (IPv4): wan/wan.1081/85.10.107.254.
============================================================
Dnsmasq version 2.86  Copyright (c) 2000-2021 Simon Kelley
Compile time options: IPv6 GNU-getopt no-DBus UBus no-i18n no-IDN DHCP no-DHCPv6 no-Lua TFTP no-conntrack no-ipset no-auth no-cryptohash no-DNSSEC no-ID loop-detect inotify dumpfile
============================================================
pbr chains - policies
	chain pbr_forward {
	}
	chain pbr_input {
	}
	chain pbr_output {
	}
	chain pbr_prerouting {
		ip saddr @pbr_wan_4_src_ip_cfg066ff5 goto pbr_mark_0x010000 comment "synology"
		ip saddr @pbr_ovpn_4_src_ip_cfg076ff5 goto pbr_mark_0x030000 comment "test co "
	}
	chain pbr_postrouting {
	}
============================================================
pbr chains - marking
	chain pbr_mark_0x010000 {
		counter packets 5 bytes 364 meta mark set meta mark & 0xff01ffff | 0x00010000
		return
	}
	chain pbr_mark_0x020000 {
		counter packets 0 bytes 0 meta mark set meta mark & 0xff02ffff | 0x00020000
		return
	}
	chain pbr_mark_0x030000 {
		counter packets 1049 bytes 117931 meta mark set meta mark & 0xff03ffff | 0x00030000
		return
	}
============================================================
pbr nft sets
	set pbr_wan_4_src_ip_cfg066ff5 {
		type ipv4_addr
		flags interval
		auto-merge
		comment "synology"
		elements = { 192.168.1.12 }
	}
	set pbr_ovpn_4_src_ip_cfg076ff5 {
		type ipv4_addr
		flags interval
		auto-merge
		comment "test co "
		elements = { 192.168.1.185 }
	}
============================================================
IPv4 table 256 route: default via x.x.x.x dev wan.1081 
IPv4 table 256 rule(s):
30000:	from all fwmark 0x10000/0xff0000 lookup pbr_wan
IPv4 table 257 route: default via 10.x.x.x dev wg0 
IPv4 table 257 rule(s):
30001:	from all fwmark 0x20000/0xff0000 lookup pbr_wg0
IPv4 table 258 route: default via 10.x.x.x dev tun0 
IPv4 table 258 rule(s):
30002:	from all fwmark 0x30000/0xff0000 lookup pbr_ovpn

root@OpenWrt:~# cat /etc/config/network 

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

config globals 'globals'

config device
	option name 'br-lan'
	option type 'bridge'
	list ports 'lan1'
	list ports 'lan2'
	list ports 'lan3'
	list ports 'lan4'

config interface 'lan'
	option device 'br-lan'
	option proto 'static'
	option ip6assign '60'
	list ipaddr '192.168.1.254/24'
	option ipv6 '0'
	option delegate '0'

config device
	option name 'wan'
	option macaddr '62:38:e0:c5:36:18'

config interface 'wan'
	option proto 'dhcp'
	option ipv6 '0'
	option device 'wan.1081'
	option metric '20'

config interface 'wan6'
	option proto 'dhcpv6'
	option device 'wan.1081'
	option reqaddress 'try'
	option reqprefix 'auto'

config device
	option type '8021q'
	option ifname 'wan'
	option vid '1081'
	option name 'wan.1081'

config interface 'wg0'
	option proto 'wireguard'
	option private_key 'x.x.x.x'
	list addresses '10..x.x.x/32'
	option peerdns '0'
	list dns '10.2.0.1'
	option metric '10'

config wireguard_wg0
	option description 'US-NJ#9'
	option public_key 'xxxxxxxxxxxxxx'
	list allowed_ips '0.0.0.0/0'
	option route_allowed_ips '1'
	option endpoint_host '69.x.x.x'
	option endpoint_port '51820'

config interface 'ovpn'
	option proto 'none'
	option device 'tun
root@OpenWrt:~# ubus -S call luci.pbr getInterfaces '{"name": "pbr" }'
{"pbr":{"interfaces":["wan","wg0","ovpn"]}}
root@OpenWrt:~# service pbr start
Activating traffic killswitch [✓]
Setting up routing for 'wan/wan.1081/x.x.x.x' [✓]
Setting up routing for 'wg0/a.b.c.d' [✓]
Setting up routing for 'ovpn/tun0/y.y.y.y' [✓]
Routing 'synology' via wan [✓]
Routing 'test co ' via ovpn [✓]
Deactivating traffic killswitch [✓]
pbr 1.0.1-16 monitoring interfaces: wan wg0 ovpn 
pbr 1.0.1-16 (nft) started with gateways:
wan/wan.1081/x.x.x.x
wg0/a.b.c.d [✓]
ovpn/tun0/y.y.y.y

If when you run:

ip route

you see in the main routing table

<openvpn_server_IP_address> dev wg0

this is exactly the case.

Disable the default gateways for the wireguard (option route_allowed_ips '0') and openvpn (pull-filter ignore route-gateway) interfaces and create a third pbr policy:

config policy
	    option name 'synology'
	    option interface 'wan'
	    option src_addr '192.168.1.12'

config policy
	    option name 'test co'
	    option src_addr '192.168.1.185'
	    option interface 'ovpn'

config policy
        option name 'default'
        option interface 'wg0'
        option dest_addr '0.0.0.0/0'

my ip route is the following

default dev wg0 proto static scope link metric 10 
default via 85.x.x.x dev wan.1081 proto static src 85.x.x.x metric 20 
10.2.x.x dev wg0 proto static scope link metric 10 
10.42.0.0/16 dev tun0 proto kernel scope link src 10.42.0.2 
69.10.y.y via 85.x.x.x dev wan.1081 proto static metric 20 
85.x.x.x/25 dev wan.1081 proto static scope link metric 20 
192.168.1.0/24 dev br-lan proto kernel scope link src 192.168.1.254 

i see i have two default one via the wan one via wg0.
the ip starting with 69.10.. is the end point of the wireguard peer.
I do not see where is the tun0 going out since i appeart to have two default. which from my understanding it is not good.

I already disable default gateway in the ovpn configuration file.
image

so that is disabled.

another question which dns does the ovpn interface use. In the wg0 interface i have disabled the peer dns and added a new one. on the ovpn interface i am still getting the one advertised by peer but which one is it? the wan provided by my isp or the one i configured on the wg0 interface configuration.

Change it to option route_allowed_ips '0',

Add this to the end of /etc/config/pbr and you'll be all set.

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