Hello guys. I’ve been trying to setup a routing policy using mangle rules to ensure my traffic coming from VPN interface is answered and goes back through the VPN.
I have RB750Gr3 (R1) with public static WAN IP and hAC ac² (R2) under another ISPs CGNAT. I’ve successfully setup wireguard tunnel between them, R1 LAN is 192.168.98.0/24 and R2’s 10.1.0.1/24. Allowed IPs in R1 peer is 10.1.0.0/24 and in R2 allowed IPs is set 0.0.0.0/0. I have the following mangle rules and routes:
/ip firewall mangle
add action=accept chain=prerouting connection-mark=no-mark connection-state=established,related
add action=mark-connection chain=prerouting in-interface=wireguard1 new-connection-mark=wireguard1-conn passthrough=no
add action=mark-routing chain=prerouting connection-mark=wireguard1-conn new-routing-mark=rtab-1 passthrough=no
add action=mark-connection chain=input in-interface=wireguard1 new-connection-mark=wireguard1-input-conn passthrough=no
add action=mark-routing chain=output connection-mark=wireguard1-input-conn log=yes new-routing-mark=rtab-1 passthrough=no
/routing table
add comment="wireguard1" disabled=no fib name=rtab-1
/ip route
add comment="wireguard1" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=wireguard1 pref-src="" routing-table=rtab-1 scope=30 suppress-hw-offload=no target-scope=10
Also have 0.0.0.0/0 with pppoe-out1 as gateway for my wan connection.
I have a DVR I want to access through my R1’s public ip address. I created a dst-nat rule on R1 for that:
/ip firewall nat
add action=dst-nat chain=dstnat comment="DVR R2" dst-port=52002 in-interface-list=WAN protocol=tcp to-addresses=10.1.0.250
The connection to DVR works perfectly when I’m on R1’s site, don’t even need nat rule. The problem is when I’m accessing from WAN IP. If I place the output mark-routing rule using the same connection mark as the prerouting one, I can’t access the DVR from R1’s public IP anymore and get type 3, code 4 ICMP on R2’s log. That’s why I added the second connection mark in input chain and output routing rule, without the output routing mark I loose access to R2’s from wireguard.
Also I couldn’t figure out why, when I enable passthrough in mark-connection rules, they stop working. From what I have been reading about, it should NOT work when passthrough is disable.
When I’m in R1’s site I use R2’s LAN IP (10.1.0.1) to access it. I don’t use IPs on the tunnel itself.
Here is a full export of the R2 config:
/interface bridge
add comment=Admin name=bridge1
/interface pppoe-client
add add-default-route=yes comment="Link 1" disabled=no interface=ether1 max-mru=1480 max-mtu=1480 name=pppoe-out1 use-peer-dns=yes user=mypppoeuser
/interface wireguard
add comment=S2S listen-port=13232 mtu=1420 name=wireguard1
/interface vlan
add comment=Guest interface=bridge1 name=vlan100 vlan-id=100
/interface ethernet switch port
set 1 default-vlan-id=1 vlan-mode=secure
set 2 default-vlan-id=1 vlan-mode=secure
set 3 default-vlan-id=1 vlan-mode=secure
set 4 default-vlan-id=1 vlan-mode=secure
set 5 default-vlan-id=1 vlan-mode=secure
/interface list
add name=WAN
/ip pool
add comment=Admin name=pool1 ranges=10.1.0.100-10.1.0.200
add comment=Guest name=pool2 ranges=192.168.100.100-192.168.100.200
/ip dhcp-server
add add-arp=yes address-pool=pool1 comment=Admin interface=bridge1 lease-time=12h name=server1
add add-arp=yes address-pool=pool2 comment="Guest VLAN100" interface=vlan100 name=server2
/queue simple
add comment="Limit Guest VLAN100" max-limit=15M/15M name=queue1 queue=pcq-upload-default/pcq-download-default target=vlan100
/routing table
add comment="wireguard1" disabled=no fib name=rtab-1
/interface bridge port
add bridge=bridge1 interface=ether2
add bridge=bridge1 interface=ether3
add bridge=bridge1 interface=ether4
add bridge=bridge1 interface=ether5
add bridge=bridge1 interface=wlan1
/interface ethernet switch vlan
add independent-learning=no ports=switch1-cpu,ether5 switch=switch1 vlan-id=100
add independent-learning=no ports=switch1-cpu,ether2,ether3,ether4,ether5 switch=switch1 vlan-id=1
/interface list member
add interface=pppoe-out1 list=WAN
/interface wireguard peers
add allowed-address=0.0.0.0/0 comment="ap wg1" endpoint-address=x.x.x.x endpoint-port=13232 interface=wireguard1 persistent-keepalive=30s public-key="***"
/ip address
add address=10.1.0.1/24 comment=Admin interface=bridge1 network=10.1.0.0
add address=192.168.100.1/24 interface=vlan100 network=192.168.100.0
/ip dhcp-server lease
add address=10.1.0.250 client-id=1:d8:77:8b:fe:17:56 comment=DVR mac-address=xxxxxxxxxxxx server=server1
/ip dhcp-server network
add address=10.1.0.0/24 comment=Admin dns-server=10.1.0.1 gateway=10.1.0.1 netmask=24 ntp-server=10.1.0.1
add address=192.168.100.0/24 comment=Guest dns-server=10.1.0.1 gateway=192.168.100.1 netmask=24 ntp-server=10.1.0.1
/ip dns
set allow-remote-requests=yes cache-size=6144KiB max-udp-packet-size=512 servers=8.8.8.8
/ip firewall filter
add action=fasttrack-connection chain=forward connection-mark=!fasttrack-off hw-offload=yes in-interface-list=WAN
add action=accept chain=input comment=DNS dst-port=53 in-interface-list=!WAN protocol=udp
add action=accept chain=input dst-port=53 in-interface-list=!WAN protocol=tcp
add action=accept chain=input comment=NTP dst-port=123 in-interface-list=!WAN protocol=udp
add action=accept chain=input comment="wireguard1" in-interface=wireguard1
add action=accept chain=forward in-interface=wireguard1
add action=drop chain=input comment="Isolate Guest VLAN100" in-interface=vlan100
add action=accept chain=input connection-state=established,related in-interface=vlan100
add action=drop chain=forward in-interface=vlan100 out-interface-list=!WAN
add action=accept chain=forward in-interface=vlan100
add action=accept chain=input comment="Input" connection-state=established,related in-interface-list=WAN
add action=drop chain=input in-interface-list=WAN
add action=accept chain=forward comment="LAN" connection-state=established,related in-interface-list=WAN
add action=drop chain=forward connection-nat-state=!dstnat in-interface-list=WAN
/ip firewall mangle
add action=accept chain=prerouting connection-mark=no-mark connection-state=established,related
add action=mark-connection chain=prerouting comment="wireguard1" in-interface=wireguard1 new-connection-mark=wireguard1-conn passthrough=no
add action=mark-routing chain=prerouting connection-mark=wireguard1-conn new-routing-mark=rtab-1 passthrough=no
add action=mark-connection chain=input in-interface=wireguard1 new-connection-mark=wireguard1-input-conn passthrough=no
add action=mark-routing chain=output connection-mark=wireguard1-input-conn log=yes new-routing-mark=rtab-1 passthrough=no
/ip firewall nat
add action=redirect chain=dstnat comment="Redirect DNS" dst-port=53 in-interface-list=!WAN protocol=udp
add action=redirect chain=dstnat dst-port=53 in-interface-list=!WAN protocol=tcp
add action=accept chain=srcnat comment="WireGuard S2S" out-interface=wireguard1
add action=masquerade chain=srcnat comment="Internet" out-interface-list=WAN
/ip route
add comment="wireguard1" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=wireguard1 pref-src="" routing-table=rtab-1 scope=30 suppress-hw-offload=no target-scope=10
I appreciate any help or suggentions ![]()
Thanks in advance.
Regards