Using Grok , I got the following script . Can anyone confirm if this is correct? Also would this script interrupt my L2TP connection while it runs the process of replacing the Route ?
/system script
add name=updateRoute source={
# Resolve the domain name to an IP address
:local domain "s1.l2tpserver.com"
:local resolvedIP
:do {
:set resolvedIP [:resolve $domain]
} on-error={
:log error "Failed to resolve $domain"
:return
}
# Check if IP was resolved successfully, stop if not
:if ([:len $resolvedIP] = 0) do={
:log error "No IP resolved for $domain"
:return
}
# Log successful resolution
:log info "Resolved $domain to $resolvedIP"
# Remove all existing IP routes
/ip route
remove [find]
# Add the new route (example: set resolved IP as gateway)
# Modify the dst-address, gateway, or other parameters as needed
add distance=1 dst-address=$resolvedIP/32 gateway=192.168.1.1 comment="Route to $domain"
:log info "Routes updated successfully"
}
I have to metion that the following route is the only route I have so removing all routes with the above script , won’t remove any other needed route:
/ip route
add distance=1 dst-address=62.62.62.62/32 gateway=192.168.1.1