basforge

Search titles, text and the “If it doesn’t work” cases.

    RU
    OverviewHomelabMikroTik

    Wired networking on MikroTik: bridge, switch chip, fasttrack and VLANs

    Inside the home network, traffic between ports of one bridge is switched by the switch chip — at port speed and bypassing the CPU. Toward the internet every packet goes through the CPU and the firewall, and fasttrack holds the speed there: already allowed connections bypass the rules. Most “why is it slow” questions are about which of the two paths the traffic takes.

    A packet’s two paths

    computer ──┐                                      ┌─ ether1 ── ISP
    NAS ───────┼─ switch chip ───────── CPU ──────────┤
    TV ────────┘   (bridge, H flag)     firewall, NAT, └─ Wi-Fi: radio always
                   port speed,          queues,           goes through the CPU
                   CPU stays idle       fasttrack
    • Inside the network, over wires. Ports of one bridge on one switch chip are switched in hardware: the computer and the NAS exchange data at 1 or 2.5 Gbit/s, and the CPU never sees it. An ordinary unmanaged switch works the same way.
    • To the internet and between networks. The packet goes up to the CPU: routing, firewall, NAT, queues. Speed depends on the CPU and on how many rules the packet passes.
    • Wi-Fi. The radio is attached to the CPU, and the switch chip doesn’t serve it: traffic between a laptop on Wi-Fi and a NAS on cable goes through the CPU and, inside it, through the bridge.

    The bridge and hardware offloading

    In a hAP’s factory config, every port except ether1 and both radios are in one bridge, bridge. The router’s address 192.168.88.1 sits on the bridge, not on a port.

    /interface bridge port print
    # Flags: I - INACTIVE; H - HW-OFFLOAD
    # Columns: INTERFACE, BRIDGE, HW, PVID
    # #    INTERFACE  BRIDGE  HW   PVID
    # 0 IH ether2     bridge  yes     1
    # 1  H ether3     bridge  yes     1
    # 4    wifi1      bridge          1

    The H flag means the switch chip serves the port. I means nothing is plugged in. Wi-Fi has no flag and can’t have one.

    Offloading goes away when the bridge needs a feature the chip doesn’t have. What each chip supports is in the table on the Bridge Hardware Offloading page. Common cases:

    • use-ip-firewall=yes on the bridge — packets inside the network go through the firewall;
    • vlan-filtering=yes on some chips — then the CPU handles VLANs1;
    • two bridges on one chip — only the first gets offloading.

    Fasttrack: how internet speed holds up

    Every packet to the internet passes the firewall’s forward chain, the connection table, NAT, queues. Fasttrack is a rule in the default config that, after a connection’s first packets, lets the rest bypass all that:

    /ip firewall filter
    add action=fasttrack-connection chain=forward connection-state=established,related \
        hw-offload=yes comment="defconf: fasttrack"
    add action=accept chain=forward connection-state=established,related,untracked \
        comment="defconf: accept established,related, untracked"

    How much it matters shows in MikroTik’s tests with 1518-byte packets: the hEX refresh routes 3.65 Gbit/s with no rules (fast path) and 1.43 through 25 firewall rules. Fasttrack brings connections back to the first figure. With small packets — games, calls — the difference is bigger.

    Check that it works by the counters — fasttrack’s should grow:

    /ip firewall filter print stats where action=fasttrack-connection
    # Columns: CHAIN, ACTION, BYTES, PACKETS
    # #  CHAIN    ACTION                BYTES          PACKETS
    # 0  forward  fasttrack-connection  48 213 773 041  41 950 112

    Fasttracked traffic also bypasses everything that doesn’t get along with it: Simple Queue and Queue Tree don’t see it (Fasttrack and queues), and neither does mangle. hw-offload=yes in the rule hands connections to hardware only on chips with hardware routing — CRS3xx and higher-end CCRs; on the hAP and hEX the parameter changes nothing2.

    VLANs at home

    A VLAN is several networks on one cable. At home you need them in three cases:

    • Guests and smart home through access points. The router and a cAP are joined by one cable, but there are two Wi-Fi networks: home and guest. On the cable they travel with different tags.
    • The ISP. Internet or IPTV arrives tagged with a VLAN — the ISP gives the number.
    • A dedicated port for a camera or a lab with its own network and rules.

    With one router and no access points, a guest network is easier as a separate bridge without VLANs (Guest network on MikroTik). With VLANs the config looks like this — an example for guests on tag 20 toward an access point on ether2:

    /interface bridge vlan add bridge=bridge vlan-ids=20 tagged=bridge,ether2
    /interface vlan add name=vlan20-guest vlan-id=20 interface=bridge
    /ip address add address=192.168.89.1/24 interface=vlan20-guest
    # the home network still goes untagged over ether2: pvid=1
    /interface bridge set bridge vlan-filtering=yes

    vlan-filtering=yes goes last and in Safe Mode: while the filter is off, bridge vlan entries do nothing, and once it’s on, a mistake in them cuts off the port3.

    Ports and power

    What How it works What to keep in mind
    1G regular gigabit 940 Mbit/s of useful speed is the ceiling
    2.5G on the hAP ax³, hAP be, RB5009 works over Cat5e at home distances; the other end needs a 2.5G card
    2.5G SFP on the hEX S, hAP ax S, L009 the ISP’s fiber module or a copper module; modules sold separately
    10G SFP+ on the RB5009 to a NAS or switch — a DAC cable or fiber: 10G copper modules run hot
    passive PoE hAP ax², hEX S: power without negotiation for MikroTik access points; not for 802.3af/at cameras
    802.3af/at PoE RB5009UPr; input on the cAP ax and hEX S standard power: cameras, other brands’ access points

    /interface ethernet monitor ether2 once shows a port’s speed and mode — the rate and full-duplex lines.

    Two ISPs

    Two default routes with different distances: the one with the lower distance works, the other waits.

    /ip route add dst-address=0.0.0.0/0 gateway=192.0.2.1 distance=1 check-gateway=ping \
        comment="primary"
    /ip route add dst-address=0.0.0.0/0 gateway=198.51.100.1 distance=2 comment="backup"

    check-gateway=ping pings the gateway every 10 seconds and disables the route after two failures. If the ISP hands out the address via DHCP, set the distance in the client: /ip dhcp-client set [find interface=ether1] default-route-distance=1. Both ISP interfaces must be in the WAN list, or masquerade won’t work on the second.

    An ISP gateway still answers ping when the network behind it is gone. Check an outside address instead, with a recursive route:

    /ip route add dst-address=1.1.1.1/32 gateway=192.0.2.1 scope=10 comment="check ISP1"
    /ip route add dst-address=0.0.0.0/0 gateway=1.1.1.1 target-scope=11 check-gateway=ping \
        distance=1 comment="primary"
    /ip route add dst-address=0.0.0.0/0 gateway=198.51.100.1 distance=2 comment="backup"

    The primary route looks up its gateway 1.1.1.1 among routes with scope up to 11 and finds the first one — to 1.1.1.1 via ISP 1. check-gateway=ping now pings 1.1.1.1: the network behind the gateway goes away — within half a minute primary gets the I flag and backup takes over; it comes back — primary turns on by itself. 1.1.1.1 now goes only through the first ISP, so give the router a different DNS server, such as 9.9.9.9.

    Queues against lag

    When the link is loaded — a cloud backup or a torrent is running — ping in games and calls climbs to hundreds of milliseconds: packets queue up at the ISP. A cake or fq_codel queue on the router keeps that queue on your side and lets small packets through first. Set the queue speed 5–10% below the plan. Fasttrack then has to be turned off or bypassed: queues don’t see its traffic (Fasttrack and queues).

    If it doesn’t work

    Copying files from the NAS to a wired computer is slow, and the router’s CPU is busy meanwhile

    Cause
    The ports aren’t hardware-offloaded: there’s no H flag on the port in /interface bridge port print. Traffic between them goes through the CPU. Offloading gets turned off by things like use-ip-firewall=yes in the bridge settings, or ports in different bridges.
    Fix
    Check the H flag on the ports and what’s enabled on the bridge with /interface bridge print detail. Keep the NAS and the computer in one bridge on ports of one switch chip.

    Turned on vlan-filtering=yes — and the router vanished

    Cause
    After the filter came on, the port you were connected through landed in the wrong VLAN: its pvid is wrong, or the bridge has no entry in /interface bridge vlan.
    Fix
    Turn on vlan-filtering=yes as the last command and in Safe Mode (Safe Mode): if the connection drops, the change rolls back. Already cut off — Winbox by MAC from a port still in VLAN 1, or a reset.

    A 2.5G port comes up at 1 Gbit/s, or even 100 Mbit/s

    Cause
    The device at the other end can’t do 2.5G, or the cable is bad: the link drops to 100 Mbit/s when only two of the four pairs work.
    Fix
    /interface ethernet monitor ether1 once shows rate and auto-negotiation. Replace the cable with Cat5e or better, and check that the card at the other end is 2.5G.

    The main ISP went down, and the backup route didn’t kick in

    Cause
    check-gateway=ping checks only the ISP’s gateway. The gateway answers, the network beyond it doesn’t work, and the route counts as alive.
    Fix
    Check reachability of an outside address: a recursive route via 1.1.1.1 — the example is in “Two ISPs” — or netwatch that disables the route.

    Not verified yet

    1. whether bridge hardware offloading survives vlan-filtering on the hAP ax² and ax³ ↑
    2. whether hw-offload=yes on fasttrack does anything on the hAP ax² ↑
    3. the VLAN 20 example on a hAP ax² and cAP ax step by step ↑