Freebsd – choose the outgoing interface for a default route

freebsdroutestatic-routes

I have a FreeBSD 8.0 virtual box with two ethernet interfaces, em0 and em1. em0 is 192.168.1.99 and em1 is 192.168.1.100. Both are "Attached to: Bridged Adapter".

When both are up, if I say

# route add default 192.168.1.1
# netstat -rn
# default            192.168.1.1        UGS         1        6    em0

So far so good. It picked em0.

# ifconfig em0 down
# route delete 0.0.0.0
# route add default 192.168.1.1
# netstat -rn
# default            192.168.1.1        UGS         1        6    *em0*

Ok. So it still picks em0 (it must really like it) even if it's down. I have tested and if I pick another ip (say 10.0.0.1) for em0 it pickes em1 for the route.

This leaves me wondering: how can I make freebsd choose em1 as the outgoing interface ? In linux I remember we could do it with the dev argument.

P.S. I did try using the -interface option – no luck. I tried

# route add default 192.168.1.1 -interface 192.168.1.100
# route add default 192.168.1.1 -interface em1

The result was

0.0.0.0&0xc0a80164 192.168.1.1        US          0        0    em0 =>

I am using FreeBSD 8.0-STABLE. Any help will be appreciated.

EDIT:
On Debian Lenny the same suite of operations correctly picks the interface that is up as outgoing interface. When both are up

route add default gw 192.168.1.1

picks eth2
route add default gw 192.168.1.1 dev eth0
picks eth0

So there must be a way to achieve this on FreeBSD, right ?

Best Answer

It sounds like you want two IPs and redundant connections. If that's the case you want to create a LAGG adapter, attach it to the two NICs, and put the IPs on the LAGG interface.

If that's not the case can you describe exactly what you're trying to accomplish?