routeros_api — MikroTik RouterOS over REST

Blocks on a MikroTik router via the RouterOS REST API (RouterOS 7.1+), managing membership in firewall address-lists. The filter (or raw) rules that consume the lists are yours to build — the npf/netscaler "membership only" model. If you want the rules created for you, or are on RouterOS 6, use the ssh driven routeros backend instead.

[kur.sshd]
backend = "routeros_api"

[kur.sshd.options]
host     = "192.0.2.1"
user     = "blocker"
password = "hunter2"
insecure = 1

Router-side setup — required first

/ip firewall filter add chain=input src-address-list=kur_sshd action=drop
/ipv6 firewall filter add chain=input src-address-list=kur_sshd action=drop

(The lists themselves spring into being on first entry; the rules are the part that must exist for bans to bite.)

Requirements

Settings

Options

| option | default | what | |------------|-------------------|---------------------------------------------------------| | host | (required) | router, optionally host:port | | user | (required) | REST API user (basic auth) | | password | (required) | REST API password | | scheme | https | https or http | | insecure | 0 | skip TLS verification (RouterOS ships self-signed) | | list4 | <prefix>_<name> | IPv4 address-list name (/ip menu) | | list6 | <prefix>_<name> | IPv6 address-list name (/ipv6 menu) | | timeout | 30 | HTTP timeout in seconds |

What each operation does

IPv4 talks to /rest/ip/firewall/address-list, IPv6 to /rest/ipv6/firewall/address-list:

| operation | API traffic | |------------|--------------------------------------------------------------------------| | init | GET .../address-list?list=<list4> — verifies reachability and auth | | ban | PUT .../address-list with {"list":"<listN>","address":"<ip>"} | | unban | GET .../address-list?list=<listN>&address=<ip> to find the entry's .id, then DELETE .../address-list/<id> | | list | no API call — the kur's own ban book | | check | same probe as init | | flush | the lookup+DELETE per banned IP | | re_init | teardown (best effort), init, re-PUT every banned IP | | teardown | the lookup+DELETE per banned IP (ban book kept) |

An entry already removed on the router by hand is treated as already unbanned, not an error.

self_heal

check/init probe only the IPv4 list endpoint — reachability and credentials, not list contents, not the IPv6 side, and never whether any rule consumes the lists. As with npf, the kur will happily manage a list nothing reads; if bans don't bite, check the rules first.

Gotchas