# rc.conf defaultrouter="x.x.x.x" is overwritten by dhcp



## esogs (Aug 12, 2009)

Hello, in my rc.conf file I have configuration items of:


```
ifconfig_re0="inet X.X.X.X netmask 255.255.255.248 media 100baseTX mediaopt full-duplex"
defaultrouter="X.X.X.X"
ifconfig_dc0="DHCP"
```

I had "thought" that similar to trying to add a default route at the command line, if the route already existed (by our setting it in the config file using defaultrotuer) and DHCP tried to set it, it would fail.

But DHCP must actually delete the default route and re-add the one it "wants". On the other hand, it isn't working to add the defaultrouter line after the dhcp pull, presumably because the default router already exists at that point, and, just like by hand, it fails to overwrite it.

Anyone know how to prevent DHCP from either over-writing the first route, or, how to do a 'route delete default' in the rc.conf file on the dhcp added default route?

Thanks.


----------



## SirDice (Aug 12, 2009)

Create a script called /etc/dhclient-enter-hooks:

```
add_new_routes() {
   return 0
}

delete_old_routes () {
    return 0
}
```

That will prevent dhclient from deleting and adding routes. Have a look at /sbin/dhclient-script. You can redefine all the functions in dhclient-enter-hooks.


----------



## esogs (Aug 13, 2009)

Thank you sir.  Before I read this, I actually did the thing I should have done in the first place:

1.  I removed the IP address for this machine from DHCP
2.  Added a static route on the card


----------



## ironmikie (Aug 13, 2009)

Maybe you can take a look at man dhclient.conf especially the sections about prepend and/or append.


----------

