Page 1 of 1

How to administer backup WAN modem?

Posted: Sat Feb 08, 2025 7:13 am
by keg415
I'm setting up an hAP ax2 with dual WAN failover. A Netgear LM1200 modem is on ether2, configured with a DHCP client. The DHCP client script updates the gateway for a route:
:if ($bound=1) do={
	/ip route set [find where comment="dhcp2"] gateway=$"gateway-address" disabled=no
	/ip route set [find where comment="LM1200"] gateway=$"gateway-address" disabled=no
} else={
	/ip route set [find where comment="dhcp2"] disabled=yes
	/ip route set [find where comment="LM1200"] disabled=yes
}
I can access the admin service for the LM1200 at its gateway IP address; however, I need to set up a static IP address, 10.1.10.106, since the gateway address is variable. But adding the route:
#     DST-ADDRESS       GATEWAY        DISTANCE
;;; LM1200
4  As 10.1.10.106/32    x.y.z.1          1
and the static IP:
#    ADDRESS        MAC-ADDRESS        INTERFACE
 23  C 10.1.10.106    6E:CD:D6:53:30:8E  ether2   

isn't working. What am I missing?

Re: How to administer backup WAN modem?

Posted: Sat Feb 08, 2025 6:42 pm
by jaclaz
The way I read the route you posted is:
to reach the IP address 10.1.10.106/32 you have to go through gateway x.y.z.1
But 10.1.10.106 is assigned to ether2? :?

Re: How to administer backup WAN modem?

Posted: Sat Feb 08, 2025 8:38 pm
by keg415
Right, I had things backward, and only one route is needed:
#     DST-ADDRESS       GATEWAY        DISTANCE
;;; LM1200
4  As 192.168.5.0/24    26.236.232.1          1
This allows the LM1200 management console to be accessed at its default IP, 192.168.5.1.

This script on the WAN2 DHCP client updates the gateway addresses:
# dhcp2 DHCP client script
# See: https://forum.mikrotik.com/viewtopic.php?t=181447

:if ($bound=1) do={
	/ip route set [find where comment="dhcp2"] gateway=$"gateway-address" disabled=no
	/ip route set [find where comment="LM1200"] gateway=$"gateway-address" disabled=no
} else={
	/ip route set [find where comment="dhcp2"] disabled=yes
	/ip route set [find where comment="LM1200"] disabled=yes
}

Re: How to administer backup WAN modem?

Posted: Sat Feb 08, 2025 9:31 pm
by anav
Im a bit confused by the approach.
Why are you putting script on LAN subnets DHCP when the proper place to address routing is the WANs??

Is it that you want users to always use the primary and if that is not available then use the backup WAN??
This is one of the common approaches and would look like so...

/ip route
add check-gateway=ping distance=1 dst-address=0.0.0.0/0 gateway=(current)PrimaryGateway-IP routing-table=main
add distance=2 dst-address=0.0.0.0/0 gateway=(current)BackupGateway-IP routing-table=main


In this setup, all users will always go out WAN1, unless its not reachable and traffic diverted to WAN2, until WAN1 comes back online.

The only reason for scripts is if the the ISP WANs, do not update the gateway IP automatically when the IP changes ( assuming dynamic WANIPs of course )

+++++++++++++++++++++++

Re: How to administer backup WAN modem?

Posted: Sat Feb 08, 2025 11:09 pm
by keg415
Im a bit confused by the approach.
Why are you putting script on LAN subnets DHCP when the proper place to address routing is the WANs??

Is it that you want users to always use the primary and if that is not available then use the backup WAN??
...
Yes. I followed these videos on recursive routing:
Full MikroTik MTCRE - Recursive Routing (Easy Automatic failover)
Recursive Routing + Failover - Mikrotik RouterOS v7
and added DHCP from this post: viewtopic.php?t=181447

The scripts are on the WAN client DHCPs.

Here's the full route list:
Flags: D - DYNAMIC; A - ACTIVE; c - CONNECT, s - STATIC
Columns: DST-ADDRESS, GATEWAY, DISTANCE
#     DST-ADDRESS       GATEWAY        DISTANCE
;;; WAN1_default
0  As 0.0.0.0/0         1.1.1.1               1
;;; WAN2_default
1   s 0.0.0.0/0         9.9.9.9               2
  DAc 10.1.10.0/24      bridge                0
  DAc 26.236.232.0/24   ether2                0
;;; LM1200
2  As 192.168.5.0/24    26.236.232.1          1
  DAc 158.51.83.128/25  ether1                0
;;; dhcp1
3  As 1.1.1.1/32        158.51.83.129         1
;;; dhcp2
4  As 9.9.9.9/32        26.236.232.1          1
Here's the DHCP client script for WAN1:
# dhcp1 DHCP client script
# See: https://forum.mikrotik.com/viewtopic.php?t=181447

:if ($bound=1) do={
	/ip route set [find where comment="dhcp1"] gateway=$"gateway-address" disabled=no
} else={
	/ip route set [find where comment="dhcp1"] disabled=yes
}
It works. Is there a reason to change? Thanks.

Re: How to administer backup WAN modem?

Posted: Sun Feb 09, 2025 6:32 am
by anav
Nope, if it aint broke, dont fix it. Carry on!!