automatic Routingtable script from mikrotik site dosent seem to work

Hi everyone

ill try myself at a loabalcing with 2+ dhcp inet connection based on the Microtik PPC Method.
Martins talks about using DHCP, but adds a preconfigured Gateway on all 3 links, witch makes that a nonsense…
https://www.youtube.com/watch?v=nlb7XAv57tw


So further in the comments the script below from the mikrotik website is mentioned, witch should overcome gateway checking and table creating:
https://help.mikrotik.com/docs/spaces/ROS/pages/24805500/DHCP#DHCP-LeaseScriptExampleLeasescriptexample)




however ill fail greatly on the the table script from mikrotiks website… anyone can help me here?

what do i expect: Getting a table “WAN1”
what happens: getting routes added nicely but always just having a “main” table, no other table is created and thus loadbalancing/failover wont work


Anyone know how to fix that?



thanks for your help!




/ip dhcp-client
add add-default-route=no dhcp-options=hostname,clientid disabled=no interface=ether2 script="{\r\
    \n    :local rmark \"WAN1\"\r\
    \n    :local count [/ip route print count-only where comment=\"WAN1\"]\r\
    \n    :if (\$bound=1) do={\r\
    \n        :if (\$count = 0) do={\r\
    \n            /ip route add gateway=\$\"gateway-address\" comment=\"WAN1\" routing-table=\$rmark\r\
    \n        } else={\r\
    \n            :if (\$count = 1) do={\r\
    \n                :local test [/ip route find where comment=\"WAN1\"]\r\
    \n                :if ([/ip route get \$test gateway] != \$\"gateway-address\") do={\r\
    \n                    /ip route set \$test gateway=\$\"gateway-address\"\r\
    \n                }\r\
    \n            } else={\r\
    \n                :error \"Multiple routes found\"\r\
    \n            }\r\
    \n        }\r\
    \n    } else={\r\
    \n        /ip route remove [find comment=\"WAN1\"]\r\
    \n    }\r\
    \n}\r\
    \n"

There Is seemingly not any provision in the script to create the table, so It must be created before and outside the script.

/routing table add name=WAN1 fib

Hi
Thanks for the hint..
I did the tables for the 4 connections, yet still the routingtable “main” is in used for all :frowning:
i changed the script to fit my table names…

for what is the “interface=ether2” in the second line, the interface the script should check?



/ip dhcp-client
add add-default-route=no dhcp-options=hostname,clientid disabled=no interface=ether2 script="{\r\
    \n    :local rmark \"ISP-SFP+16\"\r\
    \n    :local count [/ip route print count-only where comment=\"ISP-SFP+16\"]\r\
    \n    :if (\$bound=1) do={\r\
    \n        :if (\$count = 0) do={\r\
    \n            /ip route add gateway=\$\"gateway-address\" comment=\"ISP-SFP+16\" routing-table=\$rmark\r\
    \n        } else={\r\
    \n            :if (\$count = 1) do={\r\
    \n                :local test [/ip route find where comment=\"ISP-SFP+16\"]\r\
    \n                :if ([/ip route get \$test gateway] != \$\"gateway-address\") do={\r\
    \n                    /ip route set \$test gateway=\$\"gateway-address\"\r\
    \n                }\r\
    \n            } else={\r\
    \n                :error \"Multiple routes found\"\r\
    \n            }\r\
    \n        }\r\
    \n    } else={\r\
    \n        /ip route remove [find comment=\"ISP-SFP+16\"]\r\
    \n    }\r\
    \n}\r\
    \n"


Screenshots say very little, particularly without context.
Follow the instructions here:
http://forum.mikrotik.com/t/forum-rules/173010/1
and post your configuration, some members may be able to spot where the issue(s) may lie.

Config printed out:


