Community discussions

MikroTik App
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 19100
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

SCRIPT not Working ??

Tue Mar 09, 2021 12:51 am

The script should check when the dhcp client is bound, if the new gateway matches the primary recursive ip route gateway.
If not its supposed to set both the primary recursive and secondary recursive gatewayIPs to the newgateway IP.
:if (\$bound=1) do={
:local newgw $"gateway-address";
:local routegw [/ip route get [find comment="PrimaryRecursive"] gateway ];
:if ($newgw != $routegw) do={
/ip route set [find comment="PrimaryRecursive"] gateway=$newgw;
/ip route set [find comment="SecondaryRecursive"] gateway=$newgw;
/tool e-mail send to="llamaworks@accesswave.ca" subject=([/system identity
get name]) body=" This is your new gateway IP: $newIgw" start-tls=yes;
}
}
Test: Go to ip routes, change recursive Primary Gateway and Secondary gateway IPs to invalid numbers.
Go to dhcp client hit release and renew.
Results: The new gateway IP was NOT transferred to the IP Route primary and secondary recursive routings. ??????????????

CONFIG INFO
/ip route
add check-gateway=ping distance=3 gateway=1.0.0.1
add check-gateway=ping distance=4 gateway=9.9.9.9
add comment=SecondaryWAN distance=10 gateway=seondaryGW_ip
add comment=PrimaryRecursive distance=3 dst-address=1.0.0.1/32 gateway=\
    primaryGW_ip scope=10
add comment=SecondaryRecursive distance=4 dst-address=9.9.9.9/32 gateway=\
    primaryGW_IP scope=10
add comment=Email_bypass distance=1 dst-address=24.222.0.20/32 gateway=\
    secondaryGW_ip
/ip dhcp-client
add comment=BellFibre default-route-distance=255 disabled=no interface=vlanbell\
    script="\r\
    \n:if (\\\$bound=1) do={\r\
    \n:local newgw \$\"gateway-address\";\r\
    \n:local routegw [/ip route get [find comment=\"PrimaryRecursive\"] gatewa\
    y ];\r\
    \n:if (\$newgw != \$routegw) do={\r\
    \n/ip route set [find comment=\"PrimaryRecursive\"] gateway=\$newgw;\r\
    \n/ip route set [find comment=\"SecondaryRecursive\"] gateway=\$newgw;\r\
    \n/tool e-mail send to=\"email@address.com\" subject=([/system iden\
    tity\r\
    \nget name]) body=\" This is your new gateway IP: \$newIgw\" start-tls=yes\
    ;\r\
    \n}\r\
    \n}\r\
    \n"
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 19100
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: SCRIPT not Working ??

Tue Mar 09, 2021 5:33 pm

Found a script that works, thanks to Chupaka's thread.
:if ($bound=1) do={
:local iface $interface
:local gw [ /ip dhcp-client get [ find interface=$"iface" ] gateway ]
/ip route set [ find comment="PrimaryRecursive" gateway!=$gw ] gateway=$gw
/ip route set [ find comment="SecondaryRecursive" gateway!=$gw ] gateway=$gw
}

Who is online

Users browsing this forum: No registered users and 18 guests