Following is a small guide on how you can enable your mikrotik box/rb to send SMS to your mobile using GSM modem or any supported mobile set. This guide will also demonstrate how you can enable mikrotik to receive SMS via GSM modem and execute script based on the command received in the SMS 🙂
Its very useful in many situation , for example you can configure multiple script to do various task, Few examples are that you can
- create/disable users ,
- change queues ,
- reset router admin/user password ,
- ask router about internet connectivity,
- alert you if any link goes down,
& so much other things fun you can imagine, another example to restart router remotely by sending SMS message to mikrotik and then it can execute the specified script, it will reboot right away. I have used this SMS function for number of tasks and it performed very well.
Hardware used for this guide
1) Mikrotik 5.20 x86
version installed on PC
2) Teltonika GSM Modem Device. (Picture attached below, you can also use any mobile to do the task)
Teltonika ModemUSB/E12 UM1400 (syed Jahanzaib)
After plugin the device into mikrotik box, reboot the mikrotik once so it can initialize the modem device.
Open Terminal and issue the following command to make view the usb port detail.
and you will see its result something like below image . . .
If you can see usb listed, it means your device have been detected.
Now goto TOOLS > SMS
Click on ‘Receive Enabled‘ (Only if you want to
enable receiving for various functions)
in Port, select Select USB3 (or whatever your usb port name is appearing)
Set the Channel ???
In Secret type any password e.g 12345 [Secret is like your password, it is used if you want mikrotik to execute any script/command when it received appropriate sms]
As showed in the image below . . .
Test SMS sending using Mikrotik
Now its time to send test SMS to any number using mikrotik.
Click on Send SMS
In Port, select USB3 (or whatever name of your USB is detected)
in Phone number, type your destination mobile number
in Message, type your desired message,
and click on SEND SMS
As showed in the image below . . .
Howto execute script upon receiving SMS
If you have selected ‘Receive Enabled‘, then you can receive Messages on Mikrotik in INBOX section of SMS. It can also execute any script of your choice.
For example you want to reboot your router by sending sms, use the following method.
First create appropriate script that can restart router.
/system script add name=reboot policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=”/system reboot”
Now from your own mobile , send the following sms to mikrotik connected GSM Device number.
:cmd 12345 script reboot
Explanation of above command.
:cmd = tell mikrotik that its
the command it need to execute
12345 = is the secret/password that we set in the SMS setting
script = it tells mikrotik that it have to execute script function
reboot = is the script name we want mikrotik to run, which we created in above step.
You can do so much interesting stuff using this feature. I did used this option in the past to control my whole company network including Mikrotik/Linux/Microsoft Domain environment. It was used to power OFF / Power ON / Reboot and many other functions.
I will write about them later . . .
Enabling receive-enabled via script
Receive Enabled turns off auto when the router reboots, you can schedule a script that runs on every reboot and after 15 minutes of interval.
First below is a simple
command to enable the receiving via terminal manually.
/tool sms set receive-enabled=yes
Now we will create script and add scheduler, We will use terminal to do the task quickly.
/system script add name=enable-sms-rec
source=”/tool sms set receive-enabled=yes;”
Now add scheduler so this script runs periodically after 15 minutes each. and on start up also.
add comment=”execute enable-sms-rec script” disabled=no interval=15m name=\
“execute enable-sms-rec script” on-event=enable-sms-rec policy=\
Using NETWATCH tool to monitor your WAN connectivity
You can configure NETWATCH to monitor any WAN ip , for example Google dns, when it will timeout, it can can trigger script that can send sms so you can be aware about your WAN connectivity.
|1 2 3 4 5 6 7 8 9 10 11||/tool netwatch add disabled=no down-script=”/sys script run down” host=184.108.40.206 \ interval=5m timeout=1s up-script=”/sys script run up” /system script add name=down policy=\ ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \ source=”/tool sms send message=WAN_DOWN phone-number=03333021909 usb3”” add name=up policy=\ ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \ source=”/tool sms send message=WAN_UP phone-number=03333021909 usb3”|
source=”/tool sms send message=WAN_UP phone-number=03333021909 usb3”