I am struggling for hours with what I thought is an easy thing: Source routing. I am new ro VyOS and used Mikrotik RouterOS before. Here is what I had there:
/ip route rule add dst-address=0.0.0.0/0 src-address=192.0.2.0/24 table=main
/ip route rule add dst-address=0.0.0.0/0 src-address=192.0.2.0/24 table=default_pub
/ip route rule add dst-address=0.0.0.0/0 table=main
/ip route rule add dst-address=0.0.0.0/0 table=default_lan
where 192.0.2.0/24 is my public /24 and I want to achieve that everything with a source address from 192.0.2.0/24 is not sent over the normal default gateway but a separate tunnel.
For this reason, I removed the default gateway from the main routing table (“main”) and moved it to “default_lan”. Then I created a table “default_pub” that only includes a default route via the separate tunnel (which routes the 192.0.2.0/24).
What above commands do:
- For any source address 192.0.2.0/24, we first try the main routing table. If there are no matches, we try table default_pub. (It must match because this table has a default route)
- For any other address, we first try the main routing table. If there are no matches, we try default_lan (which must match because it includes the default gateway)
I tried the same thing in VyOS. To simplify things, I just try “local-route”. Here, table 170 corresponds to default_lan in the example above.
policy {
local-route {
rule 101 {
destination 0.0.0.0/0
set {
table main
}
}
rule 102 {
destination 0.0.0.0/0
set {
table 170
}
}
}
}
In my opinion, all locally generated packets should now reach the internet. But they don’t. It seems only rule 101 is processed but table 170 is never consulted.