I have an interface which is given its IP address and Router/Gateway information by DHCP.
I wish to configure a bespoke IP route whose Nexthop is the Router/Gateway allocated by DHCP, and thus not knowable at configuration time.
How can I do that?
I have an interface which is given its IP address and Router/Gateway information by DHCP.
I wish to configure a bespoke IP route whose Nexthop is the Router/Gateway allocated by DHCP, and thus not knowable at configuration time.
How can I do that?
If it’s a default route use the add-default-route=yes option on the DHCP client. If it’s a proper spoke router you’ll need a dynamic routing protocol that both routers speak.
No, I’ve disabled the default route associated with the DHCP allocation. I want a staticly-defined route that just sends traffic to one known remote IP address via the DHCP-allocated interface’s gateway router. There is no other router involved under my control.
If you can’t run a routing protocol there’s nothing built in that can do this.
You could write a script that gets the IP address assigned to the DHCP enabled interface and finds the static route based on a comment or the destination IP, and sets that IP as the gateway. Then schedule the script to run every hour (or whatever else timeframe satisfies your requirements).
Something along these lines (written in the post reply box only, not tested) for an interface called ‘interfaceName’ and a destination host of 1.1.1.1/32:
:local IPwithMask [/ip address get [/ip address find interface=interfaceName] address];
:local IP [:pick $IPwithMask 0 [:find $IPwithMask "/" 0]];
/ip route set [/ip route find dst-address="1.1.1.1/32"] gateway="$IP";