Set Default Route w/ DHCP on Multi-Homed Box

I have a machine that I use for a "lab" that has (at least) two ethernet ports: em0 and em1

Both are connected to different networks with their own DHCP servers. em0 is always connected to the "production" network that has Internet access and em1 is connected to the "lab" network. Sometimes the default route gets set correctly (em0) and other times it will get set incorrectly (em1).

I know that I can set the default route in /etc/rc.conf:

Code:
defaultrouter="192.168.1.1"

However, this machine could be on a different network where the IP addressing is no longer 192.168.x.x (i.e. 10.1.1.0 but the gateway obtained by DHCP on this interface would still be the default route. How can I tell (force) FreeBSD to use em0 as my default route?
 
Regardless of the default route you set in rc.conf it will always be overruled by DHCP. And it's the last DHCP request that sets it. So if em0 does a request it will receive "GatewayA", next em1 will do a DHCP request and sets the default gateway to "GatewayB". So your gateways keep switching back and forth and depends on the last DHCP request that succeeded.

The easiest solution is using DHCP on the production network (em0) and set a static IP address on em1 for the test network. It should also be possible to configure dhclient.conf(5) to specifically ignore the default gateway on requests made via em1.
 
The easiest solution is using DHCP on the production network (em0) and set a static IP address on em1 for the test network.

I thought that as well, but there are times the machine goes into an environment where I don't have control over the DHCP servers (like a school).

It should also be possible to configure dhclient.conf(5) to specifically ignore the default gateway on requests made via em1.

This is an area that I explored for a while, but made no progress. I think I am missing something here.
 
Back
Top