DuxTel Systems (13)
Interface Cards and Adapters (15)
Mikrotik Systems-> (155)
Mimosa Wireless (5)
RouterBOARD (10)
Router Enclosures (13)
Power Supplies & PoE-> (29)
Antennas and Accessories-> (117)
Mikrotik RouterOS (6)
Assembled Kits (6)
Carrier Wireless (1)
Cable and Misc (14)
Hardware and Mounting (23)
Configuration Library (FREE!) (7)
Quick Find
search products
search articles
New Articles
Case Studies
Product Guides (2)
Mikrotik Configuration (17)
Technical (5)
Community News (8)
Q&A (28)
Product Advisory (6)
Policy and Information (7)
Shipping & Returns
Privacy Notice
Conditions of Use
Contact Us
Creating and using Dynamic Config Scripts by Mike Everest

If your work or play is involved in dealing with large, complex data networks, and you have one or more standard components that need to be replicated to multiple individual components, then you may find yourself repeating a set of configuration steps every time you need to deploy a new device to the network.

Fortunately, Mikrotik RouterOS provides a means to save existing router configurations and to quickly and easily build dynamic configuration scripts to automate this kind of roll-out process.

The best way to begin is to use a config export file:


Click ‘new terminal’ in winbox,

enter ‘/export file=config’ at the RouterOS shell,

look in ‘files’ under winbox,

drag the file entry called ‘config.rsc’ to your desktop or other convenient PC filesystem location.


The shell command actually defines the filename – so you can use ‘/export file=myconf’ to create a file called ‘myconf.rsc’


The .rsc is just a text file – open it up in any text editor – which contains a full list of shell commands required to replicate the current configuration of your router.

You can copy-all the contents of that file, and paste into a ‘new terminal’ (right click inside the routerOS shell and choose ‘paste’) to get a complete duplicate of your original router config.


CAREFUL though!  You will duplicate the router configuration in every way INCLUDING the interface MAC addresses!  Therefore, if you are making wireless CPE kits for example, intended to all use the same access point, duplicating MAC addresses of the original wireless interface is obviously going to get you in to some trouble! ;-)

Therefore, before applying any config to a new router, I strongly recommend that you first go through the config with your text editor and at least remove all references to mac addresses.  Remember that any command or attribute in the config file that is omotted simply implies that the default setting will be accepted.


Therefore, you can also make your config file a lot simpler by also removing any commands that you are happy to keep as the default setting.


You can also make any adjustments to the config before applying – for example you may want to change some typical settings like WPA encrypttion or admin passwords, SSID names, router ID names and so on.


When you are happy with your config file, you can save it to your config library for later use or reference.


You can also use the powerful routerOS scripting language to make dynamic configuration scripts.  One example is how we make a pptp client to use the ether1 mac address as the login username:


In routerOS, to retrieve the value of the mac address of ether1, we can use this command:


/interface ethernet get ether1 mac-address


So to add a pptp client with that string as username, we can do:


/interface pptp-client add add-default-route=no allow=pap,chap,mschap1,mschap2 \

    comment="pptp client added by setup script" disabled=no max-mru=1460 \

    max-mtu=1460 mrru=disabled name=pptp-out1 password=duxman profile=default-encryption \

    user=[/interface ethernet get ether1 mac-address]


You can also make a dynamic configuration using variables defined at the beginning of your script for easy customization.  In the following example, you might want to set the wireless SSID of a device using a standard config.  Rather than hunt through the config file for the ssid value in the wireless interface property, you can define it at the beginning of the file:


# sample config.rsc

# change the following value to use as SSID


:global ssid “MySSID”


# now refer to the variable with ‘$’ prepend:


/interface wireless set ssid=$ssid


Anywhere that you want to set common variables, you can use this method to put the value definitions in a convenient place at the top of your file.


Sometimes, you may find that your scripts fail part way through applying them.  For example, if your configuration script includes a firewall rule half way through that effectively cuts you off from the router on the port you are connected to, or if the script creates a bridge or reassigns an IP address that you may need for access to the device.  In this case, you can first paste your config file into a system script, and then execute the entire script at once:

In winbox, click on ‘system -> scripts’ and then click ‘+’.  Give the script some name (if you want to, like “initial-config” then paste your entire config file into the content field.  Save and close the dialog and then click ‘run’ to execute.


You can review more routerOS scripting info at the official Wiki site:


Or feel free to contact us if you have further questions! :-)

Date Added:
Current Comments: 0
Write Review
Tell a friend
Tell a friend about this article:  
Shopping Cart
0 items
Latest News
about 8 days ago
So called SLINGSHOT exploit reported by Kaspersky Labs this week is actually a very old known issue already patched…
more >>
about 9 days ago
DuxTel News: MikroTik User Meeting & Training Melbourne, Cool new products! -
more >>
about 10 days ago
MEET US AT THE MUM! MikroTik User Meeting is coming up in Melbourne on 18th May - meet the DuxTel Team together wit…
more >>
about 11 days ago
The DuxLink-ULTRA is back! Now with two options based on the brand new UltraDish from @rfelements and RB911G-5HacD…
more >>
about 13 days ago
ready for MTCWE starting tomorrow in Sydney! :)
more >>
about 15 days ago
Congratulations go to Ian Gallagher for taking out the DUX prize for MTCNA class! :)
more >>
Follow our tweets for all the latest news and updates!
RBCA450G: RB450G kit with indoor case - assembled
The RB450G is the swiss army knife of routers. The amount of ..
5 of 5 Stars!

Copyright © 2018 DuxTel Online Store