---
title: How to run scripts on multi-WAN scenarios on Mikrotik
slug: how-to-run-scripts-on-multi-wan-scenarios-on-mikrotik
description: Learn how to effectively synchronize multiple public IPs on a MikroTik router with our step-by-step guide. This document covers essential scripts for managing routing and DNS updates for each WAN connection. 
docTags: 
createdAt: 2024-02-05T13:06:42.769Z
---

## 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.

:::hint{type="warning"}
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:

:::CodeblockTabs
routeros

```bash
/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 flush
```
:::

## Scenario: Three WANs

Copy and paste the following code to handle three internet lines:

:::CodeblockTabs
routeros

```bash
/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 flush
```
:::

## Scenario: Four WANs

Copy and paste the following code to handle four internet lines:

:::CodeblockTabs
routeros

```bash
/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 flush
```
:::

## Finalizing 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.
