MikroTik Configuration
Settings for the MikroTik RouterOS API connection.
Connection
Section titled “Connection”mikrotik.address Required
Section titled “mikrotik.address ”Env: MIKROTIK_HOST · Default: — (required)
RouterOS API address in host:port format. There is no built-in default: the bouncer exits with mikrotik.address is required if this value is empty. The 192.168.0.1:8728 used below is the sample value shipped in config/cs-routeros-bouncer.yaml, not a default.
- Port
8728— plaintext API - Port
8729— TLS-encrypted API
mikrotik: address: "192.168.0.1:8728"mikrotik.username Required
Section titled “mikrotik.username ”Env: MIKROTIK_USER · Default: — (required)
The RouterOS API username. There is no built-in default: the bouncer exits with mikrotik.username is required if this value is empty. The crowdsec name is the sample value shipped in config/cs-routeros-bouncer.yaml, not a default. Use a dedicated user with minimal permissions. See Router Setup for creating the user.
mikrotik.password Required
Section titled “mikrotik.password ”Env: MIKROTIK_PASS · Default: — (required)
The RouterOS API password.
mikrotik.tls Optional
Section titled “mikrotik.tls ”Env: MIKROTIK_TLS · Default: false
Enable TLS for the RouterOS API connection. Requires the api-ssl service on the router (port 8729).
mikrotik: address: "192.168.0.1:8729" tls: truemikrotik.tls_insecure Optional
Section titled “mikrotik.tls_insecure ”Env: MIKROTIK_TLS_INSECURE · Default: false
Skip TLS certificate verification. Only needed when the router uses a self-signed certificate.
Timeouts
Section titled “Timeouts”mikrotik.connection_timeout Optional
Section titled “mikrotik.connection_timeout ”Env: MIKROTIK_CONN_TIMEOUT · Default: 10s
Maximum time to connect and log in to the API, at startup and on every reconnect; 0 means no limit. Uses Go duration format.
mikrotik.command_timeout Optional
Section titled “mikrotik.command_timeout ”Env: MIKROTIK_CMD_TIMEOUT · Default: 30s
Maximum time to wait for the router while it answers an API command: for the answer to start, and between two parts of a long one. A router that stops answering fails the command; an answer that keeps coming, such as a large address list on a slow router, is not cut off. Increase it if your router is slow to start an answer.
Connection Pool
Section titled “Connection Pool”mikrotik.pool_size Optional
Section titled “mikrotik.pool_size ”Env: MIKROTIK_POOL_SIZE · Default: 4
How many RouterOS API sessions the bouncer can use for parallel work such as reconciliation removals. A higher value increases throughput when reconciliation has many stale address-list entries to delete, and with bulk_add_method: api also when it has many entries to add over a link with latency; on the router’s LAN one session adds fastest, and each extra one holds about 1.7 MiB of router RAM. Live decisions always use the main connection, so they are not affected.
- Valid range: 1–20
- Auto-capping: On startup the bouncer queries the router’s API service
max-sessionslimit and automatically reduces the effective pool size so it never exceedsmax-sessions − 2(reserving connections for the main client and external tools such as WinBox).
mikrotik: pool_size: 8 # Higher parallelism for reconciliation removalsChecking the router limit
Section titled “Checking the router limit”The RouterOS API service has a max-sessions setting that limits simultaneous connections. The factory default is 20.
# Check current limit/ip/service/print where name=api
# Increase it (maximum supported value is 1000)/ip/service/set api max-sessions=1000Bulk Add Method
Section titled “Bulk Add Method”mikrotik.bulk_add_method Optional
Section titled “mikrotik.bulk_add_method ”Env: MIKROTIK_BULK_ADD_METHOD · Default: script
How reconciliation (at startup and every crowdsec.reconciliation_interval) adds the address-list entries the router is missing. Live decisions are not affected: they are always added one API call each.
script(default): the bouncer sends up to 100 adds as one RouterOS script. On RouterOS 7.8rc1 and later that is a single/executecall that runs the script synchronously: nothing is stored on the router and nothing reaches its log. On older versions, and for a chunk/executecannot take (over its 64 kB limit, or on a router that turns out to lack it), the bouncer creates a temporary/system/script, runs it and removes it again. Either way the round trips a chunk costs do not depend on how many entries it holds: one through/execute, four as a stored script. Latency to the router therefore weighs far less than withapi, which pays a round trip per entry. An add the script cannot make is reported back through/executeand retried with its own API call; if a script fails, that chunk is retried one call per entry.api: every entry is added with its own API call, spread over the connection pool (pool_size), or one after another on the main connection when the pool could not be opened. No script is ever created, and the router’s configuration is left alone.
On RouterOS older than 7.8rc1, RouterOS logs every stored script with its full source when it is created, an audit of /system/script shows the bouncer’s scripts coming and going, and each add and remove is a configuration change RouterOS persists; api avoids all of that there. From 7.8rc1 on, script leaves none of it behind either, as long as /execute runs the chunk; the stored-script fallback above still does. api still runs no script at all, and it caches the id of every entry it adds, so a live unban right after a reconciliation pass removes the entry without looking it up first. Address-list entries with a timeout, which is what decisions become, are dynamic and stay in memory either way.
mikrotik: bulk_add_method: api pool_size: 4 # adds spread over the pool: helps over a link with latency, not on the router's LANRouter CPU
Section titled “Router CPU”mikrotik.cpu_limit Optional
Section titled “mikrotik.cpu_limit ”Env: MIKROTIK_CPU_LIMIT · Default: 80
The router’s CPU load, in percent of all its cores, at which the bouncer slows its reconciliation work down. While the load is at or above it, the bouncer pauses before each block of work (a script of 100 adds, 100 single adds or removals, a duplicate lookup) and uses one API connection at a time. The pause starts at 200 ms, doubles for each further busy second up to 5 s, and halves for each second the load is 10 points under the limit (or under half the limit, when that is lower), back to full speed. A periodic pass also waits up to a minute for the load to drop before it reads the address list. Live bans and unbans are never slowed down, and are applied while a pass runs, slowed or not, save an unban for an address the pass had already planned to add, which takes effect when the pass ends. Neither is a shutdown slowed down. 0 turns it off.
The load is RouterOS’ own cpu-load: the average of all cores over the last second, read at most once a second while there is bulk work. One busy second, such as the router’s own periodic jobs, slows nothing down: it takes two in a row.
mikrotik: cpu_limit: 80