Community discussions

MikroTik App
 
Macme
newbie
Topic Author
Posts: 36
Joined: Fri Apr 22, 2016 3:13 pm

Autofail over with 2isp dynamic ip

Fri Jan 14, 2022 5:45 pm

Hello,
I was looking here and there is nothing or I can't find it so if someone can point me where to find it.
What I have a hap rb, and I need to connect 2 gsm modem and if one goes down the second one take all traffic.
I have found some scripts but all is for static ip adresses. My booth ISP have dynamic Ip, so I don't know how to do that with dynamic IP from ISP.
So situation is like this:

1 ISP modem----- dynamic IP
---mikrotik Hap------lan users
2 ISP modem-----dynamic IP

Thank you
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19325
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Autofail over with 2isp dynamic ip  [SOLVED]

Fri Jan 14, 2022 5:51 pm

typical basic situation
dst-address=0.0.0.0/0 gwy=gatewayof ISP1 check-gateway=ping distance=5
dst-address=0.0.0.0/0 gwy=gatewayof ISP2 distance=10


What this does is choose is force the router to use ISP one due to a shorter distance marking,
the router will continually ping to make sure the gateway is up.
If it goes down then it will switch to the second connection but keep checking to see if the first one is backup yet.
 
aesmith
Member Candidate
Member Candidate
Posts: 264
Joined: Wed Mar 27, 2019 6:43 pm

Re: Autofail over with 2isp dynamic ip

Fri Jan 14, 2022 5:59 pm

This method does not rely on a fixed IP address from the ISPs, but it does rely on their gateway addresses being fixed. If the gateway is dynamic as well, and issued to you by DHCP or LCP or something then I don't think the normal method can be used.
 
Macme
newbie
Topic Author
Posts: 36
Joined: Fri Apr 22, 2016 3:13 pm

Re: Autofail over with 2isp dynamic ip

Fri Jan 14, 2022 6:15 pm

Thanks guys ,
I thing the gateway is dynamic too. So this solution is not good or it is?
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19325
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Autofail over with 2isp dynamic ip

Fri Jan 14, 2022 6:17 pm

In that case, perhaps a script in the DHCP client settings is the way to go.......
Along with what was provided above.

I have no idea what this does but it is one OPTION I have seen. Its is put in the IP DHCP client advanced settings.........

:local count [ /ip route print count-only where dst-address=0.0.0.0/0 routing-mark=$rmark ]
:if ($bound=1) do={
:local iface $interface
:local gw [ /ip dhcp-client get [ find interface=$"iface" ] gateway ]
:set gw "$gw%$iface"
:if ($count=0) do={
/ip route add gateway=$gw routing-mark=$rmark
} else={
if ($rmark="main") do={
/ip route set [ find dst-address=0.0.0.0/0 !routing-mark gateway!=$gw ] gateway=$gw
} else={
/ip route set [ find dst-address=0.0.0.0/0 routing-mark=$rmark gateway!=$gw ] gateway=$gw
}
}
} else={
:if ($rmark="main") do={
/ip route remove [ find dst-address=0.0.0.0/0 !routing-mark gateway~"%$interface\$" ]
} else={
/ip route remove [ find dst-address=0.0.0.0/0 routing-mark=$rmark type=unicast ]
}
}


+++++++++++++++++++++++++++++++
 
Sob
Forum Guru
Forum Guru
Posts: 9121
Joined: Mon Apr 20, 2009 9:11 pm

Re: Autofail over with 2isp dynamic ip

Fri Jan 14, 2022 6:21 pm

Or much simpler version of that, add everything as if it was static config, mark route(s) using unique comments, and then use lease script to only update gateway. Example:

viewtopic.php?p=898546#p898546
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19325
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Autofail over with 2isp dynamic ip

Fri Jan 14, 2022 6:35 pm

Okay lets parse that out................ with some modifications........

/ip route add dst-address=0.0.0.0/0 gateway=dynamicWANIP1 comment="dhcp1" table=main
/ip route add dst-address=0.0.0.0/0 gateway=dynamicWANIP2 comment="dhcp2" table=main


Then GO the the respective IP DHCP Client settings and set add-default-route=no for dhcp client and use lease script to update the route you added
For WAN1
: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
}
FOR WAN2
:if ($bound=1) do={
  /ip route set [find where comment="dhcp2"] gateway=$"gateway-address" disabled=no
} else={
  /ip route set [find where comment="dhcp2"] disabled=yes
}

Every time the IP is bound, the new gateway will be inserted into the IP route.
 
Macme
newbie
Topic Author
Posts: 36
Joined: Fri Apr 22, 2016 3:13 pm

Re: Autofail over with 2isp dynamic ip

Fri Jan 14, 2022 6:43 pm

thank you, for your help, I will try your advice, I am not an expert so a will give a try if will success will let you know, Not sure if all understood but you gave me a good start point
thank you,
 
Macme
newbie
Topic Author
Posts: 36
Joined: Fri Apr 22, 2016 3:13 pm

Re: Autofail over with 2isp dynamic ip

Wed Jan 19, 2022 6:23 pm

Hello,
Thanks all of you guy but I'm really struggling with all configuration, I am not sure but there is many way to achieve the goal.
I am little bit confused in all that, can you explain me what all I have to do for it. We can make an agreement too, so please if someone can help.
Thank you
 
Macme
newbie
Topic Author
Posts: 36
Joined: Fri Apr 22, 2016 3:13 pm

Re: Autofail over with 2isp dynamic ip

Tue Feb 08, 2022 3:56 pm

Thanks to "anav"


He solved my problem and be a big help.
Thank you all guys too.

anav thank you once again
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19325
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Autofail over with 2isp dynamic ip

Tue Feb 08, 2022 6:30 pm

Thanks to "anav"


He solved my problem and be a big help.
Thank you all guys too.

anav thank you once again
No worries, I dedicate my assistance to the good people of Ukraine, if we could just all get along and help one another!!!

Who is online

Users browsing this forum: GoogleOther [Bot] and 81 guests