MikroTik RouterBoard and USB 3G/HSPA/LTE Modems

Small example of how to direct NNTP traffic to wan2 in a dual wan setup:

First, port 119 (nntp) traffic is marked accordingly:

Code:
/ip firewall mangle
add action=mark-routing chain=prerouting comment="Mark nntp traffic" \
    dst-port=119 new-routing-mark="NNTP Traffic" passthrough=no protocol=tcp


Then a route for this marked traffic is created to wan2:

Code:
/ip route
add comment="NNTP traffic to wan2 only" gateway=wan2 routing-mark=\
    "NNTP Traffic" scope=255

Check the MikroTik Wiki for more....
 
My dual 3G wan setup dns issue:

You need to be aware, if you have each PPP connection "use Peer DNS" set, that the RB751 sets its dns servers to those of the last PPP session that was connected.

attachment.php


This poses a problem, if the router default route (distance 1), happens to set to 8ta for example, but the Cell C PPP session was the last one to connect.
The router would try to talk to the Cell C DNS servers via the 8ta PPP connection (default route), which will not work.
This causes DNS to appear "broken" to your browser for example.
You may be lucky if you try and resolve names that are already in the router DNS cache.

My solution to this was to interleave the 8ta and Cell C DNS servers, with the Google DNS servers as backup "catch all":

attachment.php


or to make it ISP independent, but relying solely on the Google DNS servers:

attachment.php


Alternatively, you could fiddle around with scripting to set the router DNS servers according to the router's current default (distance 1) route.
 
Last edited:
The RB751U works ok with the USB2.0 modem, but will not communicate with the serial port of the USB1.1 modem, even from the terminal.
[...]
However, it also works ok with a single USB1.1 modem only, but then not with two USB1.1 modems together.

I did try different modems and three different USB Hubs.
This is understable. Some USB do not attempt to translate USB protocols at all. Some other attempt to translate, but the most popular hubs have limitation you have experienced. Finding translating hub without limitation will be difficult, most likely you find primitive (not translating) hub working in your case. But it would force USB 2.0 device to operate also in USB 1.1 mode, AFAIK.

Edit: More precise about these hubs with limitation: They have single translator, it means (in my understanding) that only single device requiring translation can be used. It doesn't explain why 1.1 device do not work with 2.0 device together.
 
Last edited:
My solution to this was to interleave the 8ta and Cell C DNS servers, with the Google DNS servers as backup "catch all"

Small problem with this approach, as Cell C seems to have different DNS servers according to the IP address your PPP session is allocated.

DNS
For 41.48.x.x
- 41.48.23.29
- 41.48.23.61

For 41.50.x.x
- 41.50.20.29
- 41.50.20.61

...and there may be more.

If you are allocated a 41.50.x.x address, for some reason you cannot connect to the 41.48.23.29 and 41.48.23.61 DNS servers.

Must be some strange Cell C internal configuration issue.
I would have thought that all allocated PPP sessions addresses would have access to all their DNS servers.
They must have some valid reason for not allowing this I guess. Probably some sort of load balancing.

This definitely does not work well with my static DNS idea.

To make life easier, I have decided to use the two Google DNS servers configuration as described in my previous post. Slightly slower than the local DNS servers to resolve names, but still acceptable.
 
Last edited:
Interesting to see the "tx and rx RF circuits disabl" message in the Functionality box of the left screen.
Wonder what could have caused this?
Was the modem plugged into the RB when this happened, or had it been in a PC and then plugged into the RB?

If this happens again, try checking the current state of the modem with:
Code:
AT+CFUN?
If the current state is 4, your only choice is to reset the modem with:
Code:
AT+CFUN=6
If it is any other state, try setting it to 1:
Code:
AT+CFUN=1
And check whether it worked:
Code:
AT+CFUN?
If the current state is still not equal to 1, try resetting the modem:
Code:
AT+CFUN=4
AT+CFUN=6
 
Was the modem plugged into the RB when this happened, or had it been in a PC and then plugged into the RB?

The E272 was plugged in to the RB751U, and had been running fine for a few days before this event.
I just happened to notice it start flashing while working near it.

It hasn't happened again since then, but if it does I'll give your suggestions a try, thanks.
 
