联系

MikroTik PPPoE + FreeRADIUS:真实的 ISP 认证堆栈

首页 / 博客

8 分钟阅读
ZILL E ALI7 月 14, 2026网络

A production MikroTik PPPoE FreeRADIUS setup has to survive exactly the moments described below.

DHCP is fine until you need to bill people. The day a subscriber swaps their router, disputes their usage, or you need to throttle a plan across twelve towers, PPPoE with FreeRADIUS is the stack that holds up.

Here is the working shape of it, end to end.

MikroTik PPPoE FreeRADIUS Setup Architecture

Subscriber CPE ──PPPoE──> MikroTik BNG ──RADIUS──> FreeRADIUS ──SQL──> PostgreSQL │ │ rate limit accounting (dynamic queue) (billing source)

RouterOS is the BNG (broadband network gateway). It terminates PPPoE sessions and asks FreeRADIUS a single question: may this user in, and at what speed?

MikroTik PPPoE FreeRADIUS setup: authentication flow from subscriber CPE to MikroTik BNG to FreeRADIUS over UDP 1812 and 1813 with SQL accounting

1. PPPoE server on RouterOS

/ip pool add name=pppoe-pool ranges=10.50.0.2-10.50.255.254 /ppp profile add name=pppoe-default local-address=10.50.0.1 remote-address=pppoe-pool \ dns-server=10.50.0.1 use-encryption=no only-one=yes /interface pppoe-server server add service-name=isp interface=bridge-access default-profile=pppoe-default \ authentication=pap,chap one-session-per-host=yes disabled=no

only-one=yes 以及 one-session-per-host=yes together stop credential sharing between households — the single highest-value line in this file.

2. Point RouterOS at RADIUS

/radius add service=ppp address=10.60.0.5 secret=<strong-shared-secret> \ timeout=800ms src-address=10.60.0.1 /ppp aaa set use-radius=yes accounting=yes interim-update=5m /radius incoming set accept=yes port=3799

interim-update=5m is the sweet spot. Shorter floods the RADIUS server on a large base; longer and a mid-session disconnect loses too much usage data to bill fairly.

RADIUS redundancy without a split-brain mess

One FreeRADIUS instance is a single point of failure for every new PPPoE login on the network, even though existing sessions stay up fine without it. RouterOS accepts multiple RADIUS entries and tries them in order:

/radius add service=ppp address=10.60.0.5 secret=<strong-shared-secret> timeout=800ms src-address=10.60.0.1 add service=ppp address=10.60.0.6 secret=<strong-shared-secret> timeout=800ms src-address=10.60.0.1

The real work is not the RouterOS side – it is keeping both FreeRADIUS instances reading the same PostgreSQL data without writing conflicting accounting rows. Point both at one PostgreSQL primary (a read replica for reporting queries is fine, but radacct writes need one source of truth), and keep the shared secret identical on both so a failover is invisible to the BNG. Test the failover by actually stopping the primary FreeRADIUS process during a quiet window, not by assuming the second entry works because it is configured.

3. FreeRADIUS with SQL

Enable the sql module and store plans as reply attributes rather than hard-coded queues:

-- Plan: Home 20 Mbps, burst to 25 for 15s INSERT INTO radgroupreply (groupname, attribute, op, value) VALUES ('home-20', 'Mikrotik-Rate-Limit', ':=', '10M/20M 12M/25M 10M/20M 15'); -- Assign a subscriber to a plan INSERT INTO radusercheck (username, attribute, op, value) VALUES ('ali.k', 'Cleartext-Password', ':=', 'change-me'); INSERT INTO radusergroup (username, groupname, priority) VALUES ('ali.k', 'home-20', 1);

该 Mikrotik-Rate-Limit syntax is rx/tx burst-rx/burst-tx threshold-rx/threshold-tx burst-time. Direction is from the router's point of view, so the first value is the subscriber's 上传. Get this backwards and every customer reports "my download is only 10 Mbps" — I have made that call myself.

4. Suspend and restore without touching the router

Non-payment handling should never mean logging into a RouterOS box. Move the subscriber to a restricted group and send a disconnect:

echo "User-Name=ali.k,Acct-Session-Id=81a0043c,NAS-IP-Address=10.60.0.1" \ | radclient -x 10.60.0.1:3799 disconnect <shared-secret>

Next reconnect they land in the suspended group, whose reply attributes point DNS at a payment-reminder page and cap the rate at 512k. Pay, group flips back, session resets, service restored. No truck roll.

Testing before it touches real subscribers

radtest confirms the RADIUS side answers correctly before a single real PPPoE session depends on it:

radtest ali.k change-me 10.60.0.5 0 <shared-secret>

