script to replace IP address in routes

Hi,

I have two internet connections. One with pppoe authentication, the other LTE with a fixed public IP taken from DHCP. I would like to change from a public fixed IP behind the LTE link to a public floating one. But I noticed a problem. As I want to configure in the routing table gateway as the name of the LTE interface, not the IP address, the Internet on the second link does not work. I have read that this is how it works and the gateway address should be specified in the gateway section.

In the case of a link with ppoe there is no such problem, there normally as gateway I have pppoe interface.

Can anyone share a script that will change my gateway address in routes as the IP address on the LTE interface changes ?

Thanks in advance for any help.

You have to create a script that reads the new gateway from the ISP and then manually inserts it into the applicable IP route(s).
Search on the forum been covered a lot.

Should I put this script in the DHCP Client script section? Or in the System/Scripts section ?

I found a working script from user @ekrain. I pasted it into system/scripts added it to the schedule and it works :wink: I changed the values in find interface and find comment, of course.

:local newgw [ip dhcp-client get [find interface=“LTE”] gateway];
:local routegw [/ip route get [find comment=“WAN2”] gateway ];
:if ($newgw != $routegw) do={
/ip route set [find comment=“isp1”] gateway=$newgw;
}

Yup thats pretty common, one identifies the IP route via a unique comment on the IP route line.

I have one but do it in the IP DHCP client section (fiber).
In my case I have two DNS addresses I check for the IP so I have to change two routes and thus have two find rules.
For efficiency sake I could have used the same comment for both routes and only used one find rule. Personal taste.
:if ($bound=1) do={
:local gw $“gateway-address”
/ip route set [ find comment=“PrimaryRecursive” gateway!=$gw ] gateway=$gw
/ip route set [ find comment=“SecondaryRecursive” gateway!=$gw ] gateway=$gw
/tool e-mail send to=“myemail@address.com” subject=([/system identity
get name]) body=" This is your new gateway IP: $gw";
}

In my scenario, in IP DHCP client some additional items.

Add default route=yes
Distance=255