Community discussions

MikroTik App
 
keg415
just joined
Topic Author
Posts: 18
Joined: Wed Jan 29, 2025 1:45 am

How to administer backup WAN modem?

Sat Feb 08, 2025 7:13 am

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?
 
jaclaz
Forum Guru
Forum Guru
Posts: 2319
Joined: Tue Oct 03, 2023 4:21 pm

Re: How to administer backup WAN modem?

Sat Feb 08, 2025 6:42 pm

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? :?
 
keg415
just joined
Topic Author
Posts: 18
Joined: Wed Jan 29, 2025 1:45 am

Re: How to administer backup WAN modem?

Sat Feb 08, 2025 8:38 pm

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
}
Last edited by keg415 on Mon Feb 10, 2025 5:22 am, edited 1 time in total.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 22401
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: How to administer backup WAN modem?

Sat Feb 08, 2025 9:31 pm

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 )

+++++++++++++++++++++++
 
keg415
just joined
Topic Author
Posts: 18
Joined: Wed Jan 29, 2025 1:45 am

Re: How to administer backup WAN modem?

Sat Feb 08, 2025 11:09 pm

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.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 22401
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: How to administer backup WAN modem?

Sun Feb 09, 2025 6:32 am

Nope, if it aint broke, dont fix it. Carry on!!