# Is the default route assigned by dhcp saved somewhere?

## nasaiya

Hi all,

Is there a way to determine what the original default route assigned by dhcp is after you've altered the routing tables and removed it?

I believe dhcpcd is the one that gets the dhcp lease but I didn't see any option in the man page to query it for that sort of information.

Long story short I'm running openvpn with a policy routing setup and the up/down.sh scripts *sometimes* and for no apparent reason are not passed all the variables (like $route_net_gateway) which my scripts currently use which results in a broken routing table with no default route.

So basically I'm wondering is the dhcp assigned default route stored somewhere (other than in the initial routing table) where I could look it up for use in a script instead of relying on the variables that don't always get passed to openvpn's up/down.sh?

Thanks in advance for any help!

This little nuisance bug has been annoying me for quite some time.

----------

## Ant P.

There's probably something in dhcpcd that can do this, but I couldn't find anything obvious reading the manpages. You could try making a standalone script around rtmon(8).

----------

## nasaiya

Thanks for the quick response!

rtmon looks interesting, first time I've ever heard of it I'll have to play around with that.

Naturally I've been messing with this for a couple days now and as soon as I go and post for help I seem to have found a workaround.

Apparently openvpn's "init" and "restart" modes are the key.. I think openvpn no longer knows the old default route in restart mode so I just made my scripts exit if in restart mode since the routing tables don't need to change... I think this will work as long as the vpnserver doesn't assign me a new ip. If it does I can probably cobble something together with rtmon like my original idea.

Thanks!

----------

## John R. Graham

 *Ant P. wrote:*   

> ...
> 
> You could try making a standalone script around rtmon(.

 What package is rtmon part of?

- John

----------

## nasaiya

 *John R. Graham wrote:*   

>  *Ant P. wrote:*   ...
> 
> You could try making a standalone script around rtmon(. What package is rtmon part of?
> 
> - John

 

# equery belongs rtmon

 * Searching for rtmon ... 

sys-apps/iproute2-3.8.0 (/sbin/rtmon)

 :Smile: 

----------

## UberLord

 *nasaiya wrote:*   

> Is there a way to determine what the original default route assigned by dhcp is after you've altered the routing tables and removed it?
> 
> I believe dhcpcd is the one that gets the dhcp lease but I didn't see any option in the man page to query it for that sort of information.
> 
> 

 

dhcpcd -4U eth0

The 4 means dump the DHCP lease and not the DHCPv6 lease (if you have both).

You can see the routing options there, along with the DNS, IP address, etc.

You can also get dhcpcd to re-apply it's known config right away using the -g option.

All of this is of course documented in dhcpcd( 8 )  :Smile: 

EDIT:

It might be tricky to get to the actual default route.

DHCP has it in two options. If classless_static_routes is there, that takes precednece, otherwise it's in routers.

Example:

```
classless_static_routes='0.0.0.0/0 10.73.2.1'

routers=10.73.2.1
```

0.0.0.0/0 means that 10.73.2.1 is the gateway for the default route, so you have to hunt the space separated string for it an the next word is the ip address.

You can do this in shell script quite easily.

----------