A clean Access-Accept with the expected Mikrotik-Rate-Limit attribute in the reply means the SQL groups and reply attributes are wired correctly, independent of anything on the router. Run this from the FreeRADIUS box itself first, then from the RouterOS network – a pass locally but a timeout from the BNG subnet means a firewall rule on UDP 1812/1813, not a FreeRADIUS config problem, and it saves an hour of debugging the wrong layer.

Before cutting real subscribers over, build one test PPPoE profile with a deliberately low rate limit and confirm the full suspend-and-restore flow end to end: disconnect via radclient, reconnect, confirm the restricted group applies, flip the group back, reconnect again. If that round trip does not work cleanly on a test account, it will not work at 2 am on a real one either.

5. Accounting you can actually bill from

radacct gives you start time, stop time, input and output octets per session. Two practical notes:

  • 使用 BIGINT columns. 32-bit octet counters wrap at 4 GB and a single evening of streaming will corrupt an invoice.
  • Reconcile against interface counters weekly. Sessions that end in a power cut close with a stale stop record; interim updates are what save you.

Sizing and failure modes

Symptom Usual cause
Random session drops at the same time daily RADIUS timeout too tight, or DB backup locking radacct
Speeds ignore the plan Rate-limit direction reversed, or a static queue overriding the dynamic one
Sessions stick after CPE reboot 否 only-one=yes; stale session holds the username
CPU spikes on the BNG PPPoE encryption enabled unnecessarily, or too many interim updates

An RB5009 comfortably terminates a few hundred PPPoE sessions. Past roughly a thousand, move to a CCR-class BNG and split by area.

Migrating existing DHCP subscribers without a truck roll

Most ISPs running this stack are migrating off a flat DHCP network, not building from zero, and the CPE is usually already in the customer’s hands. The sequence that avoids a site visit:

  1. Enable PPPoE server alongside DHCP on the same bridge – they coexist fine as long as the IP pools do not overlap.
  2. Push PPPoE credentials remotely if the CPE supports TR-069/ACS management, or via the CPE’s own cloud app (many consumer ONTs and routers support this) – this is the step that avoids sending a technician out.
  3. Migrate in small batches per tower, not the whole base at once. A batch of 20-30 subscribers lets you catch a bad default profile before it is a thousand support calls.
  4. Leave the DHCP pool running until the last batch confirms clean, then decommission it. Do not delete the DHCP server the same week as the first migration batch – it is your rollback path if PPPoE throughput or stability does not match expectations.

Troubleshooting commands that actually tell you something

When a subscriber cannot connect, these four commands – in this order – find the layer that is actually broken faster than guessing:

/ppp active print ; is there even a session attempt reaching the BNG? /radius monitor 0 ; is RouterOS sending Access-Request at all? /log print where topics~"radius" ; what did RouterOS log about the RADIUS exchange? /interface pppoe-server print stats ; auth failures vs. successful sessions, by interface

On the FreeRADIUS side, radiusd -X run in the foreground on a non-production instance shows the full attribute exchange for a single test login – the fastest way to see exactly which reply attribute is missing or malformed before it reaches RouterOS at all.

Where this goes next

CPE quirks worth knowing before the first batch

Not every router behind this setup behaves the same way, and three specific quirks account for most of the “it works for everyone except this one customer” tickets:

  • Some older ONTs cache the PPPoE session and will not re-authenticate cleanly after a RADIUS-triggered disconnect until the ONT itself is power-cycled – a soft reboot via the CPE’s own management page is usually enough, no truck roll required.
  • MTU mismatches show up as “the internet half-works.” PPPoE’s 8-byte overhead means a CPE still using 1500 MTU on its LAN side will fail on large packets – video calls and some secure sites break while plain web browsing looks fine. Set the PPPoE interface MTU to 1492 on RouterOS and push the matching value to CPE profiles where the vendor exposes it.
  • Dual-WAN or mesh CPE sometimes opens two PPPoE sessions from the same household during a failover test, which one-session-per-host=yes blocks correctly but then logs as a connection failure the customer reports as “my internet won’t connect” rather than “my internet failed over.” Check the PPPoE active list for a second half-open session before assuming a credentials problem.

Once authentication and accounting are solid, the missing piece is the business layer: plans, invoices, vouchers, and a support view of who is online right now. That is precisely what NexaLink puts on top of this stack — the same FreeRADIUS schema, with an operator UI over it.

作者

ZILL E ALI

拥有 MTCNA 和 MTCRE 认证的网络工程师、ISP 基础设施专家,Developer Zon 创始人。在此撰写关于 MikroTik、Cisco、ISP 基础设施以及偶尔的构建日志。

留下回复

本站使用 Akismet 来减少垃圾评论。了解您的评论数据如何被处理。