Programatically change ports on Mikrotik RouterOS

I created a simple script, that can help you change ports on your Mikrotik router

How to use

in my script fill array with port aliases:

:global PFVports {http="80";ssh="22";https="443";ftp=23};

add a comment to your NAT rule, that starts with “PFV_” and folows with port alias like that:

Now run my script and it will automatically set dst-port to whatever you set (in script) http port value… in my example port 80.

Next time you need to change some ports, you don’t need to change one by one, just update PFVports array and re-run this script.


dst-port is just one of many things that can be changed with this script… it can be easily changed to do whatever you need.

Hope you like it :)

(3) Comments

  • agung
    27 Aug 2018

    how can i change ip automatically please tell me

    • Uroš
      03 Sep 2018

      You could try to change dst-port=”$port” to dst-address=”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.