Automatic routes using DHCP-assigned gateway

Hello,

I have a router which gets a gateway address via DHCP client. The gateway address is not always the same, it may change. Once a DHCP lease is obtained, I want to insert some routes in the routing table automatically, but I want these routes to use the dynamically assigned gateway, not a statically defined gateway address. How can this be done?

Hi,

Do you mean? when the WAN IP address and possibly obtained DNS' adresses too, then you want to immediately reflect these changes to your LAN DHCP clients? If yes, then the question is: what for? If not, then: what effect do you really want to get?

You need a DHCP client script.

RoS provides a few variables that represent the data received by the DHCP server, and you can use scripting to create the routes.

Example:

If you search on the forum you will find many other examples, if you don't manage to get a working script, post it here and surely someone will be able to assist you.

Thanks @jaclaz! This looks exactly like what I need!

Why do not make rules based on the outgoing interface instead of gw's address?
If some routes should be changed to the new address then what is is needed for?
LAN users should not be aware of the WAN IP.

LAN users should have router's IP set as a GW and only the router needs to be updated.
Why LAN users should have WAN's side GW set as their? Router is aware of the change so there is no need to change antything then.

A bit of configuration as an example would help.