The E272 was plugged in to the RB751U, and had been running fine for a few days before this event.
I just happened to notice it start flashing while working near it.

It hasn't happened again since then, but if it does I'll give your suggestions a try, thanks.

Found this E272 (Vodacom unrestricted APN) in the same state again this morning.
Indicator flashing green twice every three seconds.
tx and rx RF circuits disabled.

Maybe this is a result of something being done, like a reset or connection disable of sorts from the 3G network side? Not sure why it leaves the modem in this state, as the router cannot recover it automatically.

Tried:
AT+CFUN?
+CFUN: 4

AT+CFUN=1
ERROR

AT+CFUN=6
ERROR

Then: (strange that I had to first command the RF off, even though it was supposedly already in that state)
AT+CFUN=4
OK

AT+CFUN=6
OK

Modem reset and was able to connect PPP session again.

Now to somehow get a script to be able to send this AT command sequence!
 
Last edited:
This is an essence what ginggs wrote above. if 4, then don't try 1; select 6 for reset. If something else, select 1.
 
Now to somehow get a script to be able to send this AT command sequence!

And I think I have found a way!
Amazing what desperation can do!

This is a bit of a dirty way of firing AT commands "blind" at the modem on the MikroTik RB751U's PPP wan connection.
For some reason the ZTE MF190 needed a reset sequence different from the Huawei's

Haven't tested this on any other modems as indicated, but I will be interested to see if it can help to automatically recover my original E272 tx and Rx RF circuits disabled problem.


Code:
## Modem reset script for 3G PPP Wan links ##
## uses PPP Modem Init to send AT command to serial port ##
## Commands are simply fired "blind" at the modem ##
## sends the AT+CFUN=4, AT+CFUN=6 command sequence ##
## ZTE MF-190 requires AT+CFUN=4, AT+CFUN=1 sequence or AT+ZRST ##
## Huawei E367, E272 requires AT+CFUN=4, AT+CFUN=6 sequence ##
## Untested on other modems ##
## This script can be used with Netwatch ##
## You can adjust the delays and AT commands as needed ##
## Peter James 2012-03-12 ##

# Set the wan name #
:local WanName "wan2";

:log info "Starting $WanName Modem Reset Sequence";

# get its ID number #
:local WanID [/interface ppp-client find name=$WanName];

# Modify the dial command to force dial failure, else modem gets confused #
/interface ppp-client set dial-command="AT" $WanID;

/interface ppp-client disable $WanID;
delay 1;
/interface ppp-client enable $WanID;

/interface ppp-client set modem-init="ATZ;AT+CFUN=4" $WanID;

# Wait for tx and rx RF circuits to switch off #
delay 5;

/interface ppp-client set modem-init="ATZ;AT+CFUN=6" $WanID;

# wait for modem to reset #
delay 5;


# Modify the dial command to restore dial capability #
/interface ppp-client set dial-command="ATD" $WanID;

/interface ppp-client set modem-init="" $WanID;

# Modem should now redial  and connect #

:log info "$WanName Modem Reset Sequence complete";
 
Last edited:
This is an essence what ginggs wrote above. if 4, then don't try 1; select 6 for reset. If something else, select 1.

The problem was, even though the modem reported state 4, it would not respond to AT+CFUN=6, but returned ERROR.

I first had to send it a AT+CFUN=4 (even though it was supposedly in this state already) and only then did it respond to AT+CFUN=6 and reset.
 
The problem was, even though the modem reported state 4, it would not respond to AT+CFUN=6, but returned ERROR.
Yeah, that is weird. I have never come across that before, but I'll modify MDMA to deal with that situation.

The +CFUN=4, CFUN=6 sequence is for Huawei modems only. I'll dig through the MDMA source code and post the reset commands for other modems tonight.
 
Yeah, that is weird. I have never come across that before, but I'll modify MDMA to deal with that situation.

The +CFUN=4, CFUN=6 sequence is for Huawei modems only. I'll dig through the MDMA source code and post the reset commands for other modems tonight.

Is a bit odd.
Just checked again, and in its normal state the E272 is quite happy with the 4,6 reset sequence.
But, whatever condition it was in this morning, even though it reported state 4, it simply would not accept AT+CFUN=6.
Only after I forced a AT+CFUN=4, would it respond to that command.

