Community discussions

MUM Europe 2020
 
rbuserdl
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Thu Mar 22, 2018 1:53 pm

Route not working using interface as gateway

Mon Nov 25, 2019 6:17 pm

Hello,

I recently created some mangle rules because I never could access from outside using the secondary Internet connections
I have one ISP in WAN1 interface and the other in WAN5 interface
If I create the rute, using the default gateway as default gateway it works, but if I set directly WAN5 (the interface) as gateway, it does not work.
Both ISPs give me dynamic IPs and I cant change this, so if I set the route using dg, it wont work when the dg be different
Any Idea?

Just in case I attach the mangle rules and the route created with the interface as gateway:

/ip firewall mangle
add action=mark-connection chain=prerouting connection-mark=no-mark in-interface=WAN1 new-connection-mark=WAN1_conn passthrough=yes
add action=mark-connection chain=prerouting connection-mark=no-mark in-interface=WAN5 new-connection-mark=WAN5_conn passthrough=yes
add action=mark-routing chain=prerouting connection-mark=WAN1_conn dst-address=!192.168.1.0/24 in-interface-list=!WANs new-routing-mark=to__WAN1 \
    passthrough=yes src-address=192.168.1.0/24
add action=mark-routing chain=prerouting connection-mark=WAN5_conn dst-address=!192.168.1.0/24 in-interface-list=!WANs new-routing-mark=to__WAN5 \
    passthrough=yes src-address=192.168.1.0/24
add action=mark-routing chain=output connection-mark=WAN1_conn dst-address=!192.168.1.0/24 new-routing-mark=to__WAN1 passthrough=yes
add action=mark-routing chain=output connection-mark=WAN5_conn dst-address=!192.168.1.0/24 new-routing-mark=to__WAN5 passthrough=yes

/ip route
add check-gateway=ping distance=1 gateway=WAN5 routing-mark=to__WAN5
192.168.1.0/24 is the local network
The route appears as active (in black color) but it does not work.

Regards,
Damián
 
sindy
Forum Guru
Forum Guru
Posts: 4189
Joined: Mon Dec 04, 2017 9:19 pm

Re: Route not working using interface as gateway

Mon Nov 25, 2019 6:41 pm

An interface can only be used as a gateway if it is a point-to-point (tunnel) one (actually, there is a mechanism where routers in a subnet advertise their routing functionality to clients using broadcast ICMP, but it doesn't seem to be working in RouterOS even if the gateway supports it).

So when you want to use the route provided by DHCP at WAN 5 in some other routing table than main, you have to use a script at the dhcp-client to update that route's gateway item each time the DHCP server assigns a new IP address of the gateway, something like:
/ip dhcp-client
add interface=WAN5 script="{\
    \n  :local routeId [/ip route find distance=1 dst-address~\"0.0.0.0/0\" routing-mark=to__WAN5]\
    \n  if ((\$bound=1) and ([ip route get \$routeId gateway]!=\$\"gateway-address\")) do={\
    \n    /ip route set \$routeId gateway=\$\"gateway-address\"\
    \n  }\
    \n}"
As you can see, the default route with routing-mark=to__WAN5 has be created manually in advance, as the script only updates the gateway field of an existing one. So don't remove the route with gateway=WAN5 before adding that script to the DHCP client, it will replace the interface by IP address automatically at the nearest DHCP renewal (which you can enforce using /ip dhcp server release [find interface=WAN5]).

If you want the default route via WAN5 to be available only with a routing-mark, set the add-default-route property of that /ip dhcp client to no.
Last edited by sindy on Mon Nov 25, 2019 10:45 pm, edited 1 time in total.
Instead of writing novels, post /export hide-sensitive. Use find&replace in your favourite text editor to systematically replace all occurrences of each public IP address potentially identifying you by a distinctive pattern such as my.public.ip.1.
 
rbuserdl
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Thu Mar 22, 2018 1:53 pm

Re: Route not working using interface as gateway

Mon Nov 25, 2019 8:00 pm

Sindy, thanks a lot!!!

I didn't know that, but it make sense. I just remembered that sometimes I had used the route with the interface as gateway, but surely that was with a GRE tunnel.
We usually try to avoid scripts to make it easier for everyone (I have co-workers with less knowledge about mikrotik), but I will try your script this time. Do I need to change something in the script or I just need to copy the code in the "Advance" tab, into the "Script" box? (Graphical interface)
I though that because the script says "add", this will create a new route.

Regards,
Damián
 
sindy
Forum Guru
Forum Guru
Posts: 4189
Joined: Mon Dec 04, 2017 9:19 pm

Re: Route not working using interface as gateway

Mon Nov 25, 2019 8:21 pm

The add is for the whole new /ip dhcp-client row because it's a slightly modified export of an existing setup I use in a similar situation, to avoid typos. So remove the existing dhcp-client at WAN5 and then paste the code I gave into a command line window.
Instead of writing novels, post /export hide-sensitive. Use find&replace in your favourite text editor to systematically replace all occurrences of each public IP address potentially identifying you by a distinctive pattern such as my.public.ip.1.
 
rbuserdl
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Thu Mar 22, 2018 1:53 pm

Re: Route not working using interface as gateway

Mon Nov 25, 2019 10:42 pm

Ahhh, sorry, I didnt reallice.
Thanks again!!!
I will test and will let you know.

Regards!
Damián
 
sindy
Forum Guru
Forum Guru
Posts: 4189
Joined: Mon Dec 04, 2017 9:19 pm

Re: Route not working using interface as gateway

Mon Nov 25, 2019 10:47 pm

I've fixed a typo there (one extra underscore).

There is no way to avoid a script here - you cannot set a routing-mark to use when adding teh default route directly into the /ip dhcp-client configuration.
Instead of writing novels, post /export hide-sensitive. Use find&replace in your favourite text editor to systematically replace all occurrences of each public IP address potentially identifying you by a distinctive pattern such as my.public.ip.1.
 
rbuserdl
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Thu Mar 22, 2018 1:53 pm

Re: Route not working using interface as gateway

Wed Dec 04, 2019 9:27 pm

Yes, thank you Sindy,
I did not tell you but I had realliced about the underscore.
I have created the DHCP client with the correction and this changed the route
The IP addess is still the same than before but I trust you ;)

Thanks a lot!
 
sindy
Forum Guru
Forum Guru
Posts: 4189
Joined: Mon Dec 04, 2017 9:19 pm

Re: Route not working using interface as gateway

Wed Dec 04, 2019 10:34 pm

I have created the DHCP client with the correction and this changed the route
The IP addess is still the same than before but I trust you ;)
I'm not sure I understand the remark. If the DHCP server always assigns the same gateway IP address, you don't need the script at DHCP client to update the marked route in configuration, but are you sure the ISP won't ever re-arrange their network?
Instead of writing novels, post /export hide-sensitive. Use find&replace in your favourite text editor to systematically replace all occurrences of each public IP address potentially identifying you by a distinctive pattern such as my.public.ip.1.
 
rbuserdl
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Thu Mar 22, 2018 1:53 pm

Re: Route not working using interface as gateway

Fri Dec 06, 2019 10:50 pm

Hello Sindy,

What I mean is that the default gateway, so far, is the same than before. Maybe the DG will change in the future.
So, I cannot see that your solution is fine, until the DG change, but I believe that this solution will work because were you who gave me this ;)

Thanks again.
Regards,
Damián

Who is online

Users browsing this forum: No registered users and 79 guests