How to run scripts on multi-WAN scenarios on Mikrotik
Overview
To synchronize two or more public IPs simultaneously, you need to create a dedicated Script on your MikroTik device. The scripts below create static routes to force the update through the correct gateway and then safely clear the DNS cache.
Before proceeding, you must add a distinct dynamic network for each WAN connection directly inside your Dashboard Networks menu.
Variables to Replace
Before pasting any script into your terminal, carefully replace the placeholder data with your actual parameters:
- GATEWAY_WAN2, GATEWAY_WAN3... Replace these tags with the actual gateway IP address of your secondary lines.
- USER1, PASS1: Enter the specific username and password assigned to your first dynamic network.
- USER2, PASS2: Enter the specific username and password assigned to your second dynamic network. Do this for all subsequent credentials.
If your dynamic network password contains special characters like $ or ", you must insert the \ symbol before each of those characters in the code.
Scenario: Two WANs
Copy and paste the following code to handle two internet lines:
/ip route remove [find comment=ddns_wan]
/ip route add dst-address=185.236.104.114 gateway=<GATEWAY_WAN2> comment=ddns_wan
:tool fetch url="https://ddns.fsflt.com/nic/update\?hostname=&myip=&wildcard=NOCHG&username=USER1&password=PASS1"
:tool fetch url="https://ddns2.fsflt.com/nic/update\?hostname=&myip=&wildcard=NOCHG&username=USER2&password=PASS2"
/ip route remove [find comment=ddns_wan]
/ip dns cache flushScenario: Three WANs
Copy and paste the following code to handle three internet lines:
/ip route remove [find comment=ddns_wan]
/ip route add dst-address=185.236.104.114 gateway=<GATEWAY_WAN2> comment=ddns_wan
/ip route add dst-address=185.236.104.124 gateway=<GATEWAY_WAN3> comment=ddns_wan
:tool fetch url="https://ddns.fsflt.com/nic/update\?hostname=&myip=&wildcard=NOCHG&username=USER1&password=PASS1"
:tool fetch url="https://ddns2.fsflt.com/nic/update\?hostname=&myip=&wildcard=NOCHG&username=USER2&password=PASS2"
:tool fetch url="https://ddns3.fsflt.com/nic/update\?hostname=&myip=&wildcard=NOCHG&username=USER3&password=PASS3"
/ip route remove [find comment=ddns_wan]
/ip dns cache flushScenario: Four WANs
Copy and paste the following code to handle four internet lines:
/ip route remove [find comment=ddns_wan]
/ip route add dst-address=185.236.104.114 gateway=<GATEWAY_WAN2> comment=ddns_wan
/ip route add dst-address=185.236.104.124 gateway=<GATEWAY_WAN3> comment=ddns_wan
/ip route add dst-address=185.236.104.134 gateway=<GATEWAY_WAN4> comment=ddns_wan
:tool fetch url="https://ddns.fsflt.com/nic/update\?hostname=&myip=&wildcard=NOCHG&username=USER1&password=PASS1"
:tool fetch url="https://ddns2.fsflt.com/nic/update\?hostname=&myip=&wildcard=NOCHG&username=USER2&password=PASS2"
:tool fetch url="https://ddns3.fsflt.com/nic/update\?hostname=&myip=&wildcard=NOCHG&username=USER3&password=PASS3"
:tool fetch url="https://ddns4.fsflt.com/nic/update\?hostname=&myip=&wildcard=NOCHG&username=USER4&password=PASS4"
/ip route remove [find comment=ddns_wan]
/ip dns cache flushFinalizing and Testing
Finally, you need to create a Scheduler in your MikroTik system to automatically run your chosen Script at regular intervals like every minute.
From your Dashboard, open the Networks menu to check the status of your various connections. If everything is configured correctly, you should see the different Public IPs and their active synchronization status.