That only happened once and then it was "normal" again.
That's why I figured I would just force the 4,6 sequence in my script anyway.
 
AT commands to reset modems

The logic in MDMA is currently as follows:

ZTE:
AT+ZRST

Sierra Wireless:
AT!RESET

Huawei and all others:
AT+CFUN=4
AT+CFUN=6

Novatel don't like AT commands, but will reset when sent the following binary sequence:
0x29, 0x01, 0x00, 0x31, 0x40, 0x7E
0x29, 0x02, 0x00, 0x59, 0x6A, 0x7E
 
AT+ZRST works fine with my ZTE MF190
Indicator cycles from solid green, to red and then green again.


ZTE MF190 also works with this:

Code:
[admin@Base122] /system> serial-terminal usb1 channel=2

[Ctrl-A is the prefix key]

(Indicator solid green)
AT+CFUN=4
OK

AT+CFUN?
+CFUN: 4
OK
(indicator now solid red and remains so)

AT+CFUN=1
OK

AT+CFUN?
+CFUN: 1
OK
(indicator solid green again)

Modem then able to connect PPP session as normal.

ZTE MF190 will not work with AT+CFUN=6:

Code:
AT
OK

AT+CFUN=4
OK

AT+CFUN?
+CFUN: 4

OK

AT+CFUN=6
ERROR

AT+CFUN?
+CFUN: 4

OK

AT+CFUN=1
OK

AT+CFUN?
+CFUN: 1

OK
 
Last edited:
This script can be scheduled to run at regular intervals to ping a known good host on your 3G wan link.

If the ping fails, a 3G modem reset sequence is attempted.
So far this seems to work fine with my ZTE MF190, Huawei E367,272

Code:
## Modem reset script for 3G PPP Wan links with Email reporting  ##
## based on ping reply to a known good host. ##.
## The google dns server at 8.8.8.8 is used  ##
## in this example, but you can use any known good host to ping.  ##
## take note of your wan interface name! ##
#########################################################
## Script uses PPP Modem Init to send AT command to serial port ##
## Commands are simply fired "blind" at the modem ##
## Example sends the AT+CFUN=4, AT+CFUN=6 command sequence ##
## ZTE MF-190 requires AT+CFUN=4, AT+CFUN=1 sequence or AT+ZRST ##
## Sierra Wireless:  AT!RESET ##
## ZTE:  AT+ZRST  ##
## Huawei:  AT+CFUN=4, AT+CFUN=6 sequence ##

## This script can be used with Netwatch or sheduled to run on startup ##
## after a watchdog reboot. ##
## You can adjust the delays and AT commands as needed ##
## Schedule this script at whatever checking interval you require. ##
## Remember to set up Tools - Email settings ##
## Peter James 2012-03-15 ##
## 2012-03-23 Added usb port inactive check with router reboot ##

# Set the 3G wan name #
:local WanName "wan1";

# Define the usb port for this connection #
:local usbPortName "usb1";

:log info "Starting $WanName 3G Down Check";

:local i 0;
:local result 0;

### Define the email address to receive 3G modem reset report  ###
:local emailAddressToNotify "your_email_address"

## Define host to check ###
:local testhost "8.8.8.8";

## Define number of pings to check ##
:local PingCount 10;

### Get System Identity ###
:local SystemID [/system identity get name]

## If the usb port is inactive, reboot the router to attempt to fix this ##
:if ([/port get [find name=$usbPortName] inactive]) do={

:log info "USB Port $usbPortName detected as inactive - System Rebooting";

/system reboot;

}


## Skip the ping check if the wan interface is not running ##
:if ([/interface get [find name="$WanName"] running]=true) do={

:do {

:set i ($i + 1);

:if ([/ping $testhost interface="$WanName" interval=3 count=1]=1) do={

:set result ($result+1);

}

} while=($i < $PingCount)

}

