0

I have the following table

$ netstat -r -4 | grep 33.0 192.168.33.0/24 192.168.29.4 UGS ovpns5 

I would like to add additional route to the same network and get

$ route add -net 192.168.33.0/24 192.168.27.2 add net 192.168.33.0: gateway 192.168.27.2 fib 0: route already in table 

Why? Isn't it possible to have two routes to the same net?

I can do route change and it works.

0

1 Answer 1

1

When the kernel is looking for a route for an outbound packet, it wants to find a single answer: if there are multiple matches, it doesn't know which one to pick.

This thread on the freebsd-questions mailing list covers the same question, and suggests solving the problem by "splitting" one of the routes to create two more-specific routes:

The trick to adding a backup default route is to split 'default' into 2 different and more specific subnets:

# route add 0.0.0.0 PRIMARY_GW -netmask 127.0.0.0 # route add 127.0.0.0 PRIMARY_GW -netmask 127.0.0.0 # route add default SECONDARY_GW 

Now that default is split into 2 different smaller subnets than 'default' they will be the preferred route. If your interface that connects PRIMARY_GW goes down, the first 2 routes will be removed, leave your backup 'default' gateway to take affect.

In your case, if you want the existing route (via 192.168.29.4) to be used when it's available, you would want something like this:

route add -net 192.168.33.0/25 192.168.29.4 route add -net 192.168.33.128/25 192.168.29.4 route add -net 192.168.33.0/24 192.168.27.2 

Because the kernel always prefers the most specific route, this will use 192.168.29.4 as the gateway as long as the ovpns5 interface is available. If that interfaces goes down, the routes will be removed and the kernel will start using the 192.168.27.2 gateway.


If you're hoping to load balance between the two connections, you're looking for equal-cost multipath routing (ecmp), and I'm unclear on the state of support for that with FreeBSD.

4
  • I was thinking that load balancing should work out of the box with any TCP/IP stack. I can't imagine, that protocol assumes that all networks should have only one router and only one route. Commented Aug 9, 2022 at 22:16
  • The kernel assumes that all endpoints have a single unique route; this isn't really a "protocol" thing. As I said, there is support for load-balanced routing; I know it's available in Linux, but I'm not familiar with FreeBSD networking, and the searches I made when posting the answer were somewhat inconclusive. Commented Aug 9, 2022 at 22:18
  • How is it working in global internet? I can tracerout to some site and see route is different from day to day. Is this done mostlly with ecmp? Commented Aug 10, 2022 at 8:37
  • The internet at large uses dynamic routing protocols rather than static route tables. Commented Aug 10, 2022 at 11:42

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.