Hi there,
The table is required because that is what we are creating, an independent new routing table, so that we can tell the router where to send traffic, separately from the Main Table.
Mangling is a method of identifying traffic with some specificity, in order to apply routes as required. I havent used mangling for other needs other than involved in routing but there may be other cases… We can specify and move traffic differently as well with the use of Routing RULES.
In the mangling rules, we don’t state table to identify the table, we use the Routing Mark to do so. It ties to what we have entered in the TABLE definition itself ( the link you seek ).
Correct we do create one route, but we specify with either MANGLING or Routing Rules, what particular traffic is to use that route withe the new routing table.
What we are saying in the mangle rule is that for the identified local traffic wishing to go to these destinations, assign a route-mark in prerouting.
When it comes time to send the traffic, the router will bypass the main table and send the traffic out wireguard as we want.
However it as a last step has to ensure the firewall rules allow it.
Add chain=forward action=accept in-interface-list=Subnets-to-WG dst-address-list=REMOTE
Routing rules ( separate from mangling ) are excellent for forcing traffic out any Routing Table, as long as the source is a single subnet or single address (NO LISTS)
You could apply it smartly to contain a number of contiguous subnets by use of netmask . The table and IP route are still required, and we add the routing rule (no mangles).
192.168.0.0/24 for single subnet into wireguard
192.168.0.0/XX for multiple subnets into wireguard.
/routing table add fib name=useWG
/ip route
add dst-address=0.0.0.0/0 interface=wireguard routing-table=useWG
/routing rule dst-address=192.168.0.0/XX action=lookup-only-in-table table=main
/routing rule src-address=192.168.0.0/XX dst-address=10.10.10.0/YY action=lookup table=useWG
The advantage is that its much simpler to do in many cases and does not affect fasstrack rules.
When using mangles one must ensure the traffic does not hit the fasstrack rule otherwise performance bogs down and I think errors may occur.
If using Routing Rules for any WANIP traffic, the WANIP must be static/fixed
You should note above I have two routing rules and ORDER is critical. The second rule the one pushing traffic to wireguard pushes ALL TRAFFIC.
Imagine if local subnet wants to either
a. originate traffic to another local subnet OR
b. answer a query from another local subnet.
Wouldnt work because all that traffic would get forced into the wireguard tunnel and go nowhere.
Thus we ensure local traffic desired is permitted by ensuring that traffic goes first in routing rules;.
Final note: Mangle takes precedence over Routing Rules if there is overlap.