FreeBSD default routing question concerning DHCP

I read http://www.freebsd.org/doc/handbook/network-routing.html#network-routing-default and I'm still a little unclear on how FreeBSD automatically determines which interface is providing the default route.

I set up this FreeBSD configuration this morning to aid me in resolving my queries and this is the relevant aspect of my rc.conf:

Code:
gateway_enable="YES"
ifconfig_sis0="DHCP"
ifconfig_em0="inet 10.1.1.5 netmask 255.255.255.192"
defaultrouter=""

And here's the output of my routing table (I made up the external address):

Code:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            d215-251-233-1.hom UGS         0    90442   sis0
10.1.1.0/26        link#6             U           0   121839    em0
10.1.1.5           link#6             UHS         0        0    lo0
localhost          link#10            UH          0      406    lo0
215.251.233.0/21   link#5             U           0        0   sis0
d215-251-170-96.ho link#5             UHS         0        0    lo0

In this instance, the sis0 interface is configured for DHCP and is connected directly to a standard home internet connection and FreeBSD automatically assigned it flags "G" and "S".

  1. How did FreeBSD determine that it should assign "G" flag to the internet connection and make it the default route? This is obviously what I want but I'm curious how it makes that determination.
  2. What happens when I have a second DHCP internet connection, how does FreeBSD determine which of those two to assign "G" and make the default route?

    So concerning question 2, let's say this is my new rc.conf:

    Code:
    gateway_enable="YES"
    ifconfig_sis0="DHCP"
    ifconfig_xl0="DHCP"
    ifconfig_em0="inet 10.1.1.5 netmask 255.255.255.192"
    defaultrouter=""

    And let's say my new routing table is:

    Code:
    Destination        Gateway            Flags    Refs      Use  Netif Expire
    default            d215-251-233-1.hom UGS         0    90442   sis0
    10.1.1.0/26        link#6             U           0   121839    em0
    10.1.1.5           link#6             UHS         0        0    lo0
    localhost          link#10            UH          0      406    lo0
    222.216.241.0/24   link#7             U           0       12    xl0
    222.216.241.224    link#7             UHS         0        0    lo0
    215.251.233.0/21   link#5             U           0        0   sis0
    d215-251-170-96.ho link#5             UHS         0        0    lo0

    So now I have two DHCP addresses, 222.216.241.224 and 215.251.170.96, and FreeBSD has decided that the 222.216.241.224 is still the default. (These numbers are not mine, I basically made them up for this example)
  3. Let's say I'd rather it utilize 215.251.170.96, how do I advise my router to prioritize one NIC over the other? How can I say defaultrouter always = "xl0"?
Thanks in advance!
 
I suppose I also have a related new question as well...

4) How can I add a static route to utilize a specific interface, rather than a specific address? Man route states:

"In a change or add command where the destination and gateway are not sufficient to specify the route (as in the ISO case where several interfaces may have the same address), the -ifp or -ifa modifiers may be used to determine the interface or interface address"

Yet it doesn't give an example and my googling falls short.

route add 1.2.3.4/19 -ifp em1 doesn't work and route add 1.2.3.4/19 -interface em1 leads to an unrouted location.
 
It's a couple years later but I'm still having an issue with my posts above. I can easily do this with alternative platforms but I'm not getting the hang of it with FreeBSD.

To summarize my first and second post, I'm basically asking how a multihomed FreeBSD server can be forced to prioritize a specific interface when there are two NICs that receive DHCP addresses, addresses that both change.

Since the addresses both change, I can't specify the defaultrouter by address and the default router chosen by dhclient.conf has been random and reviewing the documentation of dhclient.conf(5) isn't illuminating.

Thanks in advance!
 
FreeBSD doesn't do multipath routing yet so in short you can't. You would need some external means to handle it. Examples would be a routing daemon that talks to upstream and fixes route, devd(8) or net/ifstated initiated actions based on interface state, or use of multiple routing tables and handling moving packets between FIBs with a firewall.
 
FreeBSD doesn't do multipath routing yet so in short you can't.

This is what I was afraid of. Do you know if OpenBSD treats this scenario any differently? I can achieve what I'm trying to do in Linux but I prefer working with FreeBSD.

I was manually re-creating routes via route command


I was wondering the same thing but since my literal intention is not primarily fault tolerance or load balancing, I was concerned this option may not apply. I have a need for a list of static routes to pass through specific interfaces depending on the target CIDR range and a cursory glance of the man page suggests utilizing lagg may not allow for this configuration.

Thanks for the interactivity gents.
 
If looking at it would tell me how to do it with stock FreeBSD then perhaps I will.

It's pretty difficult to do what pfSense is doing on stock FreeBSD. PfSense uses a system that dynamically reloads and reconfigures absolutely everything including gateway settings and anything derived from them when the system detects a change somewhere, for example when a WAN address changes. You might be able to replicate the functionality of pfSense with a lot of devd(8) magic and custom scripting but it's a lot of work.
 
dhclient(8) won't change the default route if the dhcp server doesn't supply one. So configure dhclient(8) to only send a "request" for "routers" on one interface. This is what I used in /etc/dhclient.conf to solve this problem.
Code:
#...
interface "fxp0" {
    request subnet-mask, broadcast-address time-offset;
}
Note fxp0 is the internal corporate network with a slow internet connection, em0 (not mentioned) has a fast internet connection.
 
Last edited by a moderator:
Back
Top