Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Is the default route assigned by dhcp saved somewhere?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
nasaiya
Tux's lil' helper
Tux's lil' helper


Joined: 17 May 2007
Posts: 147

PostPosted: Fri Nov 28, 2014 6:46 pm    Post subject: Is the default route assigned by dhcp saved somewhere? Reply with quote

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.
_________________
If it ain't broke - fix it till it is!
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 5592

PostPosted: Fri Nov 28, 2014 7:09 pm    Post subject: Reply with quote

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).
Back to top
View user's profile Send private message
nasaiya
Tux's lil' helper
Tux's lil' helper


Joined: 17 May 2007
Posts: 147

PostPosted: Fri Nov 28, 2014 7:22 pm    Post subject: Reply with quote

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!
_________________
If it ain't broke - fix it till it is!
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10156
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri Nov 28, 2014 7:38 pm    Post subject: Reply with quote

Ant P. wrote:
...
You could try making a standalone script around rtmon(8).
What package is rtmon part of?

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
nasaiya
Tux's lil' helper
Tux's lil' helper


Joined: 17 May 2007
Posts: 147

PostPosted: Fri Nov 28, 2014 8:06 pm    Post subject: Reply with quote

John R. Graham wrote:
Ant P. wrote:
...
You could try making a standalone script around rtmon(8).
What package is rtmon part of?

- John


# equery belongs rtmon
* Searching for rtmon ...
sys-apps/iproute2-3.8.0 (/sbin/rtmon)

:)
_________________
If it ain't broke - fix it till it is!
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6737
Location: Blighty

PostPosted: Sat Nov 29, 2014 7:31 am    Post subject: Re: Is the default route assigned by dhcp saved somewhere? Reply with quote

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 ) :)

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:
Code:
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.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum