You don't need the script when the gateway address of the ISP does not change (the IP address that they give you might change, but the gateway address is the same). It might be like that for some ISP, but it's more probable that the gateway address does change.
As for the script: You put it in the script property of the DHCP client entry, and the script will be executed both when you get a new leases, or when you lose the current lease. That's why there is first a check for $bound=1.
script (script; Default: ) Execute script when DHCP client obtains a new lease or loses an existing one, received gateway address or DNS server list is changed.
Variables that are accessible for the event script:
- bound - 1 - lease is added/changed; 0 - lease is removed
- server-address - server address
- lease-address - lease address provided by a server
- interface - name of the interface on which the client is configured
- gateway-address - gateway address provided by a server
- vendor-specific - stores value of option 43 received from DHCP server
- lease-options - an array of received options
Because you only need to update the gateway when you get a new lease, not when $bound=0.
At the top of the script a variable is defined that contain the name of the route table that will be updated, but in your case, you only need to update the main table.
The line
:local count [/ip route print count-only where comment="WAN1"]
counts how many route in the table has the WAN1 comment and save the number in the $count variable.
Later you can see this value is compared to 0, if it's zero, then the route is added. In your case, you probably don't need this part, because you have already added the two routes manually by hand, these two routes:
So you won't need to check if $count=0 to add them anymore.
When $count is not 0 then the code in the else branch is executed. Here if $count=1 then:
-
The current route entry with the comment is load into the variable $test:
:local test [/ip route find where comment="WAN1"]
-
Its current gateway value is read and compared to the value of the $"gateway-address" variable passed down by the DHCP client:
:if ([/ip route get $test gateway] != $"gateway-address") do={
-
When they are not the same (the != check) the comment that set the gateway is executed:
/ip route set $test gateway=$"gateway-address"
The script assumes only one route exists with the comment (then the check for $count=1) if there are more, then it raises the error with:
:error "Multiple routes found"
However, in your case, you do have two routes to update, so the whole check with $count=1 is not suitable. Instead you can update all the routes that match the comment, without the need to check for $count=1.
If you put the comment "Fiber recursive" on the two routes with dst-address=8.8.8.8/32 and dst-address=1.1.1.1/32 that I quoted above, then your whole lease script can be simplified to this:
:if ($bound=1) do={
/ip route set [find where comment="Fiber recursive"] gateway=$"gateway-address"
}