DuxTel Systems (11)
Interface Cards and Adapters (14)
Mikrotik Systems-> (159)
Mimosa Wireless (5)
RouterBOARD (11)
Router Enclosures (11)
Power Supplies & PoE-> (29)
Antennas and Accessories-> (106)
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 (9)
Q&A (28)
Product Advisory (7)
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 1 day ago
Cute as a button! The hAP-mini 3 port wifi router from MikroTik has finally passed all relevant certifications! Ge…
more >>
about 10 days ago
LOOK! The new wsAP-lite is a dual band WiFi AP with passthrough PoE ethernet that fits into a power point profile!
more >>
about 10 days ago
The new LtAP-mini is the ideal mobile and vehicle connectivity system with GPS - add your own 4G modem for the ulti…
more >>
about 10 days ago
The cool new RBLHGG-60adkit Wireless Wire Dish Kit is on its way - available for pre-order right now!
more >>
about 11 days ago
DuxTel News: Half-price Mimosa, MikroTik LTE updates, MUM 2018 Highlights -
more >>
about 01 month ago
CCR1072-1G-8S+ - it doesn't get any better than this! Normally $4325, special price $2999 - (ex demo model, 1 unit…
more >>
about 01 month ago
ready for MikroTik Certified Training - kicking off TOMORROW! :)
more >>
about 01 month ago
MikroTik's first ever true 802.3af/at PoE switch with auto-detecting 24v/48v and 4x 10GB SFP+ uplink is available n…
more >>
about 01 month ago
Thinking about horns? See here! :)
more >>
Follow our tweets for all the latest news and updates!
GrooveA-52HPn: dual-band outdoor AP
The GrooveA-52HPn is an amazing unit. Exactly what you would ..
5 of 5 Stars!

Copyright © 2018 DuxTel Online Store