<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MikroTik | vaheeD khoshnouD</title>
	<atom:link href="/category/mikrotik/feed/" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>linux, mikrotik, macosx</description>
	<lastBuildDate>Mon, 24 Aug 2015 06:38:51 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.7.2</generator>
	<item>
		<title>Tunnel between two mikroTik</title>
		<link>/tunnel-between-two-mikrotik/</link>
					<comments>/tunnel-between-two-mikrotik/#respond</comments>
		
		<dc:creator><![CDATA[vaheeD]]></dc:creator>
		<pubDate>Mon, 24 Aug 2015 06:23:00 +0000</pubDate>
				<category><![CDATA[MikroTik]]></category>
		<guid isPermaLink="false">/?p=712</guid>

					<description><![CDATA[<p>&#160; You need two mikrotik for this example and many many client :D In this case you need &#8230; 1) two mikrotik connect to the internet 2) just one interface 3) Just have IP address for connecting to internet and Default Gateway 4)Copy and past :D Now start with MT-01 open terminal and paste&#8230; #... </p>
<p><a class="small button secondary" href="/tunnel-between-two-mikrotik/">Continue Reading</a></p>
The post <a href="/tunnel-between-two-mikrotik/">Tunnel between two mikroTik</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></description>
										<content:encoded><![CDATA[<p><span id="more-712"></span></p>
<p>&nbsp;</p>
<p>You need two mikrotik for this example and many many client :D</p>
<p>In this case you need &#8230;<br />
1) two mikrotik connect to the internet<br />
2) just one interface<br />
3) Just have IP address for connecting to internet and Default Gateway<br />
4)Copy and past :D</p>
<p>Now start with MT-01</p>
<p>open terminal and paste&#8230;</p>
<p><code><br />
# aug/01/2015 12:00:00 by RouterOS 6.31<br />
# vaheeD MT-S<br />
#Please Attention to all comment<br />
#Secure VPN Server with<br />
#OVPN SERVER ON PORT 10022 ** You can chenage this port to XXXXX<br />
#SSTP SERVER ON PORT 1025  ** You can chenage this port to XXXXX<br />
#WINBOX PORT 6600   ###   SSH PORT  2221<br />
#<br />
/certificate<br />
add name=ca-template common-name=myCa key-usage=key-cert-sign,crl-sign<br />
sign ca-template name=myCa<br />
/ip ipsec proposal<br />
set [ find default=yes ] enc-algorithms=3des,aes-128-cbc<br />
/ip pool<br />
add name=pool ranges=192.168.88.100-192.168.88.200<br />
/ppp profile<br />
set 0 dns-server=8.8.8.8,4.2.2.1 local-address=192.168.88.1 remote-address=\<br />
    pool<br />
set 1 dns-server=8.8.8.8,4.2.2.1 local-address=192.168.88.1 \<br />
    remote-address=pool<br />
/interface ovpn-server server<br />
set enabled=yes \<br />
    port=10022<br />
/interface sstp-server server<br />
set enabled=yes port=1025<br />
/ip address<br />
###CHANGE PUBLIC_IP ADDRESS TO xxx.xxx.xxx.xxx<br />
#add address=PUBLIC_IP interface=ether1<br />
add address=192.168.88.1/24 interface=ether1 network=192.168.99.0<br />
/ip dns<br />
set allow-remote-requests=yes servers=8.8.8.8,8.8.4.4,4.2.2.1<br />
/ip firewall mangle<br />
/ip firewall nat<br />
add action=masquerade chain=srcnat<br />
###CHANGE PUBLIC_IP ADDRESS TO xxx.xxx.xxx.xxx<br />
#add action=src-nat chain=srcnat to-addresses=PUBLIC_IP<br />
###CHANGE DefaultGateway ADDRESS TO zzz.zzz.zzz.zzz<br />
#/ip route<br />
#add distance=1 gateway=DefaultGateway<br />
/ip service<br />
set telnet disabled=yes<br />
set ftp disabled=yes<br />
set www disabled=yes<br />
set ssh disabled=yes port=2221<br />
set winbox port=6600<br />
set api disabled=yes<br />
set api-ssl disabled=yes<br />
/ppp secret<br />
add name=ppp password=ppp<br />
###EXPORT CA For Client ###OPTIONAL<br />
#/certificate export-certificate myCa<br />
#/certificate export-certificate client1 export-passphrase=xxxxxxxx<br />
#/certificate export-certificate client2 export-passphrase=xxxxxxxx<br />
###FINISH SCRIPT.<br />
</code></p>
<p>now paste</p>
<p><code><br />
/interface ovpn-server server<br />
set certificate=myca<br />
</code></p>
<p>
Move to MT-02</p>
<p>****<br />
now change xxx.xxx.xxx.xxx  TO   Public ip address MT-01<br />
****</p>
<p>open terminal and paste&#8230;</p>
<p><code><br />
# aug/01/2015 12:00:00 by RouterOS 6.31<br />
# vaheeD MT-CS<br />
#Please Attention to all comment<br />
#Secure VPN Server with<br />
#PPTP SERVER With PAP Configuration<br />
#L2TP SERVER With PresharedKEY : 123456789<br />
#WEB_PROXY SERVER ON PORT 9090<br />
#SOCKS_PROXY SERVER ON PORT 10520<br />
#WINBOX PORT 6600   ###   SSH PORT  2221<br />
#<br />
### CHANGE xxx.xxx.xxx.xxx TO IP MT-S<br />
:global vpnserverOUT xxx.xxx.xxx.xxx<br />
/interface ovpn-client<br />
add auth=md5 connect-to="$vpnserverOUT" name=\<br />
    ovpn-out1 password=ppp port=10022 user=ppp<br />
add auth=md5 cipher=aes192 connect-to="$vpnserverOUT" name=\<br />
    ovpn-out2 password=ppp port=10022 user=ppp<br />
add auth=md5 cipher=aes192 connect-to="$vpnserverOUT" name=\<br />
    ovpn-out3 password=ppp port=10022 user=ppp<br />
add auth=md5 cipher=aes128 connect-to="$vpnserverOUT" name=\<br />
  ovpn-out4 password=ppp port=10022 user=ppp<br />
add cipher=aes256 connect-to="$vpnserverOUT" name=\<br />
    ovpn-out5 password=ppp port=10022 user=ppp<br />
add auth=md5 connect-to="$vpnserverOUT" name=\<br />
    ovpn-out6 password=ppp port=10022 user=ppp<br />
add cipher=aes128 connect-to="$vpnserverOUT" name=\<br />
    ovpn-out7 password=ppp port=10022 user=ppp<br />
add auth=md5 cipher=aes128 connect-to="$vpnserverOUT" name=\<br />
    ovpn-out8 password=ppp port=10022 user=ppp<br />
/ip ipsec proposal<br />
set [ find default=yes ] enc-algorithms=3des,aes-128-cbc,aes-256-cbc \<br />
    pfs-group=none<br />
/ip pool<br />
add name=vpn ranges=192.168.89.100-192.168.89.200<br />
/ppp profile<br />
add change-tcp-mss=yes dns-server=192.168.89.1,8.8.8.8 \<br />
    local-address=192.168.89.1 name=VPN remote-address=vpn<br />
/interface sstp-client<br />
add connect-to="$vpnserverOUT:1025" disabled=no http-proxy=0.0.0.0:1025 name=\<br />
    sstp-out1 password=ppp pfs=yes profile=default-encryption user=ppp<br />
add connect-to="$vpnserverOUT:1025" disabled=no http-proxy=0.0.0.0:1025 name=\<br />
    sstp-out2 password=ppp pfs=yes profile=default-encryption user=ppp<br />
add connect-to="$vpnserverOUT:1025" disabled=no http-proxy=0.0.0.0:1025 name=\<br />
    sstp-out3 password=ppp pfs=yes profile=default-encryption user=ppp<br />
add connect-to="$vpnserverOUT:1025" disabled=no http-proxy=0.0.0.0:1025 name=\<br />
    sstp-out4 password=ppp pfs=yes profile=default-encryption user=ppp<br />
add connect-to="$vpnserverOUT:1025" disabled=no http-proxy=0.0.0.0:1025 name=\<br />
    sstp-out5 password=ppp pfs=yes profile=default-encryption user=ppp<br />
add connect-to="$vpnserverOUT:1025" disabled=no http-proxy=0.0.0.0:1025 name=\<br />
    sstp-out6 password=ppp pfs=yes profile=default-encryption user=ppp<br />
add connect-to="$vpnserverOUT:1025" disabled=no http-proxy=0.0.0.0:1025 name=\<br />
    sstp-out7 password=ppp pfs=yes profile=default-encryption user=ppp<br />
add connect-to="$vpnserverOUT:1025" disabled=no http-proxy=0.0.0.0:1025 name=\<br />
    sstp-out8 password=ppp pfs=yes profile=default-encryption user=ppp<br />
/interface l2tp-server server<br />
set default-profile=VPN enabled=yes max-mru=1460 max-mtu=1460<br />
/interface pptp-server server<br />
set authentication=pap default-profile=VPN enabled=yes max-mru=1460 max-mtu=\<br />
    1460<br />
/ip address<br />
###CHANGE PUBLIC_IP ADDRESS TO xxx.xxx.xxx.xxx<br />
#add address=PUBLIC_IP interface=ether1<br />
add address=192.168.89.1/24 interface=ether1 network=192.168.89.0<br />
/ip dns<br />
set allow-remote-requests=yes cache-max-ttl=1h cache-size=8192KiB \<br />
    max-udp-packet-size=8192 servers=4.2.2.4,8.8.8.8<br />
/ip firewall address-list<br />
add address=192.168.0.0/16 list=local<br />
add address=172.16.0.0/12 list=local<br />
add address=10.0.0.0/8 list=local<br />
/ip firewall mangle<br />
add chain=prerouting comment=accept-internal-network dst-address-list=local<br />
add chain=output comment=accept-internal-network dst-address-list=local<br />
add action=mark-routing chain=prerouting new-routing-mark=VPN src-address=\<br />
    192.168.89.0/24<br />
add action=mark-routing chain=output dst-port=80 new-routing-mark=VPN \<br />
    protocol=tcp<br />
add action=mark-routing chain=output dst-port=443 new-routing-mark=VPN \<br />
    protocol=tcp<br />
add action=mark-routing chain=output dst-port=53 new-routing-mark=VPN \<br />
    protocol=udp<br />
/ip firewall nat<br />
add action=masquerade chain=srcnat<br />
add action=redirect chain=dstnat dst-port=53 protocol=udp to-ports=53<br />
/ip ipsec peer<br />
add address=0.0.0.0/0 enc-algorithm=3des exchange-mode=main-l2tp \<br />
    generate-policy=port-override local-address=0.0.0.0 secret=123456789<br />
/ip proxy<br />
set always-from-cache=yes anonymous=yes cache-administrator=noway! \<br />
    cache-on-disk=yes cache-path=disk1/web-proxy1 enabled=yes parent-proxy=\<br />
    0.0.0.0 port=9090 serialize-connections=yes<br />
/ip proxy direct<br />
add dst-address=192.168.0.0/16<br />
add dst-address=172.16.0.0/16<br />
add dst-address=10.10.0.0/16<br />
add dst-host=*.ir<br />
/ip route<br />
add comment=OUTPUT distance=1 gateway="ovpn-out1,ovpn-out2,ovpn-out3,ovpn-out4,\<br />
    ovpn-out5,ovpn-out6,ovpn-out7,ovpn-out8,sstp-out1,sstp-out2,sstp-out3,sstp\<br />
    -out4,sstp-out5,sstp-out6,sstp-out7,sstp-out8" routing-mark=VPN<br />
