{"id":6137,"date":"2026-07-14T13:00:00","date_gmt":"2026-07-14T08:00:00","guid":{"rendered":"https:\/\/zilleali.com\/mikrotik-pppoe-freeradius-isp\/"},"modified":"2026-11-25T16:06:31","modified_gmt":"2026-11-25T11:06:31","slug":"mikrotik-pppoe-freeradius-isp","status":"publish","type":"post","link":"https:\/\/zilleali.com\/zh\/mikrotik-pppoe-freeradius-isp\/","title":{"rendered":"MikroTik PPPoE + FreeRADIUS\uff1a\u771f\u5b9e\u7684 ISP \u8ba4\u8bc1\u5806\u6808"},"content":{"rendered":"<p>A production MikroTik PPPoE FreeRADIUS setup has to survive exactly the moments described below.<\/p>\n<p>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, <strong>PPPoE with <a href=\"https:\/\/freeradius.org\/\">FreeRADIUS<\/a><\/strong> is the stack that holds up.<\/p>\n<p>Here is the working shape of it, end to end.<\/p>\n<h2 id=\"mikrotik-pppoe-freeradius-setup-architecture\">MikroTik PPPoE FreeRADIUS Setup Architecture<\/h2>\n<pre><code class=\"language-text\">Subscriber CPE \u2500\u2500PPPoE\u2500\u2500&gt; MikroTik BNG \u2500\u2500RADIUS\u2500\u2500&gt; FreeRADIUS \u2500\u2500SQL\u2500\u2500&gt; PostgreSQL\n                              \u2502                         \u2502\n                          rate limit                accounting\n                       (dynamic queue)            (billing source)\n<\/code><\/pre>\n<p>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?<\/p>\n<p><picture><source srcset=\"https:\/\/zilleali.com\/wp-content\/uploads\/2026\/11\/mikrotik-pppoe-freeradius-isp-supporting-1.webp\" type=\"image\/webp\"><img decoding=\"async\" src=\"https:\/\/zilleali.com\/wp-content\/uploads\/2026\/11\/mikrotik-pppoe-freeradius-isp-supporting-1.webp\" alt=\"MikroTik PPPoE FreeRADIUS setup: authentication flow from subscriber CPE to MikroTik BNG to FreeRADIUS over UDP 1812 and 1813 with SQL accounting\"><\/picture><\/p>\n<h2 id=\"1-pppoe-server-on-routeros\">1. PPPoE server on RouterOS<\/h2>\n<pre><code class=\"language-routeros\">\/ip pool\nadd name=pppoe-pool ranges=10.50.0.2-10.50.255.254\n\n\/ppp profile\nadd name=pppoe-default local-address=10.50.0.1 remote-address=pppoe-pool \\\n    dns-server=10.50.0.1 use-encryption=no only-one=yes\n\n\/interface pppoe-server server\nadd service-name=isp interface=bridge-access default-profile=pppoe-default \\\n    authentication=pap,chap one-session-per-host=yes disabled=no\n<\/code><\/pre>\n<p><code>only-one=yes<\/code> \u4ee5\u53ca <code>one-session-per-host=yes<\/code> together stop credential sharing between households \u2014 the single highest-value line in this file.<\/p>\n<h2 id=\"2-point-routeros-at-radius\">2. Point RouterOS at RADIUS<\/h2>\n<pre><code class=\"language-routeros\">\/radius\nadd service=ppp address=10.60.0.5 secret=&lt;strong-shared-secret&gt; \\\n    timeout=800ms src-address=10.60.0.1\n\n\/ppp aaa\nset use-radius=yes accounting=yes interim-update=5m\n\n\/radius incoming\nset accept=yes port=3799\n<\/code><\/pre>\n<p><code>interim-update=5m<\/code> 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.<\/p>\n<h2 id=\"radius-redundancy-without-a-split-brain-mess\">RADIUS redundancy without a split-brain mess<\/h2>\n<p>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:<\/p>\n<pre><code class=\"language-routeros\">\/radius\nadd service=ppp address=10.60.0.5 secret=&lt;strong-shared-secret&gt; timeout=800ms src-address=10.60.0.1\nadd service=ppp address=10.60.0.6 secret=&lt;strong-shared-secret&gt; timeout=800ms src-address=10.60.0.1\n<\/code><\/pre>\n<p>The real work is not the RouterOS side &#8211; 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 <code>radacct<\/code> 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.<\/p>\n<h2 id=\"3-freeradius-with-sql\">3. FreeRADIUS with SQL<\/h2>\n<p>Enable the <code>sql<\/code> module and store plans as reply attributes rather than hard-coded queues:<\/p>\n<pre><code class=\"language-sql\">-- Plan: Home 20 Mbps, burst to 25 for 15s\nINSERT INTO radgroupreply (groupname, attribute, op, value) VALUES\n  (&#39;home-20&#39;, &#39;Mikrotik-Rate-Limit&#39;, &#39;:=&#39;, &#39;10M\/20M 12M\/25M 10M\/20M 15&#39;);\n\n-- Assign a subscriber to a plan\nINSERT INTO radusercheck (username, attribute, op, value) VALUES\n  (&#39;ali.k&#39;, &#39;Cleartext-Password&#39;, &#39;:=&#39;, &#39;change-me&#39;);\nINSERT INTO radusergroup (username, groupname, priority) VALUES\n  (&#39;ali.k&#39;, &#39;home-20&#39;, 1);\n<\/code><\/pre>\n<p>\u8be5 <code>Mikrotik-Rate-Limit<\/code> syntax is <code>rx\/tx burst-rx\/burst-tx threshold-rx\/threshold-tx burst-time<\/code>. Direction is from the router&#39;s point of view, so the first value is the subscriber&#39;s <strong>\u4e0a\u4f20<\/strong>. Get this backwards and every customer reports &quot;my download is only 10 Mbps&quot; \u2014 I have made that call myself.<\/p>\n<h2 id=\"4-suspend-and-restore-without-touching-the-router\">4. Suspend and restore without touching the router<\/h2>\n<p>Non-payment handling should never mean logging into a RouterOS box. Move the subscriber to a restricted group and send a disconnect:<\/p>\n<pre><code class=\"language-bash\">echo &quot;User-Name=ali.k,Acct-Session-Id=81a0043c,NAS-IP-Address=10.60.0.1&quot; \\\n  | radclient -x 10.60.0.1:3799 disconnect &lt;shared-secret&gt;\n<\/code><\/pre>\n<p>Next reconnect they land in the <code>suspended<\/code> 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.<\/p>\n<h2 id=\"testing-before-it-touches-real-subscribers\">Testing before it touches real subscribers<\/h2>\n<p><code>radtest<\/code> confirms the RADIUS side answers correctly before a single real PPPoE session depends on it:<\/p>\n<pre><code class=\"language-bash\">radtest ali.k change-me 10.60.0.5 0 &lt;shared-secret&gt;\n<\/code><\/pre>\n<p>A clean Access-Accept with the expected <code>Mikrotik-Rate-Limit<\/code> 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 &#8211; 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.<\/p>\n<p>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 <code>radclient<\/code>, 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.<\/p>\n<h2 id=\"5-accounting-you-can-actually-bill-from\">5. Accounting you can actually bill from<\/h2>\n<p><code>radacct<\/code> gives you start time, stop time, input and output octets per session. Two practical notes:<\/p>\n<ul>\n<li>\u4f7f\u7528 <code>BIGINT<\/code> columns. 32-bit octet counters wrap at 4 GB and a single evening of streaming will corrupt an invoice.<\/li>\n<li>Reconcile against interface counters weekly. Sessions that end in a power cut close with a stale stop record; interim updates are what save you.<\/li>\n<\/ul>\n<h2 id=\"sizing-and-failure-modes\">Sizing and failure modes<\/h2>\n<table>\n<thead>\n<tr>\n<th>Symptom<\/th>\n<th>Usual cause<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Random session drops at the same time daily<\/td>\n<td>RADIUS timeout too tight, or DB backup locking <code>radacct<\/code><\/td>\n<\/tr>\n<tr>\n<td>Speeds ignore the plan<\/td>\n<td>Rate-limit direction reversed, or a static queue overriding the dynamic one<\/td>\n<\/tr>\n<tr>\n<td>Sessions stick after CPE reboot<\/td>\n<td>\u5426 <code>only-one=yes<\/code>; stale session holds the username<\/td>\n<\/tr>\n<tr>\n<td>CPU spikes on the BNG<\/td>\n<td>PPPoE encryption enabled unnecessarily, or too many interim updates<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>An RB5009 comfortably terminates a few hundred PPPoE sessions. Past roughly a thousand, move to a CCR-class BNG and split by area.<\/p>\n<h2 id=\"migrating-existing-dhcp-subscribers-without-a-truck-roll\">Migrating existing DHCP subscribers without a truck roll<\/h2>\n<p>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&#8217;s hands. The sequence that avoids a site visit:<\/p>\n<ol>\n<li><strong>Enable PPPoE server alongside DHCP<\/strong> on the same bridge &#8211; they coexist fine as long as the IP pools do not overlap.<\/li>\n<li><strong>Push PPPoE credentials remotely<\/strong> if the CPE supports TR-069\/ACS management, or via the CPE&#8217;s own cloud app (many consumer ONTs and routers support this) &#8211; this is the step that avoids sending a technician out.<\/li>\n<li><strong>Migrate in small batches per tower<\/strong>, 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.<\/li>\n<li><strong>Leave the DHCP pool running until the last batch confirms clean<\/strong>, then decommission it. Do not delete the DHCP server the same week as the first migration batch &#8211; it is your rollback path if PPPoE throughput or stability does not match expectations.<\/li>\n<\/ol>\n<h2 id=\"troubleshooting-commands-that-actually-tell-you-something\">Troubleshooting commands that actually tell you something<\/h2>\n<p>When a subscriber cannot connect, these four commands &#8211; in this order &#8211; find the layer that is actually broken faster than guessing:<\/p>\n<pre><code class=\"language-routeros\">\/ppp active print          ; is there even a session attempt reaching the BNG?\n\/radius monitor 0          ; is RouterOS sending Access-Request at all?\n\/log print where topics~\"radius\" ; what did RouterOS log about the RADIUS exchange?\n\/interface pppoe-server print stats ; auth failures vs. successful sessions, by interface\n<\/code><\/pre>\n<p>On the FreeRADIUS side, <code>radiusd -X<\/code> run in the foreground on a non-production instance shows the full attribute exchange for a single test login &#8211; the fastest way to see exactly which reply attribute is missing or malformed before it reaches RouterOS at all.<\/p>\n<h2 id=\"where-this-goes-next\">Where this goes next<\/h2>\n<h2 id=\"cpe-quirks-worth-knowing-before-the-first-batch\">CPE quirks worth knowing before the first batch<\/h2>\n<p>Not every router behind this setup behaves the same way, and three specific quirks account for most of the &#8220;it works for everyone except this one customer&#8221; tickets:<\/p>\n<ul>\n<li><strong>Some older ONTs cache the PPPoE session<\/strong> and will not re-authenticate cleanly after a RADIUS-triggered disconnect until the ONT itself is power-cycled &#8211; a soft reboot via the CPE&#8217;s own management page is usually enough, no truck roll required.<\/li>\n<li><strong>MTU mismatches show up as &#8220;the internet half-works.&#8221;<\/strong> PPPoE&#8217;s 8-byte overhead means a CPE still using 1500 MTU on its LAN side will fail on large packets &#8211; 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.<\/li>\n<li><strong>Dual-WAN or mesh CPE sometimes opens two PPPoE sessions<\/strong> from the same household during a failover test, which <code>one-session-per-host=yes<\/code> blocks correctly but then logs as a connection failure the customer reports as &#8220;my internet won&#8217;t connect&#8221; rather than &#8220;my internet failed over.&#8221; Check the PPPoE active list for a second half-open session before assuming a credentials problem.<\/li>\n<\/ul>\n<p>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 <a href=\"\/zh\/nexalink\/\">NexaLink<\/a> puts on top of this stack \u2014 the same FreeRADIUS schema, with an operator UI over it.<\/p>","protected":false},"excerpt":{"rendered":"<p>Build the subscriber authentication layer small ISPs actually run: PPPoE server on RouterOS, FreeRADIUS with SQL, per-plan rate limits, and usable accounting.<\/p>","protected":false},"author":1,"featured_media":6410,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAow6N_ODA:productID":"","_chatbot_visible":"","_zea_seo_title":"MikroTik PPPoE FreeRADIUS Setup: Production ISP AAA Guide","_zea_seo_description":"Deploy a production MikroTik PPPoE FreeRADIUS setup for ISP billing. Configure MySQL AAA, dynamic IP pools, CoA disconnect, and rate-limit profiles.","_zea_seo_focus_keyphrase":"MikroTik PPPoE FreeRADIUS setup","_zea_seo_canonical":"","_zea_seo_robots_noindex":false,"_zea_seo_robots_nofollow":false,"_zea_seo_sitemap_exclude":false,"_zea_seo_cornerstone":false,"_zea_seo_sitemap_priority":"","_zea_seo_og_title":"MikroTik PPPoE FreeRADIUS Setup: Production ISP AAA Guide","_zea_seo_og_description":"Real ISP authentication stack: configure MikroTik PPPoE with FreeRADIUS 3.x, MySQL dictionary attributes, interim accounting, and dynamic CoA disconnects.","_zea_seo_og_image":"https:\/\/zilleali.com\/wp-content\/uploads\/2026\/11\/card_service_freeradius.jpg","_zea_seo_twitter_title":"MikroTik PPPoE FreeRADIUS Setup: Production ISP AAA Guide","_zea_seo_twitter_description":"Real ISP authentication stack: configure MikroTik PPPoE with FreeRADIUS 3.x, MySQL dictionary attributes, interim accounting, and dynamic CoA disconnects.","_zea_seo_analysis_score":0,"_zea_ai_pending":false,"_zea_ai_notes":"","_zea_ai_keyword":"","footnotes":""},"categories":[12],"tags":[201,198,197,200,202],"class_list":["post-6137","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-networking","tag-freeradius","tag-isp","tag-mikrotik","tag-pppoe","tag-routeros"],"_links":{"self":[{"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/posts\/6137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/comments?post=6137"}],"version-history":[{"count":8,"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/posts\/6137\/revisions"}],"predecessor-version":[{"id":6381,"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/posts\/6137\/revisions\/6381"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/media\/6410"}],"wp:attachment":[{"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/media?parent=6137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/categories?post=6137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zilleali.com\/zh\/wp-json\/wp\/v2\/tags?post=6137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}