Community discussions

 
christianrodher
just joined
Topic Author
Posts: 17
Joined: Thu Apr 09, 2015 9:26 pm

2 wan... switch between when no internet.

Mon Apr 30, 2018 1:42 am

i have 2 wan connections. I want the Mikrotik router to switch from 1 to the other when it fails to get internet access.

wan conections:
ether 1 = dhcp client for a cable modem/router (ip = 192.168.0.1/24) >>>>>>>>>> main internet connection
ether 2 = dhcp client for a dsl modem/router (ip = 10.0.0.138/24) >>>>>>>>>>>>> secondary internet connection

I want this:
If internet connection of cable modem/router goes down it switches to dsl modem/router and if the cable modem/router internet connection comes back it switch again to it.

can anyone help?
 
User avatar
mitchmitchell
just joined
Posts: 22
Joined: Fri Sep 22, 2017 11:05 pm

Re: 2 wan... switch between when no internet.

Mon Apr 30, 2018 2:03 am

i have 2 wan connections. I want the Mikrotik router to switch from 1 to the other when it fails to get internet access.

wan conections:
ether 1 = dhcp client for a cable modem/router (ip = 192.168.0.1/24) >>>>>>>>>> main internet connection
ether 2 = dhcp client for a dsl modem/router (ip = 10.0.0.138/24) >>>>>>>>>>>>> secondary internet connection

I want this:
If internet connection of cable modem/router goes down it switches to dsl modem/router and if the cable modem/router internet connection comes back it switch again to it.

can anyone help?
I don't have the answer but I'd be interested in how to do this as well - one of the areas RouterOS *appears* to be a bit weak is in triggering events based on network changes, and I can think of several things I'd like to do if someone can explain how to trigger scripts when things like this occur.

Sent from my SM-N950U using Tapatalk

 
anav
Forum Guru
Forum Guru
Posts: 3122
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada

Re: 2 wan... switch between when no internet.

Mon Apr 30, 2018 3:35 am

That is not to difficult

IP Route
destination=0.0.0.0/0 gateway=gatewayIP (of primary WAN) ping gateway distance=1 (to be clear these are gateway IPs of the ISP, not the WANIP the ISP has assigned to your).
destination=0.0.0.0/0 gateway=gatewayIP (of secondary WAN) distance=2

Thats it.
The router will use the primary WAN having the shortest distance and the ping will ensure the second gateway is used if the primary fails and also will return traffic to the primary when its back up.

If you want to get more complex one can check external WANIPs like opendns and google for the ping check because some apparently paranoid folks here often have a situation where the gateway is working/up but the connection beyond that provided by the ISP is not. The rules are bit more complex but not too daunting.

In my case my email is with the older ISP and in my setup WAN2, so all I had to do was make a third route rule.
destination="ipaddress_of_email_server" gateway=gatewayIP (of my WAN2)

