RouterOS and MTU — a collection of useful scripts

1. Auditing L2 MTU

{ 
:local minimalMtu 1600
:local mtuCheck do={
:if ([/interface get $1 l2mtu] < $2) do={
:put ("Interface " . [/interface get $1 name] . " has MTU under " . $2)
}
}
# ethernet
:foreach i in=[/interface ethernet find running] do={
$mtuCheck $i $minimalMtu
}
# wireless
:foreach i in=[/interface wireless find disabled=no] do={
$mtuCheck $i $minimalMtu
}
}

2. Setting max L2 MTU on all ports

# ethernet - set maximum supported L2MTU by hardware 
/interface ethernet
:foreach i in=[find] do={
set $i l2mtu=[/interface get $i max-l2mtu]
}
# wireless - max supported L2MTU is 2290
/interface wireless
:foreach i in=[find] do={
set $i l2mtu=2290
}

3. Auditing L3 MTU

{ 
:local targetMtu 1500
:foreach i in=[/ip address find] do={
:local iface [/ip address get $i interface]
:if ([/interface get $iface actual-mtu] != $targetMtu) do={
:put ("L3 MTU on interface " . [/interface get $iface name] . " is not " . $targetMtu)
}
}
}

4. Setting L3 MTU

{ 
:local targetMtu 1500
:local filterTypes "eoip|ppp-out|l2tp-out"
:foreach i in=[/ip address find] do={
:local iface [/ip address get $i interface]
:if ([/interface get $iface type] ~ $filterTypes) do={
:put ("Ignoring interface " . [/interface get $iface name] . " due to filter")
} else={
:if ([/interface get $iface mtu] != $targetMtu) do={
:put ("Updating MTU to " . $targetMtu . " on " . [/interface get $iface name])
/interface set $iface mtu=$targetMtu
}
}
}
}
/interface 
:foreach i in=[find] do={
:put ("Type of interace " . [get $i name] . " is " . [get $i type])
}

5. Checking and setting MPLS MTU

{ 
:local targetMtu 1550
:if ([/mpls interface get [/mpls interface find default=yes] mpls-mtu] = $targetMtu) do={
:put "MPLS default interface MTU is CORRECT"
} else={
:put "MPLS default interface MTU is WRONG"
}
}
{ 
:local targetMtu 1580
/mpls interface
set [ find default=yes ] mpls-mtu=$targetMtu
}

Outro

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store