# ping has failed PingCount times or ping check was skipped #
:if ($result=0) do={

:log info "Starting $WanName 3G Modem Reset Sequence";

# get its ID number #
:local WanID [/interface ppp-client find name=$WanName];

#/interface ppp-client disable $WanID;#

# Toggle the data channel setting #
/interface ppp-client set data-channel="1" $WanID;
delay 5
/interface ppp-client set data-channel="0" $WanID;

# Send first part of reset sequence #
/interface ppp-client set modem-init="AT+CFUN=4" $WanID;
/interface ppp-client enable $WanID;
# Allow time for Init command to be sent #
delay 5;
# disable again to stop dial attempts #
/interface ppp-client disable $WanID;


# Wait for tx and rx RF circuits to switch off #
delay 5;

# Send second part of reset sequence #
/interface ppp-client set modem-init="AT+CFUN=6" $WanID;
/interface ppp-client enable $WanID;
# Allow time for Init command to be sent #
delay 5;
# disable again to stop dial attempts #
/interface ppp-client disable $WanID;

:log info "waiting for modem reset 30 seconds";
# wait for modem to reset #
delay 30;

/interface ppp-client set modem-init="" $WanID;
# Allow modem to dial again #
/interface ppp-client enable $WanID;

# Modem should now redial and connect #

:log info "waiting to send email 30 seconds";
## wait before trying to send email ##
delay 30;

# Check if interface is now running #
:if ([/interface get [find name="$WanName"] running]=true) do={

/tool e-mail send tls=yes subject="$SystemID $WanName 3G Modem Was Reset" to=$emailAddressToNotify body="$WanName 3G Modem Was Reset"

:log info "Email sent $WanName 3G Modem Was Reset"

:log info "$WanName Modem Reset Sequence Complete";

} else={

:log info "$WanName Interface Not Running - Modem Reset Sequence Failed";

}

}

:log info "$WanName 3G Down Check Complete";

***Edit 2012-03-15:
Script modified to add skipping of the ping check if the wan interface is not running.
Some timings adjusted.
Added a data channel toggle sequence to help with a problem clearing the E272 problem condition.
Added interface running check before attempting to send email.

***Edit 2012-03-16
Some modems may take longer to reset than others, it may be necessary to adjust the "delay" values to get this script to work. Unfortunately there is no handshake with the modem and this is a crude "fire command and hope it works" approach.

***Edit 2012-03-23
What I am finding is that sometimes the RouterBoard cannot communicate with the modem, as the usb port has become inactive. This should only normally happen when the modem is unplugged.
Because it happens with the modem still plugged in, it can only be some error condition.
I have modified the script to include a usb port inactive check, which reboots the router to help recover from this problem.
 
Last edited:
Thanks for those modem reset commands and sequences ginggs.

I've posted this reset script over at the MikroTik forum as well.

Hopefully some folks will make use of it and give some feedback.
 
Some more scripting, this time to write the GSM modem info to a file and email this info to an email address.

A bit tricky to get the ppp-client info and monitor commands to behave inside a script.
Once fired, they continue to run, hence the loop counters to control this.

I have created two scripts.
One named pppUptime, which uses the ppp-client monitor command to get the interface Uptime.

The other is named pppInfoUPtime, which uses ppp-client info, but starts the pppUptime script as well, to allow me to get the Uptime to add to the information file and for email.

I hope these scripts are useful.
I have spent many hours on this and have learned a great deal.

Enjoy!

pppUptimeOnly:

Code:
## All this script does is set the pppUptime global variable for "wan2" in this example##
## This script name is pppUptime in this example ##
## Used in conjunction with my other pppInfo script ##
## Share, modify, improve and use as you wish ##
## Tested on RouterOS v5.12 using Huawei E367 modem #
## Peter James 2012-03-17 ##

## Set the PPP interface name for which Uptime value is required ##
:local pppName "wan2";

# loop counter #
:local k 0;

# Defined as global, so that other script can use #
:global pppUptime;

:local pppID [/interface ppp-client find name=$pppName];
:log info "PPP Uptime $pppName Script Starting";


# Start of monitor command #
/interface ppp-client monitor $pppName do={

:set k ($k+1);

# run loop twice to be sure #
:if ($k=2) do={

:set pppUptime $"uptime";

## Must now stop this script, or Monitor will run forever ##
:log info "PPP Uptime $pppName Script completed";
/system script job remove [find script=pppUptime ];

}
}

pppInfoUptime (starts the above pppUptimeOnly script):

