My Centos machine has a custom routing table foo_table
containing just a default gateway route:
# ip route add default via 10.0.2.1 table foo_table
# ip route show table foo_table
default via 10.0.2.1 dev bond0.2
A policy rule routes all traffic from 10.0.2.22 using this table:
# ip rule show
0: from all lookup local
32765: from 10.0.2.22 lookup foo_table
32766: from all lookup main
32767: from all lookup default
When I traceroute from the 10.0.2.22 Centos machine to another machine on the same local subnet, the packet is routed to the router first, then to the server:
# traceroute -In 10.0.2.60
traceroute to 10.0.2.60 (10.0.2.60), 30 hops max, 60 byte packets
1 10.0.2.1 3.573 ms 3.972 ms 4.219 ms
2 10.0.2.60 1.461 ms 1.494 ms 1.700 ms
Naturally, I would like local traffic to not unnecessarily involve the router like this.
In the main
routing table, there is of course a link scope route for the local subnet:
10.0.2.0/24 dev bond0.2 proto kernel scope link src 10.0.2.22
My understanding is that because foo_table
is consulted before main
(as per ip rule show
), the default route via 10.0.2.1 in foo_table
is used instead, even though the destination is a link local address.
Does this mean I have to add a link scope route to foo_table
as well?
# ip route add 10.0.2.0/24 dev bond0.2 scope link table foo_table
# ip route show table foo_table
10.0.2.0/24 dev bond0.2 scope link
default via 10.0.2.1 dev bond0.2
It appears to resolve the issue, but is this the right way to do it?
# traceroute -In 10.0.2.60
traceroute to 10.0.2.60 (10.0.2.60), 30 hops max, 60 byte packets
1 10.0.2.60 0.339 ms 0.355 ms 0.399 ms
Is my understanding of what's happening correct? (I've minimal experience with routing.)