Skip to main content

πŸ’‘ Mikrotik Failback

Keep traffic shaped even when LibreQoS is offline by automatically enabling RouterOS simple queues during outages. This guide adds FQ_CoDel queues, a Netwatch failback, and PPP on-up/on-down scripts so users are shaped locally when LibreQoS is down and disabled when it’s back online.

info

This setup assumes LibreQoS is the primary shaper and MikroTik queues are the fallback. When LibreQoS is online, queues are disabled; when it’s down, queues are enabled.

Prerequisites​

  • βœ… MikroTik RouterOS v6.49+ or v7.x
  • βœ… PPPoE users (or PPP secrets) with profiles
  • βœ… LibreQoS reachable on your network (e.g., 10.10.10.10)
  • βœ… Netwatch enabled for uptime detection
  • βœ… Admin access via Winbox or SSH
warning

These scripts modify queues automatically. Test on a small subset of users before enabling globally.

Configuration Steps​

  1. Create FQ_CoDel queue type

    /queue type add kind=fq-codel name=FQ_CODEL
  2. Limit SSH access to a dedicated API group

    /user group add name=sshAPI policy=ssh,read,write,!local,!telnet,!ftp,!reboot,!policy,!test,!winbox,!password,!web,!sniff,!sensitive,!api,!romon
  3. PPP on-up script (create fallback queue)

    :local address [/ppp active get [find name=$user] address]
    :local limit [/ppp profile get [find name=[/ppp secret get [find name=$user] profile]] comment]
    :local status [/tool netwatch get [find name="libreqos"] status]
    :if ($limit != "") do={
    :if ($status = "up") do={
    /queue simple add target=$address max-limit=$limit limit-at=$limit disabled=yes queue=FQ_CODEL/FQ_CODEL name=$user
    } else={
    /queue simple add target=$address max-limit=$limit limit-at=$limit disabled=no queue=FQ_CODEL/FQ_CODEL name=$user
    }
    }
  4. PPP on-down script (remove fallback queue)

    /queue simple remove [find dynamic=no name~$user]
  5. Netwatch entry for LibreQoS

    /tool netwatch add host=10.10.10.10 interval=00:00:30 timeout=2s name=libreqos \
    up-script="/queue simple set [find dynamic=no] disabled=yes" \
    down-script="/queue simple set [find dynamic=no] disabled=no"
  6. Apply PPP profile scripts

    • Add the on-up and on-down scripts to your PPP profile(s).

Option B: Winbox​

  1. Create FQ_CoDel queue type

    • Queues β†’ Queue Types β†’ Add (+)
    • Name: FQ_CODEL
    • Kind: fq-codel
  2. Create SSH API group

    • System β†’ Users β†’ Groups β†’ Add (+)
    • Name: sshAPI
    • Policies: check ssh, read, write only (disable all others)
  3. Add PPP on-up script

    • PPP β†’ Profiles β†’ Select Profile β†’ Scripts β†’ On Up
    • Paste the on-up script from Option A
  4. Add PPP on-down script

    • PPP β†’ Profiles β†’ Select Profile β†’ Scripts β†’ On Down
    • Paste the on-down script from Option A
  5. Add Netwatch entry

    • Tools β†’ Netwatch β†’ Add (+)
    • Host: LibreQoS IP (e.g., 10.10.10.10)
    • Interval: 00:00:30
    • Timeout: 2s
    • Up Script: /queue simple set [find dynamic=no] disabled=yes
    • Down Script: /queue simple set [find dynamic=no] disabled=no

Understanding the Configuration​

Flow Diagram

[PPPoE User Up]
↓
[Create Simple Queue Disabled]
↓
[Netwatch Checks LibreQoS]
↓
[LibreQoS Down?] β†’ Enable Queues
[LibreQoS Up?] β†’ Disable Queues

Components Table

ComponentPurposeNotes
FQ_CODEL queueLow-latency fallback shapingApplied to PPP users
PPP on-up scriptAdds user queueDisabled when LibreQoS is up
PPP on-down scriptRemoves user queueKeeps config clean
NetwatchDetects LibreQoS availabilityToggles queue state
sshAPI groupLimits accessOptional but recommended

Verification​

  1. Confirm queue type exists
    /queue type print where name="FQ_CODEL"
  2. Check Netwatch status
    /tool netwatch print where name="libreqos"
  3. Simulate LibreQoS down (block ping or power off)
    • Verify queues become enabled
  4. Simulate LibreQoS up
    • Verify queues become disabled

Troubleshooting​

IssueCauseSolution
Queues never enableNetwatch not firingCheck host IP and timeout
Queues always enabledNetwatch stuck downVerify ping reachability
No queues createdPPP profile has no commentAdd download/upload in profile comment
Wrong speedProfile comment format invalidUse 100M/50M format
Duplicate queuesScript runs multiple timesRemove existing queue on-up before add
On-down not removingName mismatchEnsure name=$user matches PPP user
High latencyQueue type wrongConfirm FQ_CODEL set correctly
CPU spikesToo many queuesUse queue trees for scale
LibreQoS flappingShort intervalIncrease Netwatch interval
SSH access too openGroup policiesUse sshAPI group only
PPP user missingNot activeCheck /ppp active print
Script errorsSyntax issuePaste scripts exactly as shown

Advanced Options​

  1. Guard against duplicate queues
    /queue simple remove [find dynamic=no name=$user]
    /queue simple add target=$address max-limit=$limit limit-at=$limit disabled=yes queue=FQ_CODEL/FQ_CODEL name=$user
  2. Use higher fallback limits for VIP users
  3. Set per-profile queue types
  4. Add logging to Netwatch scripts
    /log info "LibreQoS down β€” enabling fallback queues"
  5. Use Netwatch with multiple LibreQoS targets
  6. Schedule daily cleanup of stale queues
  7. Disable queues only for certain profiles
  8. Move fallback queues to queue trees
  9. Set burst parameters for short spikes
  10. Integrate with Telegram alerts

Completion​

βœ… LibreQoS failback queues are active!

Next steps:

  • Test outage and recovery workflows
  • Document profile limits and naming
  • Monitor CPU usage during fallback