Code:
## Script to write PPP-info to a file and send to Email ##
## For this example, my PPP name is "wan2" ##
## and my script name is "wan2PPPinfoUptime" ##
## This script makes use of the ppp-client info command ##
## with a loop counter to stop the command once the ##
## information has been acquired. ##
## Can be used in conjunction with my other pppUptime ##
## script if the Uptime is required as well. ##
## You can use the info file to extract information for other purposes ##
## Remember to set up Tools-Email ##
## Share, modify, improve and use as you wish ##
## Tested on RouterOS v5.12 using Huawei E367 modem #
## Peter James 2012-03-17 ##

# Set the PPP interface name #
:local pppName "wan2";

# Define the email address to receive PPP Info report  #
:local emailAddress "your_email_address"

:local i 0;

global pppUptime;

:local pppID [/interface ppp-client find name=$pppName];

# Variables to hold PPP Info #
:local String1;
:local String2;
:local pppInfoString;

# Variable to hold PPP interface current IP address #
:local currentIP;


# Get System Identity #
:local SystemID [/system identity get name];

:local pppStatus;
:if ([/interface get [find name=$pppName ] running ]=true) do={

:set pppStatus "Running";

### Get the address of the specified wan interface ###
:set currentIP [/ip address get [find interface=$pppName] address];
:set currentIP [:pick $currentIP 0 [:find $currentIP "/"]]

} else={
:set pppStatus "Disabled";
}

# Start the pppUptime script #
# Comment out if you do not need #
/system script run pppUptime;

:log info "PPP Info $pppName Script Starting";

# Create the information File #
/file print file="$SystemID-$pppName-PPP-info";

:global SysDate [/system clock get date]
:global SysTime [/system clock get time]


# Start of info command #
/interface ppp-client info $pppID do={

:set i ($i+1);

# for some reason this loop must run at least 3 times to set the system variables #
# set to run 5 times to be sure #
:if ($i=5) do={

# non info command stuff #
:set String1 "Date: $SysDate\nTime: $SysTime\nSystem ID: $SystemID\nPPP Interface: $pppName\nPPP Interface Status: $pppStatus\nIP Address: $currentIP\nUptime: $pppUptime\n";

:set String2 "Modem Status: $"status"\nPin Status: $"pin-status"\nFunctionality: $"functionality"\nManufacturer: $"manufacturer"\nModel: $"model"\nRevision: $"revision"\nSerial Number: $"serial-number"\nCurrent Operator: $"current-operator"\nAccess Technology: $"access-technology"\nSignal Strength: $"signal-strengh"";

:set pppInfoString "$String1$String2";

:log info $pppInfoString;

# Populate file with required information #
/file set "$SystemID-$pppName-PPP-info" contents=$pppInfoString; 


# Do all the other things you need to do here ???#

# Example, send Email #
:log info "Sending PPP Info email";
/tool e-mail send tls=yes subject="$SystemID $pppName PPP Info" to=$emailAddress body="$pppInfoString";

:log info "PPP Info $pppName Script Completed";

## Must now stop this script, or info will run forever ##
/system script job remove [find script=wan2PPPinfoUptime ];

}
}
 
Last edited:
Been having an issue with the RB751U DNS performance for a while.
Sometimes queries would just not resolve and my browser pages would not load.
This was very erratic and happened on both my Cell C and 8ta wan links.
The problem occurred more regularly on the Cell C connection for some reason.

After some Google assisted "research" a suggestion was to adjust the "max UDP packet size" from the default 512.

I am now using this setting:

attachment.php


The problem seems to have "gone away for now"...:)

The 8192k cache size is probably overkill for my needs....
 
I have been unable to get Vodafone K3805-Z and Vodafone K3772-Z modems to work with the RB751

I have sent a support file to Mikrotik re for the Vodafone K3805 and waiting for them to get back to me :-/
 
I have been unable to get Vodafone K3805-Z and Vodafone K3772-Z modems to work with the RB751

I have sent a support file to Mikrotik re for the Vodafone K3805 and waiting for them to get back to me :-/
The K3805-Z has an Icera chipset and uses a different AT command set to all the other ZTE modems.
I don't know anything about the K3772-Z.
 
Top
Sign up to the MyBroadband newsletter
X