# 2025-02-12 23:07:31 by RouterOS 7.17rc6
# software id = 
#
# model = CRS317-1G-16S+
# serial number = 
/interface bridge
add name=LAN1
add name=LAN2
/interface ethernet
set [ find default-name=ether1 ] name=ether1_remote
set [ find default-name=sfp-sfpplus1 ] name=sfp-sfpplus1_LAN_Bridge1
set [ find default-name=sfp-sfpplus2 ] name=sfp-sfpplus2_LAN_Bridge1
set [ find default-name=sfp-sfpplus3 ] name=sfp-sfpplus3_LAN1
set [ find default-name=sfp-sfpplus4 ] name=sfp-sfpplus4_LAN1
set [ find default-name=sfp-sfpplus5 ] name=sfp-sfpplus5_LAN1
set [ find default-name=sfp-sfpplus6 ] name=sfp-sfpplus6_LAN1
set [ find default-name=sfp-sfpplus7 ] name=sfp-sfpplus7_LAN1
set [ find default-name=sfp-sfpplus8 ] name=sfp-sfpplus8_LAN1
set [ find default-name=sfp-sfpplus9 ] name=sfp-sfpplus9_LAN2
set [ find default-name=sfp-sfpplus10 ] name=sfp-sfpplus10_LAN2
set [ find default-name=sfp-sfpplus11 ] name=sfp-sfpplus11_LAN2
set [ find default-name=sfp-sfpplus12 ] name=sfp-sfpplus12_LAN2
set [ find default-name=sfp-sfpplus13 ] name=sfp-sfpplus13_WAN
set [ find default-name=sfp-sfpplus14 ] name=sfp-sfpplus14_WAN
set [ find default-name=sfp-sfpplus15 ] name=sfp-sfpplus15_WAN
set [ find default-name=sfp-sfpplus16 ] name=sfp-sfpplus16_WAN
/interface bonding
add mode=802.3ad name=Uplink slaves=\
    sfp-sfpplus1_LAN_Bridge1,sfp-sfpplus2_LAN_Bridge1
/interface list
add name=WAN
add name=LAN
add name=Remote
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/port
set 0 name=serial0
/routing table
add disabled=no fib name=ISP-SFP+16
add disabled=no fib name=ISP-SFP+15
add disabled=no fib name=ISP-SFP+14
add disabled=no fib name=ISP-SFP+13
/interface bridge port
add bridge=LAN1 interface=Uplink
add bridge=LAN1 interface=sfp-sfpplus3_LAN1
add bridge=LAN1 interface=sfp-sfpplus4_LAN1
add bridge=LAN1 interface=sfp-sfpplus5_LAN1
add bridge=LAN1 interface=sfp-sfpplus6_LAN1
add bridge=LAN1 interface=sfp-sfpplus7_LAN1
add bridge=LAN1 interface=sfp-sfpplus8_LAN1
add bridge=LAN2 interface=sfp-sfpplus10_LAN2
add bridge=LAN2 interface=sfp-sfpplus11_LAN2
add bridge=LAN2 interface=sfp-sfpplus12_LAN2
add bridge=LAN2 interface=sfp-sfpplus9_LAN2
/ip neighbor discovery-settings
set discover-interface-list=!dynamic
/interface list member
add interface=ether1_remote list=Remote
add interface=sfp-sfpplus1_LAN_Bridge1 list=LAN
add interface=sfp-sfpplus2_LAN_Bridge1 list=LAN
add interface=sfp-sfpplus3_LAN1 list=LAN
add interface=sfp-sfpplus4_LAN1 list=LAN
add interface=sfp-sfpplus5_LAN1 list=LAN
add interface=sfp-sfpplus6_LAN1 list=LAN
add interface=sfp-sfpplus7_LAN1 list=LAN
add interface=sfp-sfpplus8_LAN1 list=LAN
add interface=sfp-sfpplus9_LAN2 list=LAN
add interface=sfp-sfpplus10_LAN2 list=LAN
add interface=sfp-sfpplus11_LAN2 list=LAN
add interface=sfp-sfpplus12_LAN2 list=LAN
add interface=sfp-sfpplus13_WAN list=WAN
add interface=sfp-sfpplus14_WAN list=WAN
add interface=sfp-sfpplus15_WAN list=WAN
add interface=sfp-sfpplus16_WAN list=WAN
add interface=LAN1 list=LAN
add interface=LAN2 list=LAN
add interface=Uplink list=LAN
/ip address
add address=10.0.202.1/24 interface=LAN2 network=10.0.202.0
add address=10.0.201.1/24 interface=LAN1 network=10.0.201.0
/ip dhcp-client
add add-default-route=no comment=Lan_Remote interface=ether1_remote \
    use-peer-dns=no use-peer-ntp=no
