Dynamic WAN address from ISP with unavailable route

Hello everyone, I have a problem with how RouterOS handles the dynamic address my ISP gives to my Mikrotik routerboard.

The problem is that the address from DHCP is something like 96.2.3.4/8 and the default gateway from the same DHCP is like 213.4.5.6. As you can see, the default gateway is outside of the IP address network given by the same DHCP.

This seems to be a fairly common issue with some ISP, and I have found a rather dirty workaround: I added a static default route to 96.1.1.1 (a random IP in the assigned network) and configured dhcp-client in order to not add the gateway provided by DHCP. This works because the cable modem reports the same MAC address for the real gateway and the bogus one.

This workaround is very weak: it only works if the ISP always assign addresses from 96.0.0.0/8 network (because of the static route).

I know that some routers have the same problem (for example Tp-link) but some others handle this situation without an hiccup. It would be great if Mikrotik could implement a fix, or suggest a better workaround.

Thanks!

I solved by using this script, scheduled to run every 10 seconds:

if ( [:len [/ip dhcp-client find status="bound"]] = 1 ) do={
           :local ipmask [/ip dhcp-client get [find status="bound"] address]
           :local ip [:pick $ipmask 0 [:find $ipmask "/"]]
           :local gw [/ip dhcp-client get [find status="bound"] gateway]
       
           :if ( [:len [/ip address find interface="ether1-gateway" address="$ip/32" network="$gw"]] = 0 ) do={
               :if ( [:len [/ip address find comment="P2P"]] > 0 ) do={
                   :log info "Removing stale P2P address"
                   /ip address remove [find comment="P2P"]
               }
               :log info "Adding P2P address $ip/32 network $gw"
               /ip address add interface="ether1-gateway" address="$ip/32" network="$gw" comment="P2P"
           }
       } else={
           :put "Not bound"
           :if ( [:len [/ip address find comment="P2P"]] > 0 ) do={
               :log info "Removing stale P2P address"
               /ip address remove [find comment="P2P"]
           }
       }

Is the default gateway always the same?

GW is acquired via DHCP (that’s the default for dhcp-client configuration), the script only manages the missing direct route between dynamic IP and GW that are on different networks.

That’s why I’m asking. Does the DHCP client get always the same gateway?

In my specific case, until now, yes. Only the dynamic IP changes.

But when writing the script I assumed that the GW could change.

The only corner case that probably is not covered is when the GW is in the same subnet of the dynamic IP, in this case the script should have no use.

Just to make it clear: the script replaces the workaround described in the first post (no need to add the bogus gateway 96.1.1.1)

Linux has an option when adding a route, “onlink”, to skip the check that the gateway is to be within the subnet.
Unfortunately it does not appear in the options available when setting a route via the MikroTik user interface.
They probably have good reasons for this, maybe there is some conflict with other functionality that MikroTik
have built on top of the existing Linux mechanisms (e.g. VRF), but sometimes it is inconvenient.
This issue is also apparent when trying to build a multipoint VPN…