The router will ensure that the email traffic gets out WAN2 (mainly because the PC resolves the smtp domain name to an IP address first, and then sends the email through the router and which point the router can then match the best fit for routing purposes.
I'd rather manage rats than software. Follow my advice at your own risk! (Sob & mkx forced me to write that!)
 
2frogs
Long time Member
Long time Member
Posts: 540
Joined: Fri Dec 03, 2010 1:38 am

Re: 2 wan... switch between when no internet.

Mon Apr 30, 2018 4:05 am

That is not to difficult

IP Route
destination=0.0.0.0/0 gateway=gatewayIP (of primary WAN) ping gateway distance=1 (to be clear these are gateway IPs of the ISP, not the WANIP the ISP has assigned to your).
destination=0.0.0.0/0 gateway=gatewayIP (of secondary WAN) distance=2

Thats it.
Almost! You will also need to set add-default-route=no in your dhcp-clients.

And as anav stated, you can route a certain IP out your primary wan and use netwatch to log the change or send an email to let you know it has changed. You can also use this to change the distance in such cases that the gateway ip is available, but not beyond.
 
christianrodher
just joined
Topic Author
Posts: 17
Joined: Thu Apr 09, 2015 9:26 pm

Re: 2 wan... switch between when no internet.

Mon Apr 30, 2018 4:29 am

That is not to difficult

IP Route
destination=0.0.0.0/0 gateway=gatewayIP (of primary WAN) ping gateway distance=1 (to be clear these are gateway IPs of the ISP, not the WANIP the ISP has assigned to you.
If I disconect the coax cable from my cable modem/router (wan1)... it wont change to the dsl connection (wan2)....

I want to check 8.8.8.8 from wan1... when 8.8.8.8 don't respond from wan1 it needs to switch to wan2... and when 8.8.8.8 respond again from wan1 it needs to switch back.

Sorry if i didnt explain correctly in first post.
 
anav
Forum Guru
Forum Guru
Posts: 3122
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada

Re: 2 wan... switch between when no internet.

Mon Apr 30, 2018 5:17 am

Okay so you are not content with the simple plan to check the gateway of your ISP, part of the paranoid crowd that thinks checking an external IP is better.
Okay, I have never experienced when the gateway was up but the rest of the network is down but I will attempt to be open minded. :-)

(by the way twoFrogs, yes it is important for the ISP setup in DHCP Client menu, to uncheck the default route - good point!)

Okay my friend, this is hopefully close to the mark......
/ip route
add dst-address=Host1(8.8.8.8) gateway=gatewayIP (of primary ISP)
add dst-address=Host2(208.67.222.222) gateway=gatewayIP (of primary ISP)
add dst-address=Host3(8.8.4.4) gateway=gatewayIP (of secondary ISP)
add dst-address=Host4(208.67.220.220) gateway=gatewayIP (of secondary ISP)

/ip route
add distance=1 gateway=Host1(8.8.8.8) check-gateway=ping
add distance=2 gateway=Host2(208.67.222.222) check-gateway=ping
add distance=3 gateway=Host3(8.8.4.4) check-gateway=ping
add distance=4 gateway=Host4(208.67.220.220) check-gateway=ping

/Ip route
add destination=0.0.0.0/0 gateway IP (ISP Primary) distance=1
add destination= 0.0.0.0/0 gateway IP(ISP Secondary) distance=2

I think, that what will happen above is that the router will check that all the hosts are available.
If for some reason 8.8.8.8 is not available the router will check .222 to ensure WAN1 is still the primary go to wan.
If both of those are unavailable, the router will use WAN 2 assuming 8.8.4.4 or .220 are pingable.
I'd rather manage rats than software. Follow my advice at your own risk! (Sob & mkx forced me to write that!)
 
2frogs
Long time Member
Long time Member
Posts: 540
Joined: Fri Dec 03, 2010 1:38 am

Re: 2 wan... switch between when no internet.

Mon Apr 30, 2018 5:58 am

/ip route
add gateway=gateway1ip distance=1 comment=WAN1
add gateway=gateway2ip distance=2 comment=WAN2
add dst-address=8.8.8.8/32 gateway=gateway1ip

/tool netwatch
add down-script="/ip route set [find where comment=\"WAN1\"] distance=3;\r\
    \n:log warning \"WAN1 down, switching to WAN2\"" host=8.8.8.8 up-script="/ip\
    \_route set [find where comment=\"WAN1\"] distance=1;\r\
    \n:log warning \"WAN1 restored\""
There is no paranoia when you are double-natted/cgnat or when your service provider suffers equipment malfunction or a contractor somewhere cuts a fiber line.
 
christianrodher
just joined
Topic Author
Posts: 17
Joined: Thu Apr 09, 2015 9:26 pm

Re: 2 wan... switch between when no internet.

Mon Apr 30, 2018 1:04 pm

anav
Thanks i will try it tonight.
2frogs
Exactly my case... I can put the cable modem/router in bridge mode and get the correct gateway in my mikrotik, but if anyone resets it i have to do it again.
I havent found a way to do it in a dsl modem/router since it gets conected to the internet by some ppp throught the telephone line..

In both cases if the internet drops for random reason (contanly happens in Puerto Rico after hurricane Maria) my mikrotik retains the same gateway...

Hopefully what
anav
posted works... ill post again tonight. thanks!
2frogs
you also posted a way. im trying it too.
 
christianrodher
just joined
Topic Author
Posts: 17
Joined: Thu Apr 09, 2015 9:26 pm

Re: 2 wan... switch between when no internet.

Mon Apr 30, 2018 1:30 pm

/ip route
add gateway=gateway1ip distance=1 comment=WAN1
add gateway=gateway2ip distance=2 comment=WAN2
add dst-address=8.8.8.8/32 gateway=gateway1ip

/tool netwatch
add down-script="/ip route set [find where comment=\"WAN1\"] distance=3;\r\
    \n:log warning \"WAN1 down, switching to WAN2\"" host=8.8.8.8 up-script="/ip\
    \_route set [find where comment=\"WAN1\"] distance=1;\r\
    \n:log warning \"WAN1 restored\""
There is no paranoia when you are double-natted/cgnat or when your service provider suffers equipment malfunction or a contractor somewhere cuts a fiber line.
works flawlessly!!! Thanks man!

anav thanks to you also. it also works and check multiple host!
 
anav
Forum Guru
Forum Guru
Posts: 3122
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada

Re: 2 wan... switch between when no internet.

Mon Apr 30, 2018 2:37 pm

1. I dont like using scripts unless I understand what they are doing.'
In other words I like to see the breakdown line by line of what functionally each command is performing.
For example I am unfamiliar with IP Route Set? How does distance=3 have to do with anything, what is the function of /r/
and on and on and on

2. the script solution does nothing to check availability of WAN2.

Finally, 2 frogs can you add in the second host as I am paranoid that google is sometimes down too and want to have an open dns server checked as well.
208.67.220.220

/ip route
add gateway=gateway1ip distance=1 comment=WAN1
add gateway=gateway2ip distance=2 comment=WAN2
add dst-address=8.8.8.8/32 gateway=gateway1ip
add dst-address=208.67.220.220/32=gateway1ip

how is your script modified??????
/tool netwatch
add down-script="/ip route set [find where comment=\"WAN1\"] distance=3;\r\
\n:log warning \"WAN1 down, switching to WAN2\"" host=8.8.8.8 up-script="/ip\
\_route set [find where comment=\"WAN1\"] distance=1;\r\
\n:log warning \"WAN1 restored\""
I'd rather manage rats than software. Follow my advice at your own risk! (Sob & mkx forced me to write that!)
 
2frogs
Long time Member
Long time Member
Posts: 540
Joined: Fri Dec 03, 2010 1:38 am

Re: 2 wan... switch between when no internet.

Tue May 01, 2018 5:11 am

For example I am unfamiliar with IP Route Set?
"Set" is CLI Command that lets you set (or change) a parameters value. In this case we are setting distance=3 for IP>Route>the route with WAN1 in comments.
How does distance=3 have to do with anything
Serves the same purpose as the distance settings that you provided. Routes with equal destination are next determined to be active by the lower distance. Changing WAN1 distance from 1 to 3 makes WAN2 distance now the lower distance and it will now be the active route. If you were to simply disable the route, the netwatch could never determine if 8.8.8.8 is available again and return WAN1 to be active.
what is the function of /r/
The "\" (\ = line break) and "\r\" (\r\ = return) are extra annotation created by /export.
up=
/ip route set [find where comment="WAN1"] distance=1;
:log warning "WAN1 restored"

down=
/ip route set [find where comment="WAN1"] distance=3;
:log warning "WAN1 down, switching to WAN2"
the script solution does nothing to check availability of WAN2.
For a simple failover, does it really matter is WAN2 availability is checked. If they are both down you have, you still will not have Internet. If you wanted to log that they are both down or need something else to happen, a second netwatch for WAN2 would be in order.
Finally, 2 frogs can you add in the second host as I am paranoid that google is sometimes down too and want to have an open dns server checked as well. 208.67.220.220
change the down script to:
:if ([/ping 208.67.220.220 count=5] = 0) do={/ip route set [find where comment="WAN1"] distance=3;
:log warning "WAN1 down, switching to WAN2"}
This may not be best as the scripts only get run once on down or up... writing a script for scheduler to check multiple IP's would be best.
 
anav
Forum Guru
Forum Guru
Posts: 3122
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada

Re: 2 wan... switch between when no internet.

Tue May 01, 2018 2:01 pm

Thanks for the explanation but it went zing....... over my head. Perhaps over time I will learn enough to understand.
Part of the problem is I have no clue what tool netwatch does.........
I'd rather manage rats than software. Follow my advice at your own risk! (Sob & mkx forced me to write that!)
 
2frogs
Long time Member
Long time Member
Posts: 540
Joined: Fri Dec 03, 2010 1:38 am

Re: 2 wan... switch between when no internet.

Tue May 01, 2018 2:50 pm

Netwatch
In learning RouterOS, Google is your friend! Just be leary of results not on official Mikrotik sites.

Who is online

Users browsing this forum: No registered users and 34 guests