I have an Ubuntu 18.04 host with two network interfaces on two subnets. I would like to set up symmetric routing so that traffic received from one interface is sent symmetrically out that same interface.
I know how to use Netplan for simple network configurations, but I'm stumped for more advanced configurations. Specifically:
- What is the Netplan syntax to add a default route like I do with
ip route add default via 192.168.0.1 dev ens192 tab 1
? - How can I add a
priority
tag to a route?
My server has two IPs:
$ ip a|grep "inet "
inet 127.0.0.1/8 scope host lo
inet 192.168.0.10/22 brd 192.168.0.255 scope global ens192
inet 192.168.1.10/24 brd 192.168.1.255 scope global ens224
$
I can use the following ip
rules to get the tables that I want:
First, I create a route for each network and then add a default gateway.
$ ip route add 192.168.0.0/24 dev ens192 tab 1
$ ip route add 192.168.1.0/24 dev ens224 tab 2
$ ip route add default via 192.168.0.1 dev ens192 tab 1
$ ip route add default via 192.168.1.1 dev ens224 tab 2
Then, I can create corresponding rules:
$ ip rule add from 192.168.0.10/32 tab 1 priority 100
$ ip rule add from 192.168.1.10/32 tab 2 priority 200
$ ip route flush cache
This gets the routes that I want:
$ ip route show tab 1
default via 192.168.0.1 dev ens192
$ ip route show tab 2
default via 192.168.1.1 dev ens224
$ ip route
default via 192.168.0.10 dev ens192
As well as the rules that I want:
$ ip rule show
0: from all lookup local
100: from 192.168.0.10 lookup 1
200: from 192.168.1.10 lookup 2
32766: from all lookup main
32767: from all lookup default
Hope this answers both of your questions
When you specify
routes:
and then you specifytable:
for those routes, you've effectively created a routing table that can be referenced elsewhere in your config. You can make source based routing for a given interface by addingrouting-policy
such thatfrom:
that interface's IP, usetable:
table you defined earlier in routes. None of these configurations made any sense to me until I figured this out just now.ip route add default via 192.168.0.1 dev ens192 tab 1
would correspond to