0

I have a host with two interfaces. ens4 is mgmnt, ens3 is another network.

# ip -br a | sort
ens1             DOWN
ens2             DOWN
ens3 UP          172.16.10.1
ens4 UP          192.168.1.100

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.100   0.0.0.0         UG    0      0        0 ens4
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 ens4
172.16.10.1     0.0.0.0         255.255.255.0   U     0      0        0 ens3

I want to put all traffic going to ens3 in its own routing table so no traffic coming to the interface will touch the local routing table.

I tried the following:

  • created a new table
echo "100   custom" > /etc/iproute2/rt_table
  • Add a route and rule to match traffic:
# ip route add 172.16.10.0/24 dev ens3 table custom
# ip rule add from 172.16.10.0/24 table custom

# ip route show table custom
172.16.10.0/24 dev ens3 scope link

# ip rule list
0:      from all lookup local
32765:  from 172.16.10.0/24 lookup custom
32766:  from all lookup main
32767:  from all lookup default

However, I noticed that broadcast and local traffic is still in the main table

# ip route show table all | grep 172.16.10
172.16.10.0/24 dev ens3 scope link
broadcast 172.16.10.0 dev ens3 table local proto kernel scope link src 172.16.10.1
local 172.16.10.1 dev ens3 table local proto kernel scope host src 172.16.10.1
broadcast 172.16.10.255 dev ens3 table local proto kernel scope link src 172.16.10.1

Therefore I am not able to route these directly connected routes. The work around is to put the interface, and routing table into their our name spaces. Is it possible to move broadcasting and local routes to a different routing table instead? I think the issue is how I am adding the ip address and ip rule statements but not sure.

Anyone know if what I am trying to do is possible?

1 Answer 1

0

Figured it out. I needed to remove the route rule I added and re-add like this with a via route:

#ip route del 172.16.10.0/24 dev ens3 table custom
#ip route add 172.16.10.0/24 dev ens3 table custom via 172.16.10.1

# ip route show table custom
172.16.10.0/24 dev ens3 scope link
172.16.10.0/24 via 172.16.1 dev ens3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.