# Interface not active
add interface=sfp-sfpplus13_WAN script="/ip dhcp-client\
    \nadd add-default-route=no dhcp-options=hostname,clientid disabled=no inte\
    rface=sfp-sfpplus13_WAN script=\"{\\r\\\
    \n    \\n    :local rmark \\\"ISP-SFP+13\\\"\\r\\\
    \n    \\n    :local count [/ip route print count-only where comment=\\\"IS\
    P-SFP+13\\\"]\\r\\\
    \n    \\n    :if (\\\$bound=1) do={\\r\\\
    \n    \\n        :if (\\\$count = 0) do={\\r\\\
    \n    \\n            /ip route add gateway=\\\$\\\"gateway-address\\\" com\
    ment=\\\"ISP-SFP+13\\\" routing-table=\\\$rmark\\r\\\
    \n    \\n        } else={\\r\\\
    \n    \\n            :if (\\\$count = 1) do={\\r\\\
    \n    \\n                :local test [/ip route find where comment=\\\"ISP\
    -SFP+13\\\"]\\r\\\
    \n    \\n                :if ([/ip route get \\\$test gateway] != \\\$\\\"\
    gateway-address\\\") do={\\r\\\
    \n    \\n                    /ip route set \\\$test gateway=\\\$\\\"gatewa\
    y-address\\\"\\r\\\
    \n    \\n                }\\r\\\
    \n    \\n            } else={\\r\\\
    \n    \\n                :error \\\"Multiple routes found\\\"\\r\\\
    \n    \\n            }\\r\\\
    \n    \\n        }\\r\\\
    \n    \\n    } else={\\r\\\
    \n    \\n        /ip route remove [find comment=\\\"ISP-SFP+13\\\"]\\r\\\
    \n    \\n    }\\r\\\
    \n    \\n}\\r\\\
    \n    \\n\""
# Interface not active
add interface=sfp-sfpplus14_WAN script="/ip dhcp-client\
    \nadd add-default-route=no dhcp-options=hostname,clientid disabled=no inte\
    rface=sfp-sfpplus14_WAN script=\"{\\r\\\
    \n    \\n    :local rmark \\\"ISP-SFP+14\\\"\\r\\\
    \n    \\n    :local count [/ip route print count-only where comment=\\\"IS\
    P-SFP+14\\\"]\\r\\\
    \n    \\n    :if (\\\$bound=1) do={\\r\\\
    \n    \\n        :if (\\\$count = 0) do={\\r\\\
    \n    \\n            /ip route add gateway=\\\$\\\"gateway-address\\\" com\
    ment=\\\"ISP-SFP+14\\\" routing-table=\\\$rmark\\r\\\
    \n    \\n        } else={\\r\\\
    \n    \\n            :if (\\\$count = 1) do={\\r\\\
    \n    \\n                :local test [/ip route find where comment=\\\"ISP\
    -SFP+14\\\"]\\r\\\
    \n    \\n                :if ([/ip route get \\\$test gateway] != \\\$\\\"\
    gateway-address\\\") do={\\r\\\
    \n    \\n                    /ip route set \\\$test gateway=\\\$\\\"gatewa\
    y-address\\\"\\r\\\
    \n    \\n                }\\r\\\
    \n    \\n            } else={\\r\\\
    \n    \\n                :error \\\"Multiple routes found\\\"\\r\\\
    \n    \\n            }\\r\\\
    \n    \\n        }\\r\\\
    \n    \\n    } else={\\r\\\
    \n    \\n        /ip route remove [find comment=\\\"ISP-SFP+14\\\"]\\r\\\
    \n    \\n    }\\r\\\
    \n    \\n}\\r\\\
    \n    \\n\""
