2

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 ?

nc3b
  • 153
  • 1
  • 7

3 Answers3

9

You need to use -ifp flag, not -interface.

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
anton
  • 91
  • 1
  • 2
1

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?

Chris S
  • 77,945
  • 11
  • 124
  • 216
  • While this is quite sensible, it doesn't answer my question. For some obscure reason I want to choose the outgoing interface. Perhaps I like one of them better. Perhaps there is an actual pertinent reason I can;t think of right now. – nc3b Aug 06 '10 at 20:14
  • 1
    Well start with why you have two NICs that are both attached to the same network?? What you're asking for amounts to a configuration that was never meant to be supported. – Chris S Aug 06 '10 at 20:24
  • So having an interface down (em0) with an ip in that subnet and an interface up (em1) with an ip in the same subnet is not supported ? – nc3b Aug 06 '10 at 20:31
  • 1
    Having two NICs connected to the exact same network and wanting to configure them totally independently is unsupported, yes. While it will obviously work for a great many things, it's not recommended, and you'll run into odd problems, as you already have. There is no reason to configure it this way. – Chris S Aug 06 '10 at 20:43
  • OK, so the last word is that this it can't be done ? I don't mean to be rude but I believe it *can* be done and it is simply a bug in route that it's not allowing it. (Not a very good argument but: if the linux crowd supports it I belive someone in some dark corner of the internet once needed it). – nc3b Aug 06 '10 at 20:50
  • $OS does a lot of things without a clear reason; necessity is not commonly a reason. Let me be sure I understand what you want; you need to administratively disable an NIC, and have routing automatically select the other independently configured interface as it lies on the same network as the first? – Chris S Aug 06 '10 at 20:53
  • @Chris: That or at least let me manually specify the physical outgoing interface. It's not like it has to go completely out of it's way. It _already_ is mapping the static route to a physical interface, right ? – nc3b Aug 06 '10 at 20:55
  • I have to dig through the code again to be sure; but I believe when you show the routes, it generates that information for your convenience. I think the kernel tracks it as $route_dest goes to $gateway, and find the first $interface where $gateway is reachable is selected. It doesn't take into consideration that the $interface is down, and I don't think the table stores $interface when it already has $gateway. (I could be wrong...) – Chris S Aug 06 '10 at 21:06
  • I noticed there is an rt_ifp in rtentry: http://www.unix.com/man-page/freebsd/9/rtentry/ but it doesn't say much about it. – nc3b Aug 06 '10 at 21:16
  • "For each route we infer the interface to use from the gateway address supplied when the route was entered." route.h:119 - The tables do not store interface when a gateway is provided. It does use that field for point-to-point links. Where there might not even be an address on the NIC. – Chris S Aug 06 '10 at 21:23
  • Ok, that pretty much settles it :) – nc3b Aug 06 '10 at 21:24
-1

You should take a look at the "Link Aggregation and Failover" in the FreeBSD Handbook here https://www.freebsd.org/doc/handbook/network-aggregation.html