/ip service<br />
set telnet disabled=yes<br />
set ftp disabled=yes<br />
set www disabled=yes<br />
set ssh port=2221<br />
set api disabled=yes<br />
set winbox port=6600<br />
/ip socks<br />
set connection-idle-timeout=5m enabled=yes max-connections=500 port=10520<br />
/ppp secret<br />
add name=ppp password=ppp profile=VPN<br />
###FINISH SCRIPT<br />
</code></p>
<p>Client Connect to MT-02 with Public IP address.</p>
<p>Have a GOOD Day!</p>
<div class="wp-about-author-containter-top" style="background-color:#FFEAA8;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=100&#038;d=mm&#038;r=g' srcset='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=200&#038;d=mm&#038;r=g 2x' class='author_gravatar left  avatar-100 photo' height='100' width='100' loading='lazy'/></div><div class="wp-about-author-text" style="margin-left:140px"><h3><a href='/author/vaheed/' title='vaheeD'>vaheeD</a></h3><p></p><p><a href='/author/vaheed/' title='More posts by vaheeD'>More Posts</a>  - <a href='https://plus.google.com/103839803047317952696' title='vaheeD'>Website</a> </p><p class="wpa-nomargin">Follow Me:<br /><a class='wpa-social-icons' href='http://www.facebook.com/vaheet'><img src='/wp-content/plugins/wp-about-author/images/facebook.png' alt='Facebook'/></a><a class='wpa-social-icons' href='https://plus.google.com/103839803047317952696'><img src='/wp-content/plugins/wp-about-author/images/googleplus.png' alt='Google Plus'/></a></p></div></div>The post <a href="/tunnel-between-two-mikrotik/">Tunnel between two mikroTik</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></content:encoded>
					
					<wfw:commentRss>/tunnel-between-two-mikrotik/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mikrotik DUAL WAN Load Balancing using PCC</title>
		<link>/mikrotik-dual-wan-load-balancing-using-pcc/</link>
					<comments>/mikrotik-dual-wan-load-balancing-using-pcc/#respond</comments>
		
		<dc:creator><![CDATA[vaheeD]]></dc:creator>
		<pubDate>Thu, 24 Jan 2013 17:17:25 +0000</pubDate>
				<category><![CDATA[MikroTik]]></category>
		<guid isPermaLink="false">/?p=621</guid>

					<description><![CDATA[<p>2 ports were connected with two difference DSL Routers, and 3rd port was connected with User LAN. Both DSL are of same speed , i.e 10Mb each. DSL MODEM IP’S DSL MODEM 1 = 192.168.1.1 DSL MODEM 2 = 192.168.2.1 If somehow you are not satisfied with the src-address approach,play with the PCC-Classifier, then Try... </p>
<p><a class="small button secondary" href="/mikrotik-dual-wan-load-balancing-using-pcc/">Continue Reading</a></p>
The post <a href="/mikrotik-dual-wan-load-balancing-using-pcc/">Mikrotik DUAL WAN Load Balancing using PCC</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></description>
										<content:encoded><![CDATA[<p><span id="more-621"></span></p>
<p><strong>2</strong> ports were connected with two difference DSL Routers,<br />
and <strong>3rd</strong> port was connected with User LAN.<br />
Both DSL are of same speed , i.e 10Mb each.</p>
<p><strong>DSL MODEM IP’S</strong><br />
DSL MODEM 1 = 192.168.1.1<br />
DSL MODEM 2 = 192.168.2.1</p>
<p>If somehow you are not satisfied with the src-address approach,play with the PCC-Classifier, then Try <strong>both addresses and ports</strong> as the classifier. While this will randomize things the most and in theory give you the most fair allocation of bandwidth, BUT there is also a good chance that it will break certain things like banking web sites and some forums. This is because often times a HTTP requests will generate several connections, so there is a chance that some requests may go out a different route than the initial one, and that will break secure web sites. For that reason I usually stick with <strong>src-address</strong> for <strong>PCC</strong> load balancing.</p>
<p>&nbsp;</p>
<pre> 

/ip address
add address=192.168.0.1/24 network=192.168.0.0 \
broadcast=192.168.0.255 interface=Local
add address=192.168.1.2/24 network=192.168.1.0 \
broadcast=192.168.1.255 interface=WAN1
add address=192.168.2.2/24 network=192.168.2.0 \
broadcast=192.168.2.255 interface=WAN2

/ip dns set allow-remote-requests=yes cache-max-ttl=1w \
cache-size=5000KiB max-udp-packet-size=512 servers=4.2.2.4,8.8.8.8

/ip firewall mangle
add chain=input in-interface=WAN1 action=mark-connection \
new-connection-mark=WAN1_conn
add chain=input in-interface=WAN2 action=mark-connection \
new-connection-mark=WAN2_conn

add chain=output connection-mark=WAN1_conn action=mark-routing \
new-routing-mark=to_WAN1
add chain=output connection-mark=WAN2_conn action=mark-routing \
new-routing-mark=to_WAN2

add chain=prerouting dst-address=192.168.1.0/24 action=accept in-interface=Local
add chain=prerouting dst-address=192.168.2.0/24 action=accept in-interface=Local

add chain=prerouting dst-address-type=!local in-interface=Local \
per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection \
new-connection-mark=WAN1_conn passthrough=yes
add chain=prerouting dst-address-type=!local in-interface=Local \
per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection \
new-connection-mark=WAN2_conn passthrough=yes

add chain=prerouting connection-mark=WAN1_conn in-interface=Local \
action=mark-routing new-routing-mark=to_WAN1
add chain=prerouting connection-mark=WAN2_conn in-interface=Local \
action=mark-routing new-routing-mark=to_WAN2

/ip route
add dst-address=0.0.0.0/0 gateway=192.168.1.1 routing-mark=to_WAN1 \
check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.2.1 routing-mark=to_WAN2 \
check-gateway=ping

add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.2.1 distance=2 check-gateway=ping

/ip firewall nat
add chain=srcnat out-interface=WAN1 action=masquerade
add chain=srcnat out-interface=WAN2 action=masquerade
&nbsp;
</pre>
<p><strong> </strong></p>
<h2>PCC WITH UN-EQUAL WAN LINKS</h2>
<p>If you have Un-Equal WAN Links, for example WAN,1 is of 4MB and WAN,2 is of 8 Mb, and you want to force MT to use WAN42link more then other because of its capacity, Then you have to Add more PCC rules assigning the same two marks to a specific link i.e WAN2 , something like</p>
<p>Code:</p>
<p>&nbsp;</p>
<pre>add chain=prerouting dst-address-type=!local in-interface=Local \
per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection \
new-connection-mark=WAN1_conn passthrough=yes
add chain=prerouting dst-address-type=!local in-interface=Local \
per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection \
new-connection-mark=WAN2_conn passthrough=yes
add chain=prerouting dst-address-type=!local in-interface=Local \
per-connection-classifier=both-addresses-and-ports:2/2 action=mark-connection \
new-connection-mark=WAN2_conn passthrough=yes</pre>
<p>&nbsp;</p>
<h2>PCC WITH HOTSPOT (Reference)</h2>
<p>&nbsp;</p>
<pre>
/ip firewall nat add action=accept chain=pre-hotspot \
disabled=no dst-address-type=!local hotspot=auth
&nbsp;
</pre>
<div class="wp-about-author-containter-top" style="background-color:#FFEAA8;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=100&#038;d=mm&#038;r=g' srcset='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=200&#038;d=mm&#038;r=g 2x' class='author_gravatar left  avatar-100 photo' height='100' width='100' loading='lazy'/></div><div class="wp-about-author-text" style="margin-left:140px"><h3><a href='/author/vaheed/' title='vaheeD'>vaheeD</a></h3><p></p><p><a href='/author/vaheed/' title='More posts by vaheeD'>More Posts</a>  - <a href='https://plus.google.com/103839803047317952696' title='vaheeD'>Website</a> </p><p class="wpa-nomargin">Follow Me:<br /><a class='wpa-social-icons' href='http://www.facebook.com/vaheet'><img src='/wp-content/plugins/wp-about-author/images/facebook.png' alt='Facebook'/></a><a class='wpa-social-icons' href='https://plus.google.com/103839803047317952696'><img src='/wp-content/plugins/wp-about-author/images/googleplus.png' alt='Google Plus'/></a></p></div></div>The post <a href="/mikrotik-dual-wan-load-balancing-using-pcc/">Mikrotik DUAL WAN Load Balancing using PCC</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></content:encoded>
					
					<wfw:commentRss>/mikrotik-dual-wan-load-balancing-using-pcc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MikroTik Monitoring With Munin</title>
		<link>/mikrotik-monitoring-with-munin/</link>
					<comments>/mikrotik-monitoring-with-munin/#respond</comments>
		
		<dc:creator><![CDATA[vaheeD]]></dc:creator>
		<pubDate>Mon, 21 Jan 2013 13:46:53 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MikroTik]]></category>
		<guid isPermaLink="false">/?p=344</guid>

					<description><![CDATA[<p>Introduction Munin is a very powerful, feature rich monitoring server based on Tobias Oetiker&#8217;s RRDTool. The monitoring server runs every 5 minutes via cron and connect to various configured nodes. Each node runs a daemon listening for connections from the server, and executes a wide range of completely customisable scripts to return data to the munin server... </p>
<p><a class="small button secondary" href="/mikrotik-monitoring-with-munin/">Continue Reading</a></p>
The post <a href="/mikrotik-monitoring-with-munin/">MikroTik Monitoring With Munin</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></description>
										<content:encoded><![CDATA[<p><span id="more-344"></span></p>
<h1>Introduction</h1>
<p>Munin is a very powerful, feature rich monitoring server based on Tobias Oetiker&#8217;s RRDTool. The monitoring server runs every 5 minutes via cron and connect to various configured nodes. Each node runs a daemon listening for connections from the server, and executes a wide range of completely customisable scripts to return data to the munin server to generate graphs from.</p>
<p>As the backend graphing engine is based on RRDTool, any feature available in RRDTool is also available as options to Munin. The really nice thing about Munin and RRDTool, is that negative numbers can be graphed.</p>
<p>In this article I will explain how to install Munin as well as Munin-Node on a single server, and how to get Munin to probe your Mikrotik devices via SNMP as well as Telnet (Depending on the type of graph). I would strongly advise that time is spend reading the Munin as well as RRDTool documentation available at the web sites, so that a clear understanding can be obtained on how Munin operates and generates graphs.</p>
<h1>Munin Server Installation and Configuration</h1>
<p>Munin-Server is only available in Linux format. As I use Ubuntu and FreeBSD only, I will base this installation guide on a Ubuntu Linux server. Once the general packages has been installed, the configuration should however be pretty much the same to any Munin installation, regardless of the flavour of Linux preferred.</p>
<h2>Installing Munin</h2>
<p>In our case, we are going to run both munin as well as munin-node on the same machine. Untill such time that (fingers crossed) we can get a munin-node integrated into Mikrotik, the node will be required to run on the same server as Munin itself for best results.</p>
<p>As such, and being Ubuntu, we simply install the two packages, and make sure that we meet all the requirements in terms of dependencies. Additionally, for the Mikrotik scripts below to work, we also need to install the Net::SNMP, and Net::Telnet::Cisco Perl packages.</p>
<pre>$sudo apt-get install munin munin-node libnet-telnet-cisco-perl libnet-snmp-perl</pre>
<p>Now that we have all that we need installed (I am presuming you have Apache / tinyHTTP Web server already installed), it&#8217;s time to head off and do some basic configurations.</p>
<h2>Configuring the Master</h2>
<p>First things first, we need to edit the Master&#8217;s configuration file, by default, <b>/etc/munin/munin.conf</b>. This is the file where you configure every munin-node that the master needs to poll. As we are using a simple model here, we are only going be to polling localhost, which is accessible via 127.0.0.1 (If it isn&#8217;t you have bigger problems than monitoring ;-) ).</p>
<p>Your Munin configuration should thus look something similar to below (Paths may vary on different distributions):</p>
<pre>dbdir       /var/lib/munin/
htmldir     /var/www/munin/
logdir      /var/log/munin
rundir      /var/run/munin/

[localhost]
        address 127.0.0.1</pre>
<p><b>dbdir</b> will be the database where munin stores its internal state files, as well as the RRD database files<br />
<b>htmldir</b> will be the directory where munin will greate the appropriate html files as well as png images<br />
<b>logdir</b> keeps various log files of what munin is doing &#8211; useful when things don&#8217;t go as you intended<br />
<b>rundir</b> munin pid files, lock files, etc. Nothing fancy here really</p>
<p>Additionally, we have configured one active node which munin needs to poll. Munin will connect to 127.0.0.1 on 4949/TCP (default port that munin runs on) and pull this node for any nodes and/or scripts configured to be graphed.</p>
<h2>Configuring the Node</h2>
<p>Whilst Munin-Node is pretty secure out of the box, there are some basic things we need to change. Even though the node only authorizes just localhost to gather data from it, it listens by default on all IP addresses. As a security measure, we are going to alter the munin-node configuration file and ensure that we are only listening on localhost for connections from the Munin Server. As such, we need to open up <b>/etc/munin/munin-node.conf</b> in your faviourite editor of choice.</p>
<p>We need to alter the <b>Host</b> value in order to bind munin-node to the 127.0.0.1 address. Your config should now look like this:</p>
<pre>#host *
host 127.0.0.1</pre>
<p>This is about all that you need to do to get Munin working. As we have modified the configurations, we need to restart the munin-node service, in Ubuntu I issue:</p>
<pre>$ /etc/init.d/munin-node restart</pre>
<h2>Configuring Apache</h2>
<p>Apache needs access to Munin&#8217;s htmldir configuration in order for you to see the pretty graphs and generated html in the browser of your choice. As such we need to configure some Alias and Directory settings in Apache&#8217;s configuration. This can be done either inside a Virtual Host of your choice, or in apache&#8217;s main configuration. As a example, I have elected to configure a new Apache Virtual Host which will only serve up the munin pages. The Virtual Host&#8217;s configuration will be something similar to</p>
<pre>&lt;VirtualHost *:80&gt;
        ServerAdmin webmaster@localhost
        ServerName monitor.example.com
        DocumentRoot /var/www/munin
        &lt;Directory /&gt;
                Options FollowSymLinks
                AllowOverride None
        &lt;/Directory&gt;
        CustomLog /var/log/apache2/monitor.example.com.access.log combined
        ErrorLog /var/log/apache2/monitor.example.com.error.log
        ServerSignature On
&lt;/VirtualHost&gt;</pre>
<p>Verify that your syntax of the Apache configuration file is correct (apache2ctl -t), and then restart your Apache web server to enable the newly configured Virtual Host</p>
<pre>$ sudo apache2ctl -t
Syntax OK
$ sudo apache2ctl graceful
$</pre>
<p>Open up your faviourite web browser, browse to <a href="http://monitor.example.com/" rel="nofollow">http://monitor.example.com/</a>, and you should have pretty graphs for the server on which you are running munin.</p>
<p>&nbsp;</p>
<h1>Munin Node for Mikrotik</h1>
<p>To configure Munin to monitor a Mikrotik device, is really a two step process. In a conventional configuration where Munin-Node is available on the target being monitored, we normally would only need to configure Munin to monitor the node in question, however, due to the lack of Munin on Mikrotik, we need to <i>alias</i> the Mikrotik node to our configured Munin-Node server in order to execute scripts on our Mikrotik device. The downside of this is that all scripts will need to be executed twice and as such scripts which use Telnet to obtain data will login two times into the routers that is being monitored.</p>
<p>&nbsp;</p>
<h2>Configuring additional Nodes in Munin</h2>
<p>The first step in monitoring Mikrotik devices, is to configure the nodes as a alias to our locally running Munin-Node. This is done by editing the Munin-Node configuration file, by default located at <b>/etc/munin/munin.conf</b>. We edit this file using our faviourite editor of choice, and define the two new nodes as listed below.</p>
<p>The part in the brackets define the node&#8217;s name, and for sanity purposes I recommend that the FQDN always be used to make your life allot easier in the following sections. The address, will always be pointing to 127.0.0.1 as Munin needs to connect to our only <i>real</i> munin-node we have running on localhost.</p>
<pre>[node1.somewhere.com]
    address 127.0.0.1

[node2.somewhere.com]
    address 127.0.0.1</pre>
<p>&nbsp;</p>
<h2>Monitoring CPU Usage</h2>
<p>Now that we have our Munin node configured, we need to configure the scripts inside Munin-Node to poll our Mikrotik Devices. This is where things get complicated, and as a example I will configure a script to monitor and graph both our router&#8217;s CPU usage. The scripts are by default located in<b>/etc/munin/plugins/</b>. The naming of these scripts are very important, and attention need to be given to the location as well as names.</p>
<p>Our CPU Monitoring script utilises SNMP, therefore, make sure that SNMP is enabled on your routers, and that the Server running munin has access to query your router via SNMP. A simple test can be performed to ensure that this is the case:</p>
<pre>$ snmpget -v 1 -c public node1.somewhere.com .1.3.6.1.2.1.25.3.3.1.2.1
HOST-RESOURCES-MIB::hrProcessorLoad.1 = INTEGER: 5
$</pre>
<p>Congratulations, we have just obtained our CPU usage of our router via a simple SNMP query. Should this query not be successfull, it means that Munin will be unable to query your router via SNMP, and you need to correct this before proceeding.</p>
<p>Now that we know SNMP queries are working like they should, we need to get a simple script operational to pull this data into Munin for monitoring&#8230; Copy the script below to query the nodes via SNMP for CPU usage, and save it in the <b>/etc/munin/plugins</b> directory having the specific file name of mikrotikcpu_node1.somewhere.com (where node1.somewhere.com is the same as the node name you configured earlier in <b>/etc/munin/munin.conf</b>). These names MUST be the same, otherwise, the scripts <b>WILL</b> fail.</p>
<p>Mikrotik CPU Usage via SNMP:</p>
<pre>#!/usr/bin/perl
###############################################################################
use diagnostics;
use Net::SNMP;
use strict;
use warnings;
###############################################################################
my $CPUOID = ".1.3.6.1.2.1.25.3.3.1.2.1";
my $SNMPCommunity = "public";
my $SNMPPort = "161";

###############################################################################
## Determine Hostname
my $Host = undef;
$0 =~ /mikrotikcpu_(.+)*$/;
unless ($Host = $1) {
  exit 2;
}

###############################################################################
## Initiate SNMP Session
my ($Session, $Error) = Net::SNMP-&gt;session (-hostname  =&gt; $Host,
                                            -community =&gt; $SNMPCommunity,
                                            -port      =&gt; $SNMPPort,
                                            -timeout   =&gt; 60,
                                            -retries   =&gt; 5,
                                            -version   =&gt; 1);
if (!defined($Session)) {
  die "Croaking: $Error";
}

###############################################################################
## Configuration
if ($ARGV[0] &amp;&amp; $ARGV[0] eq "config") {
  print "host_name " . $Host . "\n";
  print "graph_args -l 0 -r --vertical-label percent --lower-limit 0 --upper-limit 100\n";
  print "graph_title CPU usage\n";
  print "graph_category system\n";
  print "graph_info This graph shows the router's CPU usage.\n";
  print "graph_order Total\n";
  print "graph_vlabel %\n";
  print "graph_scale no\n";
  print "Total.label CPU Usage\n";
  print "Total.draw AREA\n";
  print "Total.warning 60\n";
  print "Total.critical 90\n";
  $Session-&gt;close;
  exit;
}

###############################################################################
## Execution
if (my $Result = $Session-&gt;get_request(-varbindlist =&gt; [$CPUOID])) {
  print "Total.value " . $Result-&gt;{$CPUOID} . "\n";
  $Session-&gt;close;
  exit;
}</pre>
<p>Next, we need to make sure that Munin can execute the file, and that the script os operating successfully</p>
<pre>$ chmod u+x /etc/munin/plugins/mikrotikcpu_node1.somewhere.com
$ chown munin:munin /etc/munin/plugins/mikrotikcpu_node1.somewhere.com
$ /etc/munin/plugins/mikrotikcpu_node1.somewhere.com config
host_name node1.somewhere.com
graph_args -l 0 -r --vertical-label percent --lower-limit 0 --upper-limit 100
graph_title CPU usage
graph_category system
graph_info This graph shows the router's CPU usage.
graph_order Total
graph_vlabel %
graph_scale no
Total.label CPU Usage
Total.draw AREA
Total.warning 60
Total.critical 90</pre>
<p>Our scripts seems to be working fine. <b>Very</b> important, when the script is executed with the config parameter, make 100% sure that the value of the host_name configuration variable is returned correctly, and that it is identical to the name of the node configured in <b>/etc/munin/munin.conf</b>.</p>
<p>The last step is to restart our munin-node, as we have made changes to it (we added more scripts). We simply execute the restart command:</p>
<pre>$ /etc/init.d/munin-node restart</pre>
<p>Now that we have restarted munin-node, we can also test the configuration, and see what munin will be seeing when quering the nodes that we have configured. In order to do this, we are going to telnet into Munin-Node, and obtain the graph data ourselves. This is done by telneting to the munin-node engine, running at 127.0.0.1 port 4949 (if you didn&#8217;t change any other configurations except that mentioned in this document), and we then send the &#8216;<b>nodes</b>&#8216; command, which will give us a list of nodes running under the munin-node that we have configured.</p>
<pre>$ telnet localhost 4949
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
# munin node at localhost.somewhere.com
nodes
localhost
node1.somewhere.com
node2.somewhere.com
.</pre>
<p>It seems to be perfect. We have localhost, node1.somewhere.com, as well as node2.somewhere.com. Let&#8217;s see what plugins is available under each node. Again, we telnet into the munin-node deamon, but this time, we will execute two commands, &#8216;<b>list node1.somewhere.com</b>&#8216; and &#8216;<b>list node2.somewhere.com</b>&#8216;. This will list all the plugins currently configured for these two nodes.</p>
<pre>$ telnet 127.0.0.1 4949
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
# munin node at localhost.somewhere.com
list node1.somwehere.com
mikrotikcpu_node1.somewhere.com
list node2.somewhere.com
mikrotikcpu_node2.somewhere.com</pre>
<p>We can see in both instances, the mikrotikcpu_ script has been configured, and is activated for both our mikrotik nodes. We can also attempt to fetch the data by executing a &#8216;<b>fetch mikrotikcpu_node1.somewhere.com</b>&#8216; command in munin, at which time munin-node will query the Mikrotik Router, and return the data back through Munin.</p>
<p>If all went well, you should by now have two additional nodes listed on the Web Interface munin has, and both these two additional nodes should have graphs indicating the CPU usage as a % value, between 0 and 100.</p>
<h1>Available Scripts</h1>
<p>From where on out, the installation of the scripts are pretty much the same, regardless of what you monitor or how. Each script that I have so far will be covered in the remaining sections, including details on what is required, the naming of the scripts, limitations, as well as installation instructions. As mentioned previously, if there is any monitoring not covered that you would like to see, please let me know and I will see about writing scritps to do what is required.</p>
<h2>mikrotikcpu_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Quick &amp; Easy</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>SNMP</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Mikrotikcpu_.png"><img loading="lazy" alt="Mikrotikcpu .png" src="http://wiki.mikrotik.com/images/a/af/Mikrotikcpu_.png" width="495" height="264" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/perl
###############################################################################
use diagnostics;
use Net::SNMP;
use strict;
use warnings;
###############################################################################
my $CPUOID = ".1.3.6.1.2.1.25.3.3.1.2.1";
my $SNMPCommunity = "public";
my $SNMPPort = "161";

###############################################################################
## Determine Hostname
my $Host = undef;
$0 =~ /mikrotikcpu_(.+)*$/;
unless ($Host = $1) {
  exit 2;
}

###############################################################################
## Initiate SNMP Session
my ($Session, $Error) = Net::SNMP-&gt;session (-hostname  =&gt; $Host,
                                            -community =&gt; $SNMPCommunity,
                                            -port      =&gt; $SNMPPort,
                                            -timeout   =&gt; 60,
                                            -retries   =&gt; 5,
                                            -version   =&gt; 1);
if (!defined($Session)) {
  die "Croaking: $Error";
}

###############################################################################
## Configuration
if ($ARGV[0] &amp;&amp; $ARGV[0] eq "config") {
  print "host_name " . $Host . "\n";
  print "graph_args -l 0 -r --vertical-label percent --lower-limit 0 --upper-limit 100\n";
  print "graph_title CPU usage\n";
  print "graph_category system\n";
  print "graph_info This graph shows the router's CPU usage.\n";
  print "graph_order Total\n";
  print "graph_vlabel %\n";
  print "graph_scale no\n";
  print "Total.label CPU Usage\n";
  print "Total.draw AREA\n";
  print "Total.warning 60\n";
  print "Total.critical 90\n";
  $Session-&gt;close;
  exit;
}

###############################################################################
## Execution
if (my $Result = $Session-&gt;get_request(-varbindlist =&gt; [$CPUOID])) {
  print "Total.value " . $Result-&gt;{$CPUOID} . "\n";
  $Session-&gt;close;
  exit;
}</pre>
<p>&nbsp;</p>
<h2>mikrotikdiskspace_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Quick &amp; Easy</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>SNMP</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Mikrotikdiskspace_.png"><img loading="lazy" alt="Mikrotikdiskspace .png" src="http://wiki.mikrotik.com/images/f/f0/Mikrotikdiskspace_.png" width="495" height="276" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/perl
###############################################################################
use diagnostics;
use Net::SNMP;
use strict;
use warnings;
###############################################################################
my $DiskTotalOID = ".1.3.6.1.2.1.25.2.3.1.5.1";
my $DiskUsedOID = ".1.3.6.1.2.1.25.2.3.1.6.1";
my $SNMPCommunity = "public";
my $SNMPPort = "161";

###############################################################################
## Determine Hostname
my $Host = undef;
$0 =~ /mikrotikdiskspace_(.+)*$/;
unless ($Host = $1) {
  exit 2;
}

###############################################################################
## Initiate SNMP Session
my ($Session, $Error) = Net::SNMP-&gt;session (-hostname  =&gt; $Host,
                                            -community =&gt; $SNMPCommunity,
                                            -port      =&gt; $SNMPPort,
                                            -timeout   =&gt; 60,
                                            -retries   =&gt; 5,
                                            -version   =&gt; 1);
if (!defined($Session)) {
  die "Croaking: $Error";
}

###############################################################################
## Configuration
if ($ARGV[0] &amp;&amp; $ARGV[0] eq "config") {
  my $Result = $Session-&gt;get_request(-varbindlist =&gt; [$DiskTotalOID]);
  print "host_name " . $Host . "\n";
  print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($Result-&gt;{$DiskTotalOID} * 1024) . "\n";
  print "graph_title Disk Space usage\n";
  print "graph_category system\n";
  print "graph_info This graph shows the router's Disk Space usage.\n";
  print "graph_order Total Used\n";
  print "graph_vlabel bytes\n";
  print "Total.label Total Disk Space\n";
  print "Total.draw AREA\n";
  print "Used.label Used Disk Space\n";
  print "Used.draw AREA\n";
  $Session-&gt;close;
  exit;
}

###############################################################################
## Execution
if (my $Result = $Session-&gt;get_request(-varbindlist =&gt; [$DiskTotalOID, $DiskUsedOID])) {
  print "Total.value " . ($Result-&gt;{$DiskTotalOID} * 1024) . "\n";
  print "Used.value " . ($Result-&gt;{$DiskUsedOID} * 1024) . "\n";
  $Session-&gt;close;
  exit;
}</pre>
<p>&nbsp;</p>
<h2>mikrotikmemory_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Quick &amp; Easy</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>SNMP</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Mikrotikmemory_.png"><img loading="lazy" alt="Mikrotikmemory .png" src="http://wiki.mikrotik.com/images/a/ab/Mikrotikmemory_.png" width="495" height="276" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/perl
###############################################################################
use diagnostics;
use Net::SNMP;
use strict;
use warnings;
###############################################################################
my $MemTotalOID = ".1.3.6.1.2.1.25.2.3.1.5.2";
my $MemUsedOID = ".1.3.6.1.2.1.25.2.3.1.6.2";
my $SNMPCommunity = "public";
my $SNMPPort = "161";

###############################################################################
## Determine Hostname
my $Host = undef;
$0 =~ /mikrotikmemory_(.+)*$/;
unless ($Host = $1) {
  exit 2;
}

###############################################################################
## Initiate SNMP Session
my ($Session, $Error) = Net::SNMP-&gt;session (-hostname  =&gt; $Host,
                                            -community =&gt; $SNMPCommunity,
                                            -port      =&gt; $SNMPPort,
                                            -timeout   =&gt; 60,
                                            -retries   =&gt; 5,
                                            -version   =&gt; 1);
if (!defined($Session)) {
  die "Croaking: $Error";
}

###############################################################################
## Configuration
if ($ARGV[0] &amp;&amp; $ARGV[0] eq "config") {
  my $Result = $Session-&gt;get_request(-varbindlist =&gt; [$MemTotalOID]);
  print "host_name " . $Host . "\n";
  print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($Result-&gt;{$MemTotalOID} * 1024) . "\n";
  print "graph_title Memory usage\n";
  print "graph_category system\n";
  print "graph_info This graph shows the router's memory usage.\n";
  print "graph_order Total Used\n";
  print "graph_vlabel bytes\n";
  print "Total.label Total Memory\n";
  print "Total.draw AREA\n";
  print "Used.label Used Memory\n";
  print "Used.draw AREA\n";
  $Session-&gt;close;
  exit;
}

###############################################################################
## Execution
if (my $Result = $Session-&gt;get_request(-varbindlist =&gt; [$MemTotalOID, $MemUsedOID])) {
  print "Total.value " . ($Result-&gt;{$MemTotalOID} * 1024) . "\n";
  print "Used.value " . ($Result-&gt;{$MemUsedOID} * 1024) . "\n";
  $Session-&gt;close;
  exit;
}</pre>
<p>&nbsp;</p>
<h2>mikrotikppp_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Easy to Intermediate</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>Telnet (RO Access, Single Login)</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Mikrotikppp-day.png"><img loading="lazy" alt="Mikrotikppp-day.png" src="http://wiki.mikrotik.com/images/7/71/Mikrotikppp-day.png" width="501" height="319" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/perl
#
# Beware - some perl Net::Telnet::Cisco packages are broken and you may need
# to manually hack a 'g' out of a file if you get an error message!
# Nick Barnes 20090610
#
###############################################################################
use diagnostics;
use Net::Telnet::Cisco;
use strict;
use warnings;
##############################################################################
my $TelnetPort = "23";
my $TelnetUser = "username";
my $TelnetPass = "password";

###############################################################################
## Determine Hostname
my $Host = undef;
$0 =~ /mikrotikppp_(.+)*$/;
unless ($Host = $1) {
  exit 2;
}

###############################################################################
## Initiate Telnet Session
my $MT = Net::Telnet::Cisco-&gt;new(Host    =&gt; $Host,
                                 Port    =&gt; $TelnetPort,
                                 Prompt  =&gt; '/[\&gt;\#] $/',
                                 Timeout =&gt; 30);

###############################################################################
## Configuration
if ($ARGV[0] &amp;&amp; $ARGV[0] eq "config") {
  print "host_name " . $Host . "\n";
  print "graph_args --base 1000 -l 0 -r --lower-limit 0\n";
  print "graph_title Active PPP Client Connections\n";
  print "graph_vlabel number\n";
  print "graph_category network\n";
  print "graph_info This graph shows the active amount of ppp connections\n";
  print "graph_order async isdn l2tp ovpn pppoe pptp\n";
  print "async.label async\n";
  print "async.info ASync Connections\n";
  print "isdn.label isdn\n";
  print "isdn.info ISDN Connections\n";
  print "l2tp.label l2tp\n";
  print "l2tp.info L2TP Connections\n";
  print "ovpn.label ovpn\n";
  print "ovpn.info OVPN Connections\n";
  print "pppoe.label pppoe\n";
  print "pppoe.info PPPoE Connections\n";
  print "pptp.label pptp\n";
  print "pptp.info PPTP Connections\n";
  exit;
}

###############################################################################
## Execution
if (!defined($MT-&gt;login($TelnetUser . "+ct", $TelnetPass))) {
  die "Croaking: $MT-&gt;error";
} else {
  my $async = 0;
  my $isdn = 0;
  my $ltp = 0;
  my $ovpn = 0;
  my $pppoe = 0;
  my $pptp = 0;
  my @Output = $MT-&gt;cmd("/ppp active print without-paging terse");
  foreach my $Line (@Output) {
    my ($tmp, $rest) = split(/ name/, $Line, 2);
    if ($rest &amp;&amp; $rest =~ /async/ ) { $async++; };
    if ($rest &amp;&amp; $rest =~ /isdn/ ) { $isdn++; };
    if ($rest &amp;&amp; $rest =~ /l2tp/ ) { $ltp++; };
    if ($rest &amp;&amp; $rest =~ /ovpn/ ) { $ovpn++; };
    if ($rest &amp;&amp; $rest =~ /pppoe/ ) { $pppoe++; };
    if ($rest &amp;&amp; $rest =~ /pptp/ ) { $pptp++; };
  }
  print "async.value " . $async . "\n";
  print "isdn.value " . $isdn . "\n";
  print "l2tp.value " . $ltp . "\n";
  print "ovpn.value " . $ovpn . "\n";
  print "pppoe.value " . $pppoe . "\n";
  print "pptp.value " . $pptp . "\n";
  exit;
}</pre>
<h2>mikrotikradius_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Easy to Intermediate</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>Telnet (RO Access, Single Login)</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Mikrotikradius_.png"><img loading="lazy" alt="Mikrotikradius .png" src="http://wiki.mikrotik.com/images/4/46/Mikrotikradius_.png" width="495" height="336" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/perl
###############################################################################
use diagnostics;
use Net::Telnet::Cisco;
use strict;
use warnings;
###############################################################################
my $RadiusHost = "192.168.1.251";       ## This is the address of the Radius
                                        ## Server we monitor as configured in
                                        ## /radius on Mikrotik
my $TelnetPort = "23";
my $TelnetUser = "username";
my $TelnetPass = "password";

###############################################################################
## Determine Hostname
my $Host = undef;
$0 =~ /mikrotikradius_(.+)*$/;
unless ($Host = $1) {
  exit 2;
}

###############################################################################
## Initiate Telnet Session
my $MT = Net::Telnet::Cisco-&gt;new(Host    =&gt; $Host,
                                 Port    =&gt; $TelnetPort,
                                 Prompt  =&gt; '/[\&gt;\#] $/',
                                 Timeout =&gt; 30);
if (!defined($MT-&gt;login($TelnetUser . "+ct", $TelnetPass))) {
  die "Croaking: $MT-&gt;error";
}

###############################################################################
## Configuration
if ($ARGV[0] &amp;&amp; $ARGV[0] eq "config") {
  print "host_name " . $Host . "\n";
  print "graph_args --base 1000 -l 0 -r --lower-limit 0\n";
  print "graph_title Radius Statistics\n";
  print "graph_vlabel requests/s\n";
  print "graph_category system\n";
  print "graph_info This graph shows Radius usage.\n";
  print "graph_period second\n";
  print "graph_order pending requests accepts rejects resends timeouts badreplies\n";
  print "pending.label pending\n";
  print "pending.info Requests Pending\n";
  print "requests.label requests\n";
  print "requests.info Requests Completed\n";
  print "requests.type COUNTER\n";
  print "accepts.label accepts\n";
  print "accepts.info Authentication Accepted\n";
  print "accepts.type COUNTER\n";
  print "rejects.label rejects\n";
  print "rejects.info Authentication Rejected\n";
  print "rejects.type COUNTER\n";
  print "resends.label resends\n";
  print "resends.info Request Resends\n";
  print "resends.type COUNTER\n";
  print "timeouts.label timeouts\n";
  print "timeouts.info Request Timeouts\n";
  print "timeouts.type COUNTER\n";
  print "badreplies.label badreplies\n";
  print "badreplies.info Bad Replies\n";
  print "badreplies.type COUNTER\n";
  exit;
}

###############################################################################
## Execution
my ($tmp, $pending, $requests, $accepts, $rejects, $resends, $timeouts, $badreplies, $rtt) = undef;
my @Output = $MT-&gt;cmd("/radius monitor [find address=" . $RadiusHost . "] once");
foreach my $Line (@Output) {
  if ($Line =~ /pending/) {
    ($tmp, $pending) = split(/: /, $Line, 2);
  } elsif ($Line =~ /requests/) {
    ($tmp, $requests) = split(/: /, $Line, 2);
  } elsif ($Line =~ /accepts/) {
    ($tmp, $accepts) = split(/: /, $Line, 2);
  } elsif ($Line =~ /rejects/) {
    ($tmp, $rejects) = split(/: /, $Line, 2);
  } elsif ($Line =~ /resends/) {
    ($tmp, $resends) = split(/: /, $Line, 2);
  } elsif ($Line =~ /timeouts/) {
    ($tmp, $timeouts) = split(/: /, $Line, 2);
  } elsif ($Line =~ /bad-replies/) {
    ($tmp, $badreplies) = split(/: /, $Line, 2);
  }
}
print "pending.value " . $pending;
print "requests.value " . $requests;
print "accepts.value " . $accepts;
print "rejects.value " . $rejects;
print "resends.value " . $resends;
print "timeouts.value " . $timeouts;
print "badreplies.value " . $badreplies;</pre>
<p>&nbsp;</p>
<h2>mikrotikroutes_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Easy to Intermediate</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>Telnet (RO Access, Single Login)</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Mikrotikroutes_.png"><img loading="lazy" alt="Mikrotikroutes .png" src="http://wiki.mikrotik.com/images/c/c1/Mikrotikroutes_.png" width="481" height="408" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/perl
###############################################################################
use diagnostics;
use Net::Telnet::Cisco;
use strict;
use warnings;
##############################################################################
my ($total, $disabled, $active, $dynamic, $connected, $static, $rip, $bgp, $ospf, $mme, $blackhole, $unreachable, $prohibit) = undef;
my $TelnetPort = "23";
my $TelnetUser = "username";
my $TelnetPass = "password";

###############################################################################
## Determine Hostname
my $Host = undef;
$0 =~ /mikrotikroutes_(.+)*$/;
unless ($Host = $1) {
  exit 2;
}

###############################################################################
## Initiate Telnet Session
my $MT = Net::Telnet::Cisco-&gt;new(Host    =&gt; $Host,
                                 Port    =&gt; $TelnetPort,
                                 Prompt  =&gt; '/[\&gt;\#] $/',
                                 Timeout =&gt; 30);

###############################################################################
## Configuration
if ($ARGV[0] &amp;&amp; $ARGV[0] eq "config") {
  print "host_name " . $Host . "\n";
  print "graph_args --base 1000 -l 0 -r --lower-limit 0\n";
  print "graph_title Routing Tables\n";
  print "graph_vlabel number\n";
  print "graph_category network\n";
  print "graph_info This graph shows the routing table size\n";
  print "graph_order total disabled active dynamic connected static rip bgp ospf mme blackhole unreachable prohibit\n";
  print "total.label total\n";
  print "total.info Total Routes\n";
  print "disabled.label disabled\n";
  print "disabled.info Total Disabled Routes\n";
  print "active.label active\n";
  print "active.info Total Active Routes\n";
  print "dynamic.label dynamic\n";
  print "dynamic.info Total Dynamic Routes\n";
  print "connected.label connected\n";
  print "connected.info Total Connected Routes\n";
  print "static.label static\n";
  print "static.info Total Static Routes\n";
  print "rip.label rip\n";
  print "rip.info Routes obtained via RIP\n";
  print "bgp.label bgp\n";
  print "bgp.info Routes obtained via BGP\n";
  print "ospf.label ospf\n";
  print "ospf.info Routes obtained via OSPF\n";
  print "mme.label mme\n";
  print "mme.info Routes obtained via MME\n";
  print "blackhole.label blackhold\n";
  print "blackhole.info Blackhole Routes\n";
  print "unreachable.label unreachable\n";
  print "unreachable.info Routes currently unreachable\n";
  print "prohibit.label prohibit\n";
  print "prohibit.info Prohibited routes\n";
  exit;
}

###############################################################################
## Execution
if (!defined($MT-&gt;login($TelnetUser . "+ct", $TelnetPass))) {
  die "Croaking: $MT-&gt;error";
} else {
  my @Output = $MT-&gt;cmd("/ip route print without-paging terse");
  $total = 0;
  $disabled = 0;
  $active = 0;
  $dynamic = 0;
  $connected = 0;
  $static = 0;
  $rip = 0;
  $bgp = 0;
  $ospf = 0;
  $mme = 0;
  $blackhole = 0;
  $unreachable = 0;
  $prohibit = 0;

  foreach my $Line (@Output) {
    $total = $total + 1;
    my ($tmp, $rest) = split(/  /, $Line, 2);
    if ($tmp &amp;&amp; $tmp =~ /X/) {$disabled = $disabled + 1;}
    if ($tmp &amp;&amp; $tmp =~ /A/) {$active = $active + 1;}
    if ($tmp &amp;&amp; $tmp =~ /D/) {$dynamic = $dynamic + 1;}
    if ($tmp &amp;&amp; $tmp =~ /C/) {$connected = $connected + 1;}
    if ($tmp &amp;&amp; $tmp =~ /S/) {$static = $static + 1;}
    if ($tmp &amp;&amp; $tmp =~ /r/) {$rip = $rip + 1;}
    if ($tmp &amp;&amp; $tmp =~ /b/) {$bgp = $bgp + 1;}
    if ($tmp &amp;&amp; $tmp =~ /o/) {$ospf = $ospf + 1;}
    if ($tmp &amp;&amp; $tmp =~ /m/) {$mme = $mme + 1;}
    if ($tmp &amp;&amp; $tmp =~ /B/) {$blackhole = $blackhole + 1;}
    if ($tmp &amp;&amp; $tmp =~ /U/) {$unreachable = $unreachable + 1;}
    if ($tmp &amp;&amp; $tmp =~ /P/) {$prohibit = $prohibit + 1;}
  }
  print "total.value " . $total . "\n";
  print "disabled.value " . $disabled . "\n";
  print "active.value " . $active . "\n";
  print "dynamic.value " . $dynamic . "\n";
  print "connected.value " . $connected . "\n";
  print "static.value " . $static . "\n";
  print "rip.value " . $rip . "\n";
  print "bgp.value " . $bgp . "\n";
  print "ospf.value " . $ospf . "\n";
  print "mme.value " . $mme . "\n";
  print "blackhole.value " . $blackhole . "\n";
  print "unreachable.value " . $unreachable . "\n";
  print "prohibit.value " . $prohibit . "\n";
  exit;
}</pre>
<h2>mikrotikwirelessinterface_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Easy to Intermediate</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>Telnet (RO Access, Single Login)</td>
</tr>
<tr>
<td>Notes:</td>
<td>Monitors Wireless Interface (CCQ, Signals, etc) on CPE side only, Interface MUST BE in station mode to operate, Only monitors the first interface found (Interface number 0 in /interface wireless print</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Mikrotikwirelessinterface_.png"><img loading="lazy" alt="Mikrotikwirelessinterface .png" src="http://wiki.mikrotik.com/images/c/c7/Mikrotikwirelessinterface_.png" width="495" height="348" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/perl
###############################################################################
use diagnostics;
use Net::Telnet::Cisco;
use strict;
use warnings;
##############################################################################
my $TelnetPort = "23";
my $TelnetUser = "username";
my $TelnetPass = "password";

###############################################################################
## Determine Hostname
my $Host = undef;
$0 =~ /mikrotikwirelessinterface_(.+)*$/;
unless ($Host = $1) {
  exit 2;
}

###############################################################################
## Initiate Telnet Session
my $MT = Net::Telnet::Cisco-&gt;new(Host    =&gt; $Host,
                                 Port    =&gt; $TelnetPort,
                                 Prompt  =&gt; '/[\&gt;\#] $/',
                                 Timeout =&gt; 30);

###############################################################################
## Configuration
if ($ARGV[0] &amp;&amp; $ARGV[0] eq "config") {
  print "host_name " . $Host . "\n";
  print "graph_args -l 0 --lower-limit -100 --upper-limit 100\n";
  print "graph_title Wireless Interface Quality (MACAddress)\n";
  print "graph_vlabel Comms Quality\n";
  print "graph_category network\n";
  print "graph_info This graph shows the wireless interface statistics\n";
  print "graph_order txccq rxccq txsignal txrate rxrate acttimeout noisefloor\n";
  print "graph_scale no\n";
  print "txccq.label TX CCQ (%)\n";
  print "rxccq.label RX CCQ (%)\n";
  print "txsignal.label TX Signal Strength (dBm)\n";
  print "acttimeout.label ACT Timeout (us)\n";
  print "noisefloor.label Noise Floor (dBm)\n";
  print "txrate.label TX Rate (Mbps)\n";
  print "rxrate.label RX Rate (Mbps)\n";
  exit;
}

###############################################################################
## Execution
if (!defined($MT-&gt;login($TelnetUser . "+ct", $TelnetPass))) {
  die "Croaking: $MT-&gt;error";
} else {
  my @Output = $MT-&gt;cmd("/interface wireless monitor 0 once\nD\n");
  my ($rest, $tmp, $txccq, $rxccq, $txsignal, $stn, $otxccq, $acttimeout, $noisefloor, $txrate, $rxrate) = undef;
  foreach my $Line (@Output) {
    if (($Line =~ /tx-ccq/ &amp;&amp; $Line !~ /overall-tx-ccq/) &amp;&amp; $Line =~ m/(\d+)/) {
      $txccq = $1;
    }
    if ($Line =~ /rx-ccq/ &amp;&amp; $Line =~ m/(\d+)/) {
      $rxccq = $1;
    }
    if ($Line =~ /tx-signal-strength/ &amp;&amp; $Line =~ m/(.\d+)/) {
      $txsignal = $1;
    }
    if ($Line =~ /current-ack-timeout/ &amp;&amp; $Line =~ m/(.\d+)/) {
      $acttimeout = $1;
    }
    if ($Line =~ /noise-floor/ &amp;&amp; $Line =~ m/(.\d+)/) {
      $noisefloor = $1;
    }
    if ($Line =~ /tx-rate/ &amp;&amp; $Line =~ m/(\d+)/) {
      $txrate = $1;
    }
    if ($Line =~ /rx-rate/ &amp;&amp; $Line =~ m/(\d+)/) {
      $rxrate = $1;
    }
  }
  print "txccq.value " . $txccq . "\n";
  print "rxccq.value " . $rxccq . "\n";
  print "txsignal.value " . $txsignal . "\n";
  print "acttimeout.value " . $acttimeout . "\n";
  print "noisefloor.value " . $noisefloor . "\n";
  print "txrate.value " . $txrate . "\n";
  print "rxrate.value " . $rxrate . "\n";
  exit;
}</pre>
<p>&nbsp;</p>
<h2>mikrotikwirelessregistration_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Advanced</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>Telnet (RO Access, Double Login)</td>
</tr>
<tr>
<td>Notes:</td>
<td>Script is NOT YET 100%. The registration table is not parsed properly. This script will need editing. Patches and/or updates are welcome!</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Mikrotikwirelessregistration_.png"><img loading="lazy" alt="Mikrotikwirelessregistration .png" src="http://wiki.mikrotik.com/images/c/ca/Mikrotikwirelessregistration_.png" width="495" height="408" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/perl
###############################################################################
use diagnostics;
use Net::Telnet::Cisco;
use strict;
use warnings;
##############################################################################
my @Output = undef;
my $TelnetPort = "23";
my $TelnetUser = "username";
my $TelnetPass = "password";

###############################################################################
## Determine Hostname
my $Host = undef;
$0 =~ /mikrotikwirelessregistration_(.+)*$/;
unless ($Host = $1) {
  exit 2;
}

###############################################################################
## Initiate Telnet Session
my $MT = Net::Telnet::Cisco-&gt;new(Host    =&gt; $Host,
                                 Port    =&gt; $TelnetPort,
                                 Prompt  =&gt; '/[\&gt;\#] $/',
                                 Timeout =&gt; 30);
if (!defined($MT-&gt;login($TelnetUser . "+ct", $TelnetPass))) {
  die "Croaking: $MT-&gt;error";
}

###############################################################################
## Configuration
if ($ARGV[0] &amp;&amp; $ARGV[0] eq "config") {
  print "host_name " . $Host . "\n";
  print "graph_args -l 0 --lower-limit -100 --upper-limit 0\n";
  print "graph_title Wireless Interface Registrations (Signal Strength)\n";
  print "graph_vlabel dBm Signal\n";
  print "graph_category network\n";
  print "graph_info This graph shows the wireless registration signal strength\n";
  print "graph_scale no\n";
  @Output = $MT-&gt;cmd("/interface wireless registration-table print without-paging");
  foreach my $Line (@Output) {
    my ($tmp, $number, $interface, $radio, $mac, $ap, $signal, $txrate, $uptime) = split(/\s+/, $Line, 9);
    if ($interface &amp;&amp; $interface ne "INTERFACE") {
      print $interface . ".label " . $interface . "\n";
    }
  }
  exit;
}

###############################################################################
## Execution
@Output = $MT-&gt;cmd("/interface wireless registration-table print without-paging");
foreach my $Line (@Output) {
  my ($tmp, $number, $interface, $radio, $mac, $ap, $signal, $txrate, $uptime) = split(/\s+/, $Line, 9);
  if ($interface &amp;&amp; $interface ne "INTERFACE") {
    if ($signal =~ m/(.\d+)/) {
      print $interface . ".value " . $1 . "\n";
    }
  }
}
exit;</pre>
<p>&#8212;<a title="User:Savage (page does not exist)" href="http://wiki.mikrotik.com/index.php?title=User:Savage&amp;action=edit&amp;redlink=1">Savage</a> 14:02, 14 January 2009 (EET)</p>
<h2>mikrotikdhcpleases_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Advanced</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>API (PHP)</td>
</tr>
<tr>
<td>Notes:</td>
<td>Produces a graph which shows the number of active leases for each DHCP server. Assumes that the DHCP servers are sensibly named! &#8220;server 1&#8221; and &#8220;server1&#8221; are treated as the same server!</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Dhcpleases.png"><img loading="lazy" alt="Dhcpleases.png" src="http://wiki.mikrotik.com/images/e/e6/Dhcpleases.png" width="501" height="307" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/php
&lt;?php

// Change the following path as appropriate
require('/var/www/html/ros/routeros_api.class.php');

$API = new routeros_api();

// debug
$API-&gt;debug = false;

// Work out which hostname we're connecting to.
$hostname = explode("_",$argv[0],2);

if (isset($hostname[1])) {
  $hostname = $hostname[1];
} else {
  die("No hostname available");
}

// First things first, get the information we want to look at
// change username/password as appropriate
if ($API-&gt;connect($hostname, 'munin', 'munin')) {

   $API-&gt;write('/ip/dhcp-server/getall');
   $dhcp_servers = $API-&gt;read();

// Not very optimal - we get the leases even if we don't need them, but it'll do for the moment.
   $API-&gt;write('/ip/dhcp-server/lease/getall');
   $dhcp_leases = $API-&gt;read();

   $API-&gt;disconnect();

   $connect = 'yes';
} else {
   $connect = 'no (could not connect)';
}

if ($argc &gt; 1 &amp;&amp; $argv[1] == 'autoconf') {
  print $connect . "\n";
  exit;
}

//Output configuration information
if ($argc &gt; 1 &amp;&amp; $argv[1] == 'config') {
  print "host_name $hostname\n";
  print "graph_args --base 1000 -l 0 -r --lower-limit 0\n";
  print "graph_title DHCP leases\n";
  print "graph_vlabel number\n";
  print "graph_category network\n";
  print "graph_info This graph shows the number of active leases for each DHCP server\n";
  print "graph_scale no\n";
  if (!empty($dhcp_servers)) {
    foreach ($dhcp_servers as $value) {
      $nicename=ereg_replace("[^A-Za-z0-9]", "",$value["name"]);
      print $nicename . ".label " . $value["name"] . "\n";
    }
  }
  exit;
}

// Exit if we don't have any servers to report on.
if (empty($dhcp_servers)) {
  exit;
}

// Set count for each server to zero.
foreach ($dhcp_servers as $value) {
  $dhcp_server_leases[$value["name"]]=0 ;
}

// Then calculate the count for each server.
if (!empty($dhcp_leases)) {
  foreach ($dhcp_leases as $value) {
    if (array_key_exists("active-server",$value)) {
      $dhcp_server_leases[$value["active-server"]]+=1;
    }
  }
}

// Finally, print it all out.
foreach ($dhcp_server_leases as $key =&gt; $value) {
  print ereg_replace("[^A-Za-z0-9]", "",$key) . ".value " . $value . "\n";
}

exit;

?&gt;</pre>
<h2>mikrotikfirewallrules_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Advanced</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>API (PHP)</td>
</tr>
<tr>
<td>Notes:</td>
<td>Produces a graph which shows the number of active firewall rules for each chain.</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Firewallrules.png"><img loading="lazy" alt="Firewallrules.png" src="http://wiki.mikrotik.com/images/c/c0/Firewallrules.png" width="501" height="319" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/php
&lt;?php

require('/var/www/html/ros/routeros_api.class.php');

$API = new routeros_api();

// debug
$API-&gt;debug = false;

// Work out which hostname we're connecting to.
$hostname = explode("_",$argv[0],2);

if (isset($hostname[1])) {
  $hostname = $hostname[1];
} else {
  die("No hostname available");
}

// First things first, get the information we want to look at
if ($API-&gt;connect($hostname, 'munin', 'munin')) {

   $API-&gt;write('/ip/firewall/filter/getall');
   $firewall_rules = $API-&gt;read();

   $API-&gt;disconnect();

   $rulecount=array();

   foreach ($firewall_rules as $value) {

// Some versions of ROS use disabled=true, others use invalid=true
     if ((array_key_exists("disabled",$value) &amp;&amp; $value["disabled"] == 'false') ||
     (array_key_exists("invalid",$value) &amp;&amp; $value["invalid"] == 'false')) {
       if (array_key_exists($value["chain"],$rulecount)) {
         $rulecount[$value["chain"]] += 1;
       } else {
         $rulecount[$value["chain"]] = 1;
       }
     }
   }

   $connect = 'yes';
} else {
   $connect = 'no (could not connect)';
}

if ($argc &gt; 1 &amp;&amp; $argv[1] == 'autoconf') {
  print $connect . "\n";
  exit;
}

if ($argc &gt; 1 &amp;&amp; $argv[1] == 'config') {
  print "host_name $hostname\n";
  print "graph_args --base 1000 -l 0 -r --lower-limit 0\n";
  print "graph_title Firewall rules\n";
  print "graph_vlabel number\n";
  print "graph_category network\n";
  print "graph_info This graph shows the number of active firewall rules in each chain\n";
  print "graph_scale no\n";

  if (!empty($rulecount)) {
    foreach ($rulecount as $key =&gt; $value) {
      print $key . ".label " . $key . "\n";
    }
  }
  exit;
}

if (empty($rulecount)) {
  exit;
}

foreach ($rulecount as $key =&gt; $value) {
  print $key . ".value " . $value . "\n";
}

exit;

?&gt;</pre>
<h2>mikrotikfirewallcount_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Advanced</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>API (PHP)</td>
</tr>
<tr>
<td>Notes:</td>
<td>Produces a graph which shows the number of packets for specified firewall rules. Packets matching a firewall rule are graphed when the comments field for the rule starts &#8220;GRAPH &#8211; &#8220;. The end of the line is used to label the points (e.g. &#8220;GRAPH &#8211; Dropped packets&#8221;, &#8220;Dropped packets is the label&#8221;). Note that this does not work on ROS 3.25 as for some bizarre reason, rule comments are no longer accessible from the API.</td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Firewallcount.png"><img loading="lazy" alt="Firewallcount.png" src="http://wiki.mikrotik.com/images/5/53/Firewallcount.png" width="501" height="295" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/php
&lt;?php

require('/var/www/html/ros/routeros_api.class.php');

$API = new routeros_api();

// debug
$API-&gt;debug = false;

// Work out which hostname we're connecting to.
$hostname = explode("_",$argv[0],2);

if (isset($hostname[1])) {
  $hostname = $hostname[1];
} else {
  die("No hostname available");
}

// First things first, get the information we want to look at
if ($API-&gt;connect($hostname, 'munin', 'munin')) {

   $API-&gt;write('/ip/firewall/filter/getall');
   $firewall_rules = $API-&gt;read();

   $API-&gt;disconnect();

   $graphme=array();

   foreach ($firewall_rules as $value) {
     if (array_key_exists("comment",$value)) {
       $comment = explode(" - ",$value["comment"]);
       if ($comment[0] == "GRAPH" &amp;&amp; isset($comment[1])) {
         $id=ereg_replace("[^A-Za-z0-9]", "",$value[".id"]);
         $graphme[$id]["name"]=$comment[1];
         $graphme[$id]["packets"]=$value["packets"];
       }
     }
   }

   $connect = 'yes';
} else {
   $connect = 'no (could not connect)';
}

if ($argc &gt; 1 &amp;&amp; $argv[1] == 'autoconf') {
  print $connect . "\n";
  exit;
}

if ($argc &gt; 1 &amp;&amp; $argv[1] == 'config') {
  print "host_name $hostname\n";
  print "graph_args --base 1000 -l 0 -r --lower-limit 0\n";
  print "graph_title Logged packets \n";
  print "graph_vlabel number\n";
  print "graph_category firewall\n";
  print "graph_info This graph shows the number of packets for logged firewall rules\n";
  print "graph_scale no\n";

  if (!empty($graphme)) {
    foreach ($graphme as $key =&gt; $value) {
      $id=ereg_replace("[^A-Za-z0-9]", "",$key);
      print $id . ".label " . $value["name"] . "\n";
      print $id . ".type COUNTER\n";
    }
  }
  exit;
}

// If there's nothing to graph, don't bother.
if (empty($graphme)) {
  exit;
}

foreach ($graphme as $key =&gt; $value) {
  print $key . ".value " . $value["packets"] . "\n";
}

exit;

?&gt;</pre>
<h2>mikrotikifrate_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Advanced</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>API (PHP)</td>
</tr>
<tr>
<td>Notes:</td>
<td>This graph shows the incoming and outgoing transfer rate of a specified interface. Uses PHP API.Tested on v3.30, v4.6, v5.0beta2.</td>
</tr>
<tr>
<td>Usage:</td>
<td>As above, except you also need to specify the name of the monitored interface in the filename.</td>
</tr>
<tr>
<td>Filename syntax:</td>
<td><b>mikrotikifrate_hostname_interfacename</b></td>
</tr>
<tr>
<td>Filename example:</td>
<td><i>mikrotikifrate_example.changeip.net_ether1</i></td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Ifrate.png"><img loading="lazy" alt="Ifrate.png" src="http://wiki.mikrotik.com/images/5/56/Ifrate.png" width="503" height="292" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/php
&lt;?php

// Change the following path as appropriate
require('/var/www/html/ros/routeros_api.class.php');

$API = new routeros_api();

// debug
$API-&gt;debug = false;

// Work out hostname and interface name
$param = explode("_",$argv[0],3);

if (isset($param[1])) {
  $hostname = $param[1];
} else {
  die("No hostname available. Filename should be like: mikrotikifrate_example.changeip.net_ether1");
}

if (isset($param[2])) {
  $ifname = $param[2];
} else {
  die("No interface name available. Filename should be like: mikrotikifrate_example.changeip.net_ether1");
}

// change username/password as appropriate
if ($API-&gt;connect($hostname, 'munin', 'munin')) {

   $API-&gt;write('/interface/print',false);
   $API-&gt;write('=stats=');

   $READ = $API-&gt;read(false);
   $interfaces = $API-&gt;parse_response($READ);

   $API-&gt;disconnect();

   $connect = 'yes';
} else {
   $connect = 'no (could not connect)';
}

if ($argc &gt; 1 &amp;&amp; $argv[1] == 'autoconf') {
  print $connect . "\n";
  exit;
}

// Output configuration information
if ($argc &gt; 1 &amp;&amp; $argv[1] == 'config') {
  print "host_name $hostname\n";
  print "graph_args --base 1000\n";
  print "graph_title $ifname traffic\n";
  print "graph_vlabel bits per second\n";
  print "graph_category network\n";
  print "graph_info This graph shows the incoming and outgoing traffic rate of an interface\n";
  print "in.label received\n";
  print "in.type DERIVE\n";
  print "in.draw AREA\n";
  print "in.min 0\n";
  print "in.cdef in,8,*\n";
  print "out.label sent\n";
  print "out.type DERIVE\n";
  print "out.draw LINE1\n";
  print "out.min 0\n";
  print "out.cdef out,8,*\n";

  exit;
}

// Exit if we don't have any servers to report on.
if (empty($interfaces)) {
  exit;
}

// Finally, print it all out.
    foreach ($interfaces as $interface)
    {
	if ($interface['name']==$ifname)
	{
	    //print_r($interface);
	    $bytes = explode("/", $interface['bytes']);
	    print ("in.value ") . $bytes[0] . "\n";
	    print ("out.value ") . $bytes[1] . "\n";
	}
    }

exit;

?&gt;</pre>
<p>&nbsp;</p>
<h2>mikrotikwirelessconnected_</h2>
<table>
<tbody>
<tr>
<td>Installation:</td>
<td>Easy to Intermediate</td>
</tr>
<tr>
<td>Technology Used:</td>
<td>Telnet (RO Access, Single Login)</td>
</tr>
<tr>
<td>Notes:</td>
<td>This chart shows the number of clients connected to each wireless interface.Tested on v3.30, v4.9.</td>
</tr>
<tr>
<td>Usage:</td>
<td>As above, except you also need to specify more than 9 interfaces.</td>
</tr>
<tr>
<td>Filename syntax:</td>
<td><b>mikrotikwirelessconnected_hostname</b></td>
</tr>
<tr>
<td>Filename example:</td>
<td><i>mikrotikwirelessconnected_ap1.domain.ext</i></td>
</tr>
<tr>
<td>Sample Graph:</td>
<td><a href="http://wiki.mikrotik.com/wiki/File:Graph-mkwireless_host-day.png"><img loading="lazy" alt="Graph-mkwireless host-day.png" src="http://wiki.mikrotik.com/images/9/92/Graph-mkwireless_host-day.png" width="495" height="307" /></a></td>
</tr>
</tbody>
</table>
<p>Script:</p>
<pre>#!/usr/bin/perl
###############################################################################
use diagnostics;
use Net::Telnet::Cisco;
use strict;
use warnings;
##############################################################################
my $TelnetPort = "23";
my $TelnetUser = "munin";
my $TelnetPass = "password";

###############################################################################
## Determine Hostname
my $Host = undef;
$0 =~ /mikrotikwirelessconnected_(.+)*$/;
unless ($Host = $1) {
  exit 2;
}

###############################################################################
## Initiate Telnet Session
my $MT = Net::Telnet::Cisco-&gt;new(Host    =&gt; $Host,
                                 Port    =&gt; $TelnetPort,
                                 Prompt  =&gt; '/[\&gt;\#] $/',
                                 Timeout =&gt; 30);

###############################################################################
## Configuration
if ($ARGV[0] &amp;&amp; $ARGV[0] eq "config") {
  print "host_name " . $Host . "\n";
  print "graph_args -l 0 --lower-limit 0 --upper-limit 40\n";
  print "graph_title Wireless clients in " . $Host . " \n";
  print "graph_vlabel Number of clients\n";
  print "graph_category network\n";
  print "graph_info This graph shows the number of clients connected at the interfaces Wireless\n";
  # Pega num interfaces para grafico
  if (!defined($MT-&gt;login($TelnetUser . "+ct", $TelnetPass))) {
    die "Croaking: $MT-&gt;error";
    } else {
      # Pega o numero de interfaces na AP
	  # Gets the number of interfaces in AP
      my @interfaces = $MT-&gt;cmd("/interface wireless print count-only\nD\n");
      my ($count,$int,$cli_online,$inter_number) = undef;

      $count = 0;
      foreach my $Line (@interfaces) {
        if ( $Line =~ m/([0-9]\n)/ &amp;&amp; $count&lt;1 ){
          $int = $1;
          $count = $count+1;
        }
      }

      print "graph_order";
      $inter_number = 1;
      for ($count=1;$count&lt;=$int;$count++){
          print " cl_on_wlan" . $inter_number ."";
          $inter_number = $count +1;
      }
      print "\n";

      for ($count=1;$count&lt;=$int;$count++){
        $inter_number = $count ;
        print "cl_on_wlan" . $inter_number . ".warning 25\n";
        print "cl_on_wlan" . $inter_number . ".critical 30\n";
        print "cl_on_wlan" . $inter_number . ".label WLAN". $inter_number . "\n";
        print "cl_on_wlan" . $inter_number . ".info WIRELESS LAN " . $inter_number . "\n";
      }

    }
  exit;
}

###############################################################################
## Execution
if (!defined($MT-&gt;login($TelnetUser . "+ct", $TelnetPass))) {
  die "Croaking: $MT-&gt;error";
  } else {

  # Pega o numero de interfaces na AP
  # Gets the number of interfaces in AP
  my @interfaces = $MT-&gt;cmd("/interface wireless print count-only\nD\n");
  my ($count,$int) = undef;

  $count = 0;
  foreach my $Line (@interfaces) {
  if ( $Line =~ m/([0-9]\n)/ &amp;&amp; $count&lt;1 ){
        $int = $1;
        $count = $count+1;
    }
  }

# Pega o número de clientes para cada interface
# Gets the number of customers for each interface
for ($count = 0; $count &lt; $int; $count++) {
  my @Output = $MT-&gt;cmd("/interface wireless monitor " . $count . " once\nD\n");
  my ($rest, $tmp, $cli_online, $inter_number, $cl_on_wlan14) = undef;
  foreach my $Line (@Output) {
  # Pega clientes registrados
    if ($Line =~ /registered-clients/ &amp;&amp; $Line =~ m/(\d+)/) {
        $cli_online = $1;
        $inter_number = $count+1;
        print "cl_on_wlan" . $inter_number . ".value " . $1 . "\n";
    }
  }
  print "cl_on_wlan" . $inter_number . ".value " . $cli_online . "\n";
  }
  exit;
}
</pre>
<p>REFERENCE : MikroTik wiki </p>
<div class="wp-about-author-containter-top" style="background-color:#FFEAA8;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=100&#038;d=mm&#038;r=g' srcset='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=200&#038;d=mm&#038;r=g 2x' class='author_gravatar left  avatar-100 photo' height='100' width='100' loading='lazy'/></div><div class="wp-about-author-text" style="margin-left:140px"><h3><a href='/author/vaheed/' title='vaheeD'>vaheeD</a></h3><p></p><p><a href='/author/vaheed/' title='More posts by vaheeD'>More Posts</a>  - <a href='https://plus.google.com/103839803047317952696' title='vaheeD'>Website</a> </p><p class="wpa-nomargin">Follow Me:<br /><a class='wpa-social-icons' href='http://www.facebook.com/vaheet'><img src='/wp-content/plugins/wp-about-author/images/facebook.png' alt='Facebook'/></a><a class='wpa-social-icons' href='https://plus.google.com/103839803047317952696'><img src='/wp-content/plugins/wp-about-author/images/googleplus.png' alt='Google Plus'/></a></p></div></div>The post <a href="/mikrotik-monitoring-with-munin/">MikroTik Monitoring With Munin</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></content:encoded>
					
					<wfw:commentRss>/mikrotik-monitoring-with-munin/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Force Disconnect Wireless Stations with Low CCQ in MikroTik</title>
		<link>/force-disconnect-wireless-stations-with-low-ccq-in-mikrotik/</link>
					<comments>/force-disconnect-wireless-stations-with-low-ccq-in-mikrotik/#respond</comments>
		
		<dc:creator><![CDATA[vaheeD]]></dc:creator>
		<pubDate>Sat, 19 Jan 2013 20:02:36 +0000</pubDate>
				<category><![CDATA[MikroTik]]></category>
		<guid isPermaLink="false">/?p=580</guid>

					<description><![CDATA[<p>This script checks all registered stations and forces a disconnect for any station(s) which has a CCQ level less than that specified below (in this example it&#8217;s set to 70% for TX and for RX). The idea is that once they are forced to disconnect, the stations will attempt to reassociate with the best available... </p>
<p><a class="small button secondary" href="/force-disconnect-wireless-stations-with-low-ccq-in-mikrotik/">Continue Reading</a></p>
The post <a href="/force-disconnect-wireless-stations-with-low-ccq-in-mikrotik/">Force Disconnect Wireless Stations with Low CCQ in MikroTik</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></description>
										<content:encoded><![CDATA[<p><span id="more-580"></span></p>
<p>This script checks all registered stations and forces a disconnect for any station(s) which has a CCQ level less than that specified below (in this example it&#8217;s set to 70% for TX and for RX).</p>
<p>The idea is that once they are forced to disconnect, the stations will attempt to reassociate with the best available AP, eliminating the &#8216;sticky node&#8217; problem.</p>
<p>The only modifications you need to make is to change your minimum allowed CCQ level.</p>
<p>On your APs:</p>
<pre>/system script 
add name="station-check" source="/interface \
   wireless registration-table\r\n:foreach i in=[ /interface wireless registration-table find ap=no] \
   do={\r\n   :if ([get \$i tx-ccq] &lt; \"70\" &amp;&amp; [get \$i rx-ccq] &lt; \"70\") do={\r\n           :log warning \
   ([get \$i radio-name] . \" was disconnected due to low CCQ - Tx: \" . [get \$i tx-ccq] . \"% / Rx: \" . \
   [get \$i rx-ccq] . \"%\")\r\n           /interface wireless registration-table remove \$i\r\n           \
   :delay 5s\r\n           }\r\n}"</pre>
<p><b>Important: Remember that non-MikroTik stations will not report back their received CCQ, so the TX-CCQ will always be 0%.</b><br />
Once you have configured the script, set up a scheduler to run the script everytime you want it to check for low signals. In the example below, the script will run every day at 1 second after midnight!</p>
<p>On your APs:</p>
<pre>/system scheduler 
add disabled=no interval=1d name="station-check-schedule" on-event="/system script run \
   station-check ;" start-time=00:00:01</pre>
<p>Done!</p>
<div class="wp-about-author-containter-top" style="background-color:#FFEAA8;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=100&#038;d=mm&#038;r=g' srcset='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=200&#038;d=mm&#038;r=g 2x' class='author_gravatar left  avatar-100 photo' height='100' width='100' loading='lazy'/></div><div class="wp-about-author-text" style="margin-left:140px"><h3><a href='/author/vaheed/' title='vaheeD'>vaheeD</a></h3><p></p><p><a href='/author/vaheed/' title='More posts by vaheeD'>More Posts</a>  - <a href='https://plus.google.com/103839803047317952696' title='vaheeD'>Website</a> </p><p class="wpa-nomargin">Follow Me:<br /><a class='wpa-social-icons' href='http://www.facebook.com/vaheet'><img src='/wp-content/plugins/wp-about-author/images/facebook.png' alt='Facebook'/></a><a class='wpa-social-icons' href='https://plus.google.com/103839803047317952696'><img src='/wp-content/plugins/wp-about-author/images/googleplus.png' alt='Google Plus'/></a></p></div></div>The post <a href="/force-disconnect-wireless-stations-with-low-ccq-in-mikrotik/">Force Disconnect Wireless Stations with Low CCQ in MikroTik</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></content:encoded>
					
					<wfw:commentRss>/force-disconnect-wireless-stations-with-low-ccq-in-mikrotik/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MikroTik RouterOS Port Knocking</title>
		<link>/mikrotik-routeros-port-knocking/</link>
					<comments>/mikrotik-routeros-port-knocking/#respond</comments>
		
		<dc:creator><![CDATA[vaheeD]]></dc:creator>
		<pubDate>Sat, 19 Jan 2013 18:52:49 +0000</pubDate>
				<category><![CDATA[MikroTik]]></category>
		<guid isPermaLink="false">/?p=573</guid>

					<description><![CDATA[<p>Port knocking is a method of establishing a connection to a networked device that has no open ports. Before a connection is established, ports are opened using a port knock sequence, which is a series of connection attempts to closed ports. A remote host generates and sends an authentic knock sequence in order to manipulate... </p>
<p><a class="small button secondary" href="/mikrotik-routeros-port-knocking/">Continue Reading</a></p>
The post <a href="/mikrotik-routeros-port-knocking/">MikroTik RouterOS Port Knocking</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></description>
										<content:encoded><![CDATA[<p><span id="more-573"></span></p>
<p>Port knocking is a method of establishing a connection to a networked device that has no open ports.</p>
<p>Before a connection is established, ports are opened using a port knock sequence, which is a series of connection attempts to closed ports.</p>
<p>A remote host generates and sends an authentic knock sequence in order to manipulate device firewall rules to open one or more specific ports.</p>
<p>Once the desired ports are opened, the remote host can establish a connection and begin a session (in this example, SSH will be available after issuing the correct Knocking Sequence to a RouterOS Based Router).</p>
<p>Optionally, another knock sequence may used to trigger the closing of the previously enabled port.</p>
<pre>
/ip firewall filter
 
add action=log chain=input log-prefix="KNOCK STAGE 01" disabled=no\
    protocol=tcp dst-port=1010
add action=add-src-to-address-list address-list="KNOCK STAGE 01"\
    address-list-timeout=15s chain=input disabled=no\
    dst-port=1010 protocol=tcp
 
add action=log chain=input log-prefix="KNOCK STAGE 02" disabled=no\
    protocol=tcp dst-port=2020 src-address-list="KNOCK STAGE 01"
add action=add-src-to-address-list address-list="KNOCK STAGE 02"\
    address-list-timeout=15s chain=input disabled=no\
    dst-port=2020 protocol=tcp
 
add action=log chain=input log-prefix="KNOCK STAGE 03" disabled=no\
    protocol=tcp dst-port=3030 src-address-list="KNOCK STAGE 02"
add action=add-src-to-address-list address-list="KNOCK STAGE 03"\
    address-list-timeout=15s chain=input disabled=no\
    dst-port=3030 protocol=tcp
 
add action=accept chain=input disabled=no\
    dst-port=22 protocol=tcp src-address-list="KNOCK STAGE 03"
<br>
</pre>
<p>In this example Address-Lists are created with a validity of 15s, so the knocking sequence needs to be issued quite fast.</p>
<p>Better security will be granted using a sequence with decreasing port number and different protocols (to avoid basic Port Scans).<br />
Example: 30001/TCP -> 2001/UDP -> 101/TCP => Open 22/TCP.<br />
&nbsp;</p>
<div class="wp-about-author-containter-top" style="background-color:#FFEAA8;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=100&#038;d=mm&#038;r=g' srcset='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=200&#038;d=mm&#038;r=g 2x' class='author_gravatar left  avatar-100 photo' height='100' width='100' loading='lazy'/></div><div class="wp-about-author-text" style="margin-left:140px"><h3><a href='/author/vaheed/' title='vaheeD'>vaheeD</a></h3><p></p><p><a href='/author/vaheed/' title='More posts by vaheeD'>More Posts</a>  - <a href='https://plus.google.com/103839803047317952696' title='vaheeD'>Website</a> </p><p class="wpa-nomargin">Follow Me:<br /><a class='wpa-social-icons' href='http://www.facebook.com/vaheet'><img src='/wp-content/plugins/wp-about-author/images/facebook.png' alt='Facebook'/></a><a class='wpa-social-icons' href='https://plus.google.com/103839803047317952696'><img src='/wp-content/plugins/wp-about-author/images/googleplus.png' alt='Google Plus'/></a></p></div></div>The post <a href="/mikrotik-routeros-port-knocking/">MikroTik RouterOS Port Knocking</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></content:encoded>
					
					<wfw:commentRss>/mikrotik-routeros-port-knocking/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MikroTik RouterOS &#8220;Safe Mode&#8221;</title>
		<link>/mikrotik-routeros-safe-mode/</link>
					<comments>/mikrotik-routeros-safe-mode/#respond</comments>
		
		<dc:creator><![CDATA[vaheeD]]></dc:creator>
		<pubDate>Sat, 19 Jan 2013 18:40:48 +0000</pubDate>
				<category><![CDATA[MikroTik]]></category>
		<guid isPermaLink="false">/?p=562</guid>

					<description><![CDATA[<p>Safe Mode It is sometimes possible to change router configuration in a way that will make the router inaccessible (except from local console). Usually this is done by accident, but there is no way to undo last change when connection to router is already cut. Safe mode can be used to minimize such risk. Safe... </p>
<p><a class="small button secondary" href="/mikrotik-routeros-safe-mode/">Continue Reading</a></p>
The post <a href="/mikrotik-routeros-safe-mode/">MikroTik RouterOS “Safe Mode”</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></description>
										<content:encoded><![CDATA[<p><span id="more-562"></span></p>
<h3>Safe Mode</h3>
<p>It is sometimes possible to change router configuration in a way that will make the router inaccessible (except from local console). Usually this is done by accident, but there is no way to undo last change when connection to router is already cut. Safe mode can be used to minimize such risk.</p>
<p>Safe mode is entered by pressing <b>[CTRL]+[X]</b>. To save changes and quit safe mode, press <b>[CTRL]+[X]</b> again. To exit without saving the made changes, hit <b>[CTRL]+[D]</b></p>
<pre>[admin@MikroTik] ip route&gt;[CTRL]+[X]
[Safe Mode taken]

[admin@MikroTik] ip route&lt;SAFE&gt;</pre>
<p>&nbsp;</p>
<p>Message <b>Safe Mode taken</b> is displayed and prompt changes to reflect that session is now in safe mode. All configuration changes that are made (also from other login sessions), while router is in safe mode, are automatically undone if safe mode session terminates abnormally. You can see all such changes that will be automatically undone tagged with an <b>F</b> flag in system history:</p>
<pre>[admin@MikroTik] ip route&gt;
[Safe Mode taken]

[admin@MikroTik] ip route&lt;SAFE&gt; add
[admin@MikroTik] ip route&lt;SAFE&gt; /system history print
Flags: U - undoable, R - redoable, F - floating-undo
  ACTION                                   BY                 POLICY
F route added                              admin              write</pre>
<p>Now, if telnet connection (or winbox terminal) is cut, then after a while (TCP timeout is <b>9</b> minutes) all changes that were made while in safe mode will be undone. Exiting session by <b>[Ctrl]+[D]</b> also undoes all safe mode changes, while <b>/quit</b> does not.</p>
<p>If another user tries to enter safe mode, he&#8217;s given following message:</p>
<pre>[admin@MikroTik] &gt;
Hijacking Safe Mode from someone - unroll/release/don't take it [u/r/d]:</pre>
<ul>
<li>[u] &#8211; undoes all safe mode changes, and puts the current session in safe mode.</li>
<li>[r] &#8211; keeps all current safe mode changes, and puts current session in a safe mode. Previous owner of safe mode is notified about this:</li>
</ul>
<pre> 
     [admin@MikroTik] ip firewall rule input
     [Safe mode released by another user]</pre>
<ul>
<li>[d] &#8211; leaves everything as-is.</li>
</ul>
<p>If too many changes are made while in safe mode, and there&#8217;s no room in history to hold them all (currently history keeps up to 100 most recent actions), then session is automatically put out of the safe mode, no changes are automatically undone. Thus, it is best to change configuration in small steps, while in safe mode. Pressing [Ctrl]+[X] twice is an easy way to empty safe mode action list.</p>
<p>&nbsp;</p>
<h3>HotLock Mode</h3>
<p>When HotLock mode is enabled commands will be auto completed.</p>
<p>To enter/exit HotLock mode press <b>[CTRL]+[V]</b>.</p>
<pre>[admin@MikroTik] /ip address&gt; [CTRL]+[V]
[admin@MikroTik] /ip address&gt;&gt;</pre>
<p>Double <code>&gt;&gt;</code> is indication that HotLock mode is enabled. For example if you type <code>/in e</code>, it will be auto completed to</p>
<pre>[admin@MikroTik] /ip address&gt;&gt; /interface ethernet</pre>
<p>&nbsp;</p>
<div class="wp-about-author-containter-top" style="background-color:#FFEAA8;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=100&#038;d=mm&#038;r=g' srcset='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=200&#038;d=mm&#038;r=g 2x' class='author_gravatar left  avatar-100 photo' height='100' width='100' loading='lazy'/></div><div class="wp-about-author-text" style="margin-left:140px"><h3><a href='/author/vaheed/' title='vaheeD'>vaheeD</a></h3><p></p><p><a href='/author/vaheed/' title='More posts by vaheeD'>More Posts</a>  - <a href='https://plus.google.com/103839803047317952696' title='vaheeD'>Website</a> </p><p class="wpa-nomargin">Follow Me:<br /><a class='wpa-social-icons' href='http://www.facebook.com/vaheet'><img src='/wp-content/plugins/wp-about-author/images/facebook.png' alt='Facebook'/></a><a class='wpa-social-icons' href='https://plus.google.com/103839803047317952696'><img src='/wp-content/plugins/wp-about-author/images/googleplus.png' alt='Google Plus'/></a></p></div></div>The post <a href="/mikrotik-routeros-safe-mode/">MikroTik RouterOS “Safe Mode”</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></content:encoded>
					
					<wfw:commentRss>/mikrotik-routeros-safe-mode/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>NTH load balancing with masquerade</title>
		<link>/nth-load-balancing-with-masquerade/</link>
					<comments>/nth-load-balancing-with-masquerade/#respond</comments>
		
		<dc:creator><![CDATA[vaheeD]]></dc:creator>
		<pubDate>Sat, 12 Jan 2013 07:39:51 +0000</pubDate>
				<category><![CDATA[MikroTik]]></category>
		<guid isPermaLink="false">/?p=496</guid>

					<description><![CDATA[<p>NTH ? example: nth=Every,Counter,Packet nth=2,3,0. 2,3,1 2,3,2 divide all packets into groups of three (2+1). The packets will be numbered from 0 to 2. So, a sequence of packets the rule matches looks like: (0 1 2)(0 1 2)(0 1 2)(0 1 2)(0 1 2)&#8230; the first rule will match the first packet in each... </p>
<p><a class="small button secondary" href="/nth-load-balancing-with-masquerade/">Continue Reading</a></p>
The post <a href="/nth-load-balancing-with-masquerade/">NTH load balancing with masquerade</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></description>
										<content:encoded><![CDATA[<p><span id="more-496"></span></p>
<h2>NTH ?</h2>
<p>example: nth=Every,Counter,Packet nth=2,3,0. 2,3,1 2,3,2</p>
<p>divide all packets into groups of three (2+1). The packets will be numbered from 0 to 2. So, a sequence of packets the rule matches looks like: (0 1 2)(0 1 2)(0 1 2)(0 1 2)(0 1 2)&#8230;</p>
<p>the first rule will match the first packet in each group (&#8220;Packet&#8221;=0). The second rule will match the second packet in each group (&#8220;Packet&#8221;=1) and so on. Each successful match increments the counter. When a value of &#8220;Every&#8221; is reached, the counter is reset to 0. For this to work, the &#8220;Counter&#8221; should be the same for all rules (you can pick any value from 0 to 15, IIRC).</p>
<h2>Introduction</h2>
<p>This example is improved (different) version of round-robin load balancing example. It adds persistent user sessions, i.e. a particular user would use the same source IP address for all outgoing connections.</p>
<h2>Quick Start for Impatient</h2>
<p>Configuration export from the gateway router:</p>
<pre>/ ip address
add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=Local 
add address=10.111.0.2/24 network=10.111.0.0 broadcast=10.111.0.255 interface=wlan2
add address=10.112.0.2/24 network=10.112.0.0 broadcast=10.112.0.255 interface=wlan1

/ ip firewall mangle
add chain=prerouting src-address-list=odd in-interface=Local action=mark-connection \
  new-connection-mark=odd passthrough=yes 
add chain=prerouting src-address-list=odd in-interface=Local action=mark-routing \
  new-routing-mark=odd passthrough=no
add chain=prerouting src-address-list=even in-interface=Local action=mark-connection \
  new-connection-mark=even passthrough=yes 
add chain=prerouting src-address-list=even in-interface=Local action=mark-routing \
  new-routing-mark=even passthrough=no
add chain=prerouting in-interface=Local connection-state=new nth=2,1 \ 
    action=mark-connection new-connection-mark=odd passthrough=yes
add chain=prerouting in-interface=Local action=add-src-to-address-list \
  address-list=odd address-list-timeout=1d connection-mark=odd passthrough=yes 
add chain=prerouting in-interface=Local connection-mark=odd action=mark-routing \ 
    new-routing-mark=odd passthrough=no
add chain=prerouting in-interface=Local connection-state=new nth=2,2 \ 
    action=mark-connection new-connection-mark=even passthrough=yes
add chain=prerouting in-interface=Local action=add-src-to-address-list \
  address-list=even address-list-timeout=1d connection-mark=even passthrough=yes 
add chain=prerouting in-interface=Local connection-mark=even action=mark-routing \ 
    new-routing-mark=even passthrough=no

/ ip firewall nat 
add chain=srcnat out-interface=wlan1 action=masquerade
add chain=srcnat out-interface=wlan2 action=masquerade

/ ip route 
add dst-address=0.0.0.0/0 gateway=10.111.0.1 scope=255 target-scope=10 routing-mark=odd
add dst-address=0.0.0.0/0 gateway=10.112.0.1 scope=255 target-scope=10 routing-mark=even 
add dst-address=0.0.0.0/0 gateway=10.112.0.1 scope=255 target-scope=10</pre>
<h2>Explanation</h2>
<p>First we give a code snippet and then explain what it actually does.</p>
<h3>IP Addresses</h3>
<pre>/ ip address 
add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=Local
add address=10.111.0.2/24 network=10.111.0.0 broadcast=10.111.0.255 interface=wlan2 
add address=10.112.0.2/24 network=10.112.0.0 broadcast=10.112.0.255 interface=wlan1</pre>
<p>The router has two upstream (WAN) interfaces with the addresses of 10.111.0.2/24 and 10.112.0.2/24. The LAN interface has the name &#8220;Local&#8221; and IP address of 192.168.0.1/24.</p>
<h3>Mangle</h3>
<pre>/ ip firewall mangle 
add chain=prerouting src-address-list=odd in-interface=Local action=mark-connection \
  new-connection-mark=odd passthrough=yes 
add chain=prerouting src-address-list=odd in-interface=Local action=mark-routing \
  new-routing-mark=odd</pre>
<p>All traffic from customers having their IP address previously placed in the address list &#8220;odd&#8221; is instantly marked with connection and routing marks &#8220;odd&#8221;. Afterwards the traffic is excluded from processing against successive mangle rules in prerouting chain.</p>
<pre>/ ip firewall mangle 
add chain=prerouting src-address-list=even in-interface=Local action=mark-connection \
  new-connection-mark=even passthrough=yes 
add chain=prerouting src-address-list=even in-interface=Local action=mark-routing \
  new-routing-mark=even</pre>
<p>Same stuff as above, only for customers having their IP address previously placed in the address list &#8220;even&#8221;.</p>
<pre>/ ip firewall mangle 
add chain=prerouting in-interface=Local connection-state=new nth=2,1 \ 
    action=mark-connection new-connection-mark=odd passthrough=yes
add chain=prerouting in-interface=Local action=add-src-to-address-list \
  address-list=odd address-list-timeout=1d connection-mark=odd passthrough=yes 
add chain=prerouting in-interface=Local connection-mark=odd action=mark-routing \ 
    new-routing-mark=odd passthrough=no</pre>
<p>First we take every second packet that establishes new session (note connection-state=new), and mark it with connection mark &#8220;odd&#8221;. Consequently all successive packets belonging to the same session will carry the connection mark &#8220;odd&#8221;. Note that we are passing these packets to the second and third rules (passthrough=yes). Second rule adds IP address of the client to the address list to enable all successive sessions to go through the same gateway. Third rule places the routing mark &#8220;odd&#8221; on all packets that belong to the &#8220;odd&#8221; connection and stops processing all other mangle rules for these packets in prerouting chain.</p>
<pre>/ ip firewall mangle 
add chain=prerouting in-interface=Local connection-state=new nth=2,2 \ 
    action=mark-connection new-connection-mark=even passthrough=yes
add chain=prerouting in-interface=Local action=add-src-to-address-list \
  address-list=even address-list-timeout=1d connection-mark=even passthrough=yes 
add chain=prerouting in-interface=Local connection-mark=even action=mark-routing \ 
    new-routing-mark=even passthrough=no</pre>
<p>These rules do the same for the remaining half of the traffic as the first three rules for the first half of the traffic.</p>
<p>The code above effectively means that each new connection initiated through the router from the local network will be marked as either &#8220;odd&#8221; or &#8220;even&#8221; with both routing and connection marks.</p>
<p>The above works fine. There are however some situations where you might find that the same IP address is listed under both the ODD and EVEN scr-address-lists. This behavior causes issues with apps that require persistent connections. A simple remedy for this situation is to add the following statement to your mangle rules:</p>
<pre>add chain=prerouting in-interface=Local connection-state=new nth=2,2 \ 
    src-address-list=!odd action=mark-connection new-connection-mark=even \
    passthrough=yes</pre>
<p>This will ensure that the new connection will not already be part of the ODD src-address-list. You will have to do the same for the ODD mangle rule thus excluding IP&#8217;s already part of the EVEN scr-address-list.</p>
<h3>NAT</h3>
<pre>/ ip firewall nat 
add chain=srcnat out-interface=wlan1 action=masquerade
add chain=srcnat out-interface=wlan2 action=masquerade</pre>
<p>Fix the source address according to the outgoing interface.</p>
<h3>Routing</h3>
<pre>/ ip route 
add dst-address=0.0.0.0/0 gateway=10.111.0.1 scope=255 target-scope=10 routing-mark=odd 
add dst-address=0.0.0.0/0 gateway=10.112.0.1 scope=255 target-scope=10 routing-mark=even</pre>
<p>For all traffic marked &#8220;odd&#8221; (consequently having 10.111.0.2 translated source address) we use 10.111.0.1 gateway. In the same manner all traffic marked &#8220;even&#8221; is routed through the 10.112.0.1 gateway.</p>
<pre>/ ip route
add dst-address=0.0.0.0/0 gateway=10.112.0.1 scope=255 target-scope=10</pre>
<p>Finally, we have one additional entry specifying that traffic from the router itself (the traffic without any routing marks) should go to 10.112.0.1 gateway.</p>
<div class="wp-about-author-containter-top" style="background-color:#FFEAA8;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=100&#038;d=mm&#038;r=g' srcset='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=200&#038;d=mm&#038;r=g 2x' class='author_gravatar left  avatar-100 photo' height='100' width='100' loading='lazy'/></div><div class="wp-about-author-text" style="margin-left:140px"><h3><a href='/author/vaheed/' title='vaheeD'>vaheeD</a></h3><p></p><p><a href='/author/vaheed/' title='More posts by vaheeD'>More Posts</a>  - <a href='https://plus.google.com/103839803047317952696' title='vaheeD'>Website</a> </p><p class="wpa-nomargin">Follow Me:<br /><a class='wpa-social-icons' href='http://www.facebook.com/vaheet'><img src='/wp-content/plugins/wp-about-author/images/facebook.png' alt='Facebook'/></a><a class='wpa-social-icons' href='https://plus.google.com/103839803047317952696'><img src='/wp-content/plugins/wp-about-author/images/googleplus.png' alt='Google Plus'/></a></p></div></div>The post <a href="/nth-load-balancing-with-masquerade/">NTH load balancing with masquerade</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></content:encoded>
					
					<wfw:commentRss>/nth-load-balancing-with-masquerade/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ECMP load balancing with masquerade</title>
		<link>/ecmp-load-balancing-with-masquerade/</link>
					<comments>/ecmp-load-balancing-with-masquerade/#respond</comments>
		
		<dc:creator><![CDATA[vaheeD]]></dc:creator>
		<pubDate>Sat, 12 Jan 2013 07:32:53 +0000</pubDate>
				<category><![CDATA[MikroTik]]></category>
		<category><![CDATA[Network]]></category>
		<guid isPermaLink="false">/?p=493</guid>

					<description><![CDATA[<p>Introduction This example is improved (different) version of round-robin load balancing example. It adds persistent user sessions, i.e. a particular user would use the same source IP address for all outgoing connections. Quick Start for Impatient Configuration export from the gateway router: / ip address add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=Local add address=10.111.0.2/24 network=10.111.0.0 broadcast=10.111.0.255 interface=wlan2... </p>
<p><a class="small button secondary" href="/ecmp-load-balancing-with-masquerade/">Continue Reading</a></p>
The post <a href="/ecmp-load-balancing-with-masquerade/">ECMP load balancing with masquerade</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></description>
										<content:encoded><![CDATA[<p><span id="more-493"></span></p>
<h2>Introduction</h2>
<p>This example is improved (different) version of round-robin load balancing example. It adds persistent user sessions, i.e. a particular user would use the same source IP address for all outgoing connections.</p>
<h2>Quick Start for Impatient</h2>
<p>Configuration export from the gateway router:</p>
<pre>/ ip address
add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=Local 
add address=10.111.0.2/24 network=10.111.0.0 broadcast=10.111.0.255 interface=wlan2
add address=10.112.0.2/24 network=10.112.0.0 broadcast=10.112.0.255 interface=wlan1

/ ip route
add dst-address=0.0.0.0/0 gateway=10.111.0.1,10.112.0.1 check-gateway=ping 

/ ip firewall nat 
add chain=srcnat out-interface=wlan1 action=masquerade
add chain=srcnat out-interface=wlan2 action=masquerade

/ ip firewall mangle
add chain=input in-interface=wlan1 action=mark-connection new-connection-mark=wlan1_conn
add chain=input in-interface=wlan2 action=mark-connection new-connection-mark=wlan2_conn
add chain=output connection-mark=wlan1_conn action=mark-routing new-routing-mark=to_wla1     
add chain=output connection-mark=wlan1_conn action=mark-routing new-routing-mark=to_wla2     

/ ip route
add dst-address=0.0.0.0/0 gateway=10.111.0.1 routing-mark=to_wla1 
add dst-address=0.0.0.0/0 gateway=10.111.0.2 routing-mark=to_wla2</pre>
<h2>Explanation</h2>
<p>First we give a code snippet and then explain what it actually does.</p>
<h3>IP Addresses</h3>
<pre>/ ip address 
add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=Local
add address=10.111.0.2/24 network=10.111.0.0 broadcast=10.111.0.255 interface=wlan2 
add address=10.112.0.2/24 network=10.112.0.0 broadcast=10.112.0.255 interface=wlan1</pre>
<p>The router has two upstream (WAN) interfaces with the addresses of 10.111.0.2/24 and 10.112.0.2/24. The LAN interface has the name &#8220;Local&#8221; and IP address of 192.168.0.1/24.</p>
<p>&nbsp;</p>
<h3>NAT</h3>
<pre>/ ip firewall nat 
add chain=srcnat out-interface=wlan1 action=masquerade
add chain=srcnat out-interface=wlan2 action=masquerade</pre>
<p>As routing decision is already made we just need rules that will fix src-addresses for all outgoing packets. if this packet will leave via wlan1 it will be NATed to 10.112.0.2/24, if via wlan2 then NATed to 10.111.0.2/24</p>
<p>&nbsp;</p>
<h3>Routing</h3>
<pre>/ ip route 
add dst-address=0.0.0.0/0 gateway=10.111.0.1,10.112.0.1 check-gateway=ping</pre>
<p>This is typical ECMP (Equal Cost Multi-Path) gateway with check-gateway. ECMP is &#8220;persistent per-connection load balancing&#8221; or &#8220;per-src-dst-address combination load balancing&#8221;. As soon as one of the gateway will not be reachable, check-gateway will remove it from gateway list. And you will have a &#8220;failover&#8221; effect.<br />
You can use asymmetric bandwidth links also &#8211; for example one link is 2Mbps other 10Mbps. Just use this command to make load balancing 1:5</p>
<pre>/ ip route 
add dst-address=0.0.0.0/0 gateway=10.111.0.1,10.112.0.1,10.112.0.1,10.112.0.1,10.112.0.1,10.112.0.1 check-gateway=ping</pre>
<p>&nbsp;</p>
<h3>Connections to the router itself</h3>
<pre>/ ip firewall mangle
add chain=input in-interface=wlan1 action=mark-connection new-connection-mark=wlan1_conn
add chain=input in-interface=wlan2 action=mark-connection new-connection-mark=wlan2_conn
add chain=output connection-mark=wlan1_conn action=mark-routing new-routing-mark=to_wlan1     
add chain=output connection-mark=wlan1_conn action=mark-routing new-routing-mark=to_wlan2</pre>
<pre>/ ip route
add dst-address=0.0.0.0/0 gateway=10.111.0.1 routing-mark=to_wlan1 
add dst-address=0.0.0.0/0 gateway=10.111.0.2 routing-mark=to_wlan2</pre>
<p>With all multi-gateway situations there is a usual problem to reach router from public network via one, other or both gateways. Explanations is very simple &#8211; Outgoing packets uses same routing decision as packets that are going trough the router. So reply to a packet that was received via wlan1 might be send out and masqueraded via wlan2.</p>
<p>To avoid that we need to policy routing those connections.</p>
<h2>Known Issues</h2>
<h3>DNS issues</h3>
<p>ISP specific DNS servers might have custom configuration that treats specific requests from ISP&#8217;s network differently than requests from other network. So in case connection is made via other gateway those sites will not be accessible.</p>
<p>To avoid that we suggest to use 3rd-party (public) DNS servers, and in case you need ISP specific recourse, create static DNS entry and policy route that traffic to specific gateway.</p>
<h3>Routing table flushing</h3>
<p>Every time when something triggers flush of the routing table and ECMP cache is flushed. Connections will be assigned to gateways once again and may or may not be on the same gateway.(in case of 2 gateways there are 50% chance that traffic will start to flow via other gateway).<br />
If you have fully routed network (clients address can be routed via all available gateway), change of the gateway will have no ill effect, but in case you use masquerade, change of the gateway will result in change of the packet&#8217;s source address and connection will be dropped.<br />
Routing table flush can be caused by 2 things:</p>
<p>1) routing table change (dynamic routing protocol update, user manual changes)</p>
<p>2) every 10 minutes routing table is flushed for security reasons (to avoid possible DoS attacks)</p>
<p><b>So even if you do not have any changes of routing table, connections may jump to other gateway every 10 minutes</b></p>
<div class="wp-about-author-containter-top" style="background-color:#FFEAA8;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=100&#038;d=mm&#038;r=g' srcset='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=200&#038;d=mm&#038;r=g 2x' class='author_gravatar left  avatar-100 photo' height='100' width='100' loading='lazy'/></div><div class="wp-about-author-text" style="margin-left:140px"><h3><a href='/author/vaheed/' title='vaheeD'>vaheeD</a></h3><p></p><p><a href='/author/vaheed/' title='More posts by vaheeD'>More Posts</a>  - <a href='https://plus.google.com/103839803047317952696' title='vaheeD'>Website</a> </p><p class="wpa-nomargin">Follow Me:<br /><a class='wpa-social-icons' href='http://www.facebook.com/vaheet'><img src='/wp-content/plugins/wp-about-author/images/facebook.png' alt='Facebook'/></a><a class='wpa-social-icons' href='https://plus.google.com/103839803047317952696'><img src='/wp-content/plugins/wp-about-author/images/googleplus.png' alt='Google Plus'/></a></p></div></div>The post <a href="/ecmp-load-balancing-with-masquerade/">ECMP load balancing with masquerade</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></content:encoded>
					
					<wfw:commentRss>/ecmp-load-balancing-with-masquerade/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Interface Bonding 802.3ad (LACP) with Mikrotik</title>
		<link>/interface-bonding-802-3ad-lacp-with-mikrotik/</link>
					<comments>/interface-bonding-802-3ad-lacp-with-mikrotik/#respond</comments>
		
		<dc:creator><![CDATA[vaheeD]]></dc:creator>
		<pubDate>Fri, 11 Jan 2013 20:20:06 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MikroTik]]></category>
		<guid isPermaLink="false">/?p=486</guid>

					<description><![CDATA[<p>Bonding (also called port trunking or link aggregation) can be configured quite easily on RouterOS-Based devices. Having 2 NICs (ether1 and ether2) in each router (Router1 and Router2), it is possible to get maximum data rate between 2 routers, by aggregating port bandwidth. To add a bonding interface on Router1 and Router2: /interface bonding add slaves=ether1,ether2 (bonding interface needs... </p>
<p><a class="small button secondary" href="/interface-bonding-802-3ad-lacp-with-mikrotik/">Continue Reading</a></p>
The post <a href="/interface-bonding-802-3ad-lacp-with-mikrotik/">Interface Bonding 802.3ad (LACP) with Mikrotik</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></description>
										<content:encoded><![CDATA[<p><span id="more-486"></span></p>
<p>Bonding (also called port trunking or link aggregation) can be configured quite easily on RouterOS-Based devices.</p>
<p>Having 2 NICs (<em>ether1</em> and <em>ether2</em>) in each router (<em>Router1</em> and <em>Router2</em>), it is possible to get maximum data rate between 2 routers, by aggregating port bandwidth.</p>
<p>To add a bonding interface on Router1 and Router2:</p>
<div>
<pre>/interface bonding add slaves=ether1,ether2</pre>
</div>
<p>(bonding interface needs a couple of seconds to get connectivity with its peer)</p>
<p><strong>Link Monitoring:</strong><br />
Currently bonding in RouterOS supports two schemes for monitoring a link state of slave devices: MII and ARP monitoring. It is not possible to use both methods at a time due to restrictions in the bonding driver.</p>
<p><strong>ARP Monitoring:</strong><br />
ARP monitoring sends ARP queries and uses the response as an indication that the link is operational. This also gives assurance that traffic is actually flowing over the links. If balance-rr and balance-xor modes are set, then the switch should be configured to evenly distribute packets across all links. Otherwise all replies from the ARP targets will be received on the same link which could cause other links to fail. ARP monitoring is enabled by setting three properties <var>link-monitoring</var>, <var>arp-ip-targets</var> and <var>arp-interval</var>. Meaning of each option is described later in this article. It is possible to specify multiple ARP targets that can be useful in a High Availability setups. If only one target is set, the target itself may go down. Having an additional targets increases the reliability of the ARP monitoring.</p>
<p><strong>MII Monitoring:</strong><br />
MII monitoring monitors only the state of the local interface. In RouterOS it is possible to configure MII monitoring in two ways:</p>
<p><em>MII Type 1:</em> device driver determines whether link is up or down. If device driver does not support this option then link will appear as always up.<br />
<em>MII Type 2:</em> deprecated calling sequences within the kernel are used to determine if link is up. This method is less efficient but can be used on all devices. This mode should be set only if MII type 1 is not supported.</p>
<p>Main disadvantage is that MII monitoring can’t tell if the link actually can pass the packets or not even if the link is detected as up.</p>
<p>MII monitoring is configured setting desired <var>link-monitoring</var> mode and <var>mii-interval</var>.</p>
<div class="wp-about-author-containter-top" style="background-color:#FFEAA8;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=100&#038;d=mm&#038;r=g' srcset='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=200&#038;d=mm&#038;r=g 2x' class='author_gravatar left  avatar-100 photo' height='100' width='100' loading='lazy'/></div><div class="wp-about-author-text" style="margin-left:140px"><h3><a href='/author/vaheed/' title='vaheeD'>vaheeD</a></h3><p></p><p><a href='/author/vaheed/' title='More posts by vaheeD'>More Posts</a>  - <a href='https://plus.google.com/103839803047317952696' title='vaheeD'>Website</a> </p><p class="wpa-nomargin">Follow Me:<br /><a class='wpa-social-icons' href='http://www.facebook.com/vaheet'><img src='/wp-content/plugins/wp-about-author/images/facebook.png' alt='Facebook'/></a><a class='wpa-social-icons' href='https://plus.google.com/103839803047317952696'><img src='/wp-content/plugins/wp-about-author/images/googleplus.png' alt='Google Plus'/></a></p></div></div>The post <a href="/interface-bonding-802-3ad-lacp-with-mikrotik/">Interface Bonding 802.3ad (LACP) with Mikrotik</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></content:encoded>
					
					<wfw:commentRss>/interface-bonding-802-3ad-lacp-with-mikrotik/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ECMP Failover Script with MikroTik</title>
		<link>/ecmp-failover-script-with-mikrotik/</link>
					<comments>/ecmp-failover-script-with-mikrotik/#respond</comments>
		
		<dc:creator><![CDATA[vaheeD]]></dc:creator>
		<pubDate>Thu, 10 Jan 2013 20:37:06 +0000</pubDate>
				<category><![CDATA[MikroTik]]></category>
		<guid isPermaLink="false">/?p=483</guid>

					<description><![CDATA[<p>How to do automatic ECMP failover This script demonstrates one method of doing automatic failover using the Netwatch function and using scripting to enable or disable gateways. This is probably not the most efficient way, but it works. I would welcome any input on how it can be improved. The situation: You have 2 lines... </p>
<p><a class="small button secondary" href="/ecmp-failover-script-with-mikrotik/">Continue Reading</a></p>
The post <a href="/ecmp-failover-script-with-mikrotik/">ECMP Failover Script with MikroTik</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></description>
										<content:encoded><![CDATA[<p><span id="more-483"></span></p>
<h2>How to do automatic ECMP failover</h2>
<p>This script demonstrates one method of doing automatic failover using the Netwatch function and using scripting to enable or disable gateways. This is probably not the most efficient way, but it works. I would welcome any input on how it can be improved.</p>
<p>The situation:</p>
<p>You have 2 lines going out to the internet &#8211; 10.0.0.12 and 10.0.0.13. You have setup a mangle to mark HTTP traffic (optional) and want to route http along the 2 lines using load balancing.</p>
<p>You setup the mangle:</p>
<pre>   /ip firewall mangle add chain=prerouting protocol=tcp dst-port=80 action=mark-routing \
   new-routing-mark=ecmp-http-route passthrough=yes comment=" Route HTTP \
   traffic to ECMP" disabled=no</pre>
<p>You set up ECMP (Equal Cost Multipath Routing) by using something like</p>
<pre>   /ip route add dst-address=0.0.0.0/0 gateway=10.0.0.12,10.0.0.13 routing-mark=ecmp-http-route comment="ECMP route for HTTP"</pre>
<p>Now you have ECMP for HTTP only. This is nice because MSN messenger, banking websites and other programs and problem sites will not be broken in the same way it might be if you used ECMP for all protocols.</p>
<p>What I then do is for example mark SMTP traffic and route this out through 10.0.0.12:</p>
<pre>   /ip firewall mangle add chain=prerouting protocol=tcp dst-port=25 action=mark-routing \
   new-routing-mark=smtp-out passthrough=yes comment="SMTP Traffic" disabled=no</pre>
<pre>   /ip route add dst-address=0.0.0.0/0 gateway=10.0.0.12 routing-mark=smtp-out comment="SMTP Traffic out"</pre>
<p>and route all other traffic through 10.0.0.13</p>
<pre>   /ip route add dst-address=0.0.0.0/0 gateway=10.0.0.13 comment="Default Route to Internet"</pre>
<p>Then I need to setup 2 routes to specific addresses to force the router through specific gateways to &#8220;test&#8221; the links. These should not be popular addresses with your users! Otherwise when a gateway goes down they will have no access to those sites. The addresses I am using as an example are 1.1.1.12 to test 10.0.0.12, and 1.1.1.13 to test 10.0.0.13.</p>
<p>Next I use the Netwatch Function to switch all traffic to the working gateway should any of the gateways fail:</p>
<pre>   / tool netwatch 
   add host=1.1.1.13 timeout=2s interval=30s up-script="/ip route set \
   \[find comment=\"Default Route To Internet\"\] gateway=10.0.0.13" \
   down-script="/ip route set \[find comment=\"Default Route To Internet\"\] \
   gateway=10.0.0.12 comment="" disabled=no 
   add host=1.1.1.12 timeout=2s interval=30s up-script="/ip route set \
   \[find comment=\"SMTP Traffic out\"\] gateway=1.0.0.12" down-script="/ip \
   \n" \route set \[find comment=\"SMTP Traffic out\"\] gateway=10.0.0.13
   comment="" disabled=no</pre>
<p>The problem is that the ECMP http route will still be active, therefore http traffic wont work, so I have 2 scripts to check if both gateways are up or down and take action accordingly:</p>
<pre>/ system script 
   add name="ecmp-startup" source=":if ([/ping 1.1.1.12 count=1]=1 &amp;&amp; \
   [/ping 1.1.1.13 count=1]=1 &amp;&amp; [/ip route get [find \
   comment=\"ECMP Route For HTTP\"] disabled]=true) do={ :log info \"Both gateways up\" \
   \n/ip route set [find routing-mark=ecmp-http-route] \
   disabled=no}" policy=ftp,reboot,read,write,policy,test,winbox,password 
   add name="ecmp-shutdown" source=":if ([/ping 1.1.1.12 count=1]=1 &amp;&amp; \
   [/ping 1.1.1.13 count=1]=0) do={ :log info \"Gateway down\"\
   \n/ip route set [find routing-mark=ecmp-http-route] \
   disabled=yes}" policy=ftp,reboot,read,write,policy,test,winbox,password</pre>
<pre>   Hi I found this error while trying to use this script, what worked for me was
   ecmp start/shut script. Looks like  in the start and shut script (") are missing
   from the find, well other the script works wonders for me. Thanks a lot savagedavid</pre>
<pre>   ecmp starthp script
   :if ([/ping 1.1.1.13 count=1]=1 &amp;&amp; [/ping 1.1.1.12 count=1]=1 &amp;&amp; [/ip route get \
   [find routing-mark="ecmp-http-route"] disabled]=true) do={:log info "Both Gateways are up" \
   /n/ip route set [find routing-mark="ecmp-http-route"] disable=no}</pre>
<pre>   ecmp shutdown script
   :if ([/ping 1.1.1.13 count=1]=0 || [/ping 1.1.1.12 count=1]=0) do={:log info \
   "Gateway down" /ip route set [find routing-mark="ecmp-http-route"] disabled=yes}</pre>
<p>Notice that it first checks to see if the route is enable before trying to re-enable it. Otherwise it will reset the route and users will be dropped momentarily.</p>
<p>Then finally schedule the scripts to check every 30 seconds:</p>
<pre>   / system scheduler 
   add name="gateway-check" on-event="/system script run ecmp-shutdown
   script run ecmp-startup" start-date=jan/01/1970 start-time=00:00:00 \
   interval=30s comment="" disabled=no</pre>
<div class="wp-about-author-containter-top" style="background-color:#FFEAA8;"><div class="wp-about-author-pic"><img alt='' src='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=100&#038;d=mm&#038;r=g' srcset='http://1.gravatar.com/avatar/4ef8c65e8d3633adf28103cadb4591c2?s=200&#038;d=mm&#038;r=g 2x' class='author_gravatar left  avatar-100 photo' height='100' width='100' loading='lazy'/></div><div class="wp-about-author-text" style="margin-left:140px"><h3><a href='/author/vaheed/' title='vaheeD'>vaheeD</a></h3><p></p><p><a href='/author/vaheed/' title='More posts by vaheeD'>More Posts</a>  - <a href='https://plus.google.com/103839803047317952696' title='vaheeD'>Website</a> </p><p class="wpa-nomargin">Follow Me:<br /><a class='wpa-social-icons' href='http://www.facebook.com/vaheet'><img src='/wp-content/plugins/wp-about-author/images/facebook.png' alt='Facebook'/></a><a class='wpa-social-icons' href='https://plus.google.com/103839803047317952696'><img src='/wp-content/plugins/wp-about-author/images/googleplus.png' alt='Google Plus'/></a></p></div></div>The post <a href="/ecmp-failover-script-with-mikrotik/">ECMP Failover Script with MikroTik</a> first appeared on <a href="/">vaheeD khoshnouD</a>.]]></content:encoded>
					
					<wfw:commentRss>/ecmp-failover-script-with-mikrotik/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