# Interface not active
add interface=sfp-sfpplus15_WAN script="/ip dhcp-client\
    \nadd add-default-route=no dhcp-options=hostname,clientid disabled=no inte\
    rface=sfp-sfpplus15_WAN script=\"{\\r\\\
    \n    \\n    :local rmark \\\"ISP-SFP+15\\\"\\r\\\
    \n    \\n    :local count [/ip route print count-only where comment=\\\"IS\
    P-SFP+15\\\"]\\r\\\
    \n    \\n    :if (\\\$bound=1) do={\\r\\\
    \n    \\n        :if (\\\$count = 0) do={\\r\\\
    \n    \\n            /ip route add gateway=\\\$\\\"gateway-address\\\" com\
    ment=\\\"ISP-SFP+15\\\" routing-table=\\\$rmark\\r\\\
    \n    \\n        } else={\\r\\\
    \n    \\n            :if (\\\$count = 1) do={\\r\\\
    \n    \\n                :local test [/ip route find where comment=\\\"ISP\
    -SFP+15\\\"]\\r\\\
    \n    \\n                :if ([/ip route get \\\$test gateway] != \\\$\\\"\
    gateway-address\\\") do={\\r\\\
    \n    \\n                    /ip route set \\\$test gateway=\\\$\\\"gatewa\
    y-address\\\"\\r\\\
    \n    \\n                }\\r\\\
    \n    \\n            } else={\\r\\\
    \n    \\n                :error \\\"Multiple routes found\\\"\\r\\\
    \n    \\n            }\\r\\\
    \n    \\n        }\\r\\\
    \n    \\n    } else={\\r\\\
    \n    \\n        /ip route remove [find comment=\\\"ISP-SFP+15\\\"]\\r\\\
    \n    \\n    }\\r\\\
    \n    \\n}\\r\\\
    \n    \\n\""
add interface=sfp-sfpplus16_WAN script="/ip dhcp-client\
    \nadd add-default-route=no dhcp-options=hostname,clientid disabled=no inte\
    rface=ether2 script=\"{\\r\\\
    \n    \\n    :local rmark \\\"ISP-SFP+16\\\"\\r\\\
    \n    \\n    :local count [/ip route print count-only where comment=\\\"IS\
    P-SFP+16\\\"]\\r\\\
    \n    \\n    :if (\\\$bound=1) do={\\r\\\
    \n    \\n        :if (\\\$count = 0) do={\\r\\\
    \n    \\n            /ip route add gateway=\\\$\\\"gateway-address\\\" com\
    ment=\\\"ISP-SFP+16\\\" routing-table=\\\$rmark\\r\\\
    \n    \\n        } else={\\r\\\
    \n    \\n            :if (\\\$count = 1) do={\\r\\\
    \n    \\n                :local test [/ip route find where comment=\\\"ISP\
    -SFP+16\\\"]\\r\\\
    \n    \\n                :if ([/ip route get \\\$test gateway] != \\\$\\\"\
    gateway-address\\\") do={\\r\\\
    \n    \\n                    /ip route set \\\$test gateway=\\\$\\\"gatewa\
    y-address\\\"\\r\\\
    \n    \\n                }\\r\\\
    \n    \\n            } else={\\r\\\
    \n    \\n                :error \\\"Multiple routes found\\\"\\r\\\
    \n    \\n            }\\r\\\
    \n    \\n        }\\r\\\
    \n    \\n    } else={\\r\\\
    \n    \\n        /ip route remove [find comment=\\\"ISP-SFP+16\\\"]\\r\\\
    \n    \\n    }\\r\\\
    \n    \\n}\\r\\\
    \n    \\n\""
/ip dhcp-server network
add address=10.201.0.0/24 dns-server=10.201.0.1 gateway=10.201.0.1 netmask=24 \
    ntp-server=10.201.0.1 wins-server=10.201.0.1
add address=10.202.0.0/24 dns-server=10.202.0.1 gateway=10.202.0.1 netmask=24 \
    ntp-server=10.202.0.1 wins-server=10.202.0.1
/ip firewall nat
add action=masquerade chain=srcnat out-interface-list=WAN
/system clock
set time-zone-name=Europe/Zurich
/system identity
set name="Internet Loadbalancer"
/system note
set show-at-login=no
/system swos
set static-ip-address=10.0.200.1

Hi All
Found the ssue..

Besides the hint from jaclaz that i had to create the tables manually, i also had to feed the script in to the console without an existing dhcp client on the interface i wanted it to run on..
the script then made the dhcp client and now it works also with putting things in the right table :slight_smile: