Start with a small guest network
On a guest network, knowing a shared Wi-Fi password should not give everyone unlimited usage. A captive portal associates access with individual accounts. This guide configures and tests quotas, speed limits and HTTPS login for a small guest or voucher network. Hotspot accounting does not replace a guest VLAN, Wi-Fi encryption or device authentication; this example controls only the IPv4 hotspot path.
Use RouterOS 7 with working WAN access on ether1. Reserve ether5 exclusively for a guest access point in bridge/AP mode, without its own NAT or DHCP. Management must stay on another interface. The example guest subnet is 10.20.30.0/24. Replace portal.example.com with a domain you control.
Use an IPv4 guest segment. Do not offer a parallel uncontrolled IPv6 path: RouterOS HotSpot does not provide equivalent IPv6 enforcement. Keep guests separate from staff and management networks, and enable client isolation on the AP where supported.
Choose the accounting authority
| Method | Quotas and administration | Accounting/recovery | Scale/complexity |
|---|---|---|---|
| Local HotSpot users | Per-user byte/uptime limits; profiles set rate ceilings; manual renewal | Counters on the router; reconcile after outages; not billing-grade by assumption | One small gateway; simplest dependency model |
| External RADIUS | Central identity/policy; attributes and backend implement plans/limits | Start/Interim/Stop records; HA, duplicate/missing records and fail policy need design | Several gateways; requires an operated accounting database and secure transport |
| MikroTik User Manager | RouterOS RADIUS application with profiles/limitations; separate supported package | Central User Manager database; back it up separately from a text export | Integrated vouchers/plans; capacity and sessions depend on host/license/version |
Prepare without losing management access
/export file=before-hotspot
/interface bridge port print
/ip address print
/ip route print
/system clock printDownload the export, then enter Safe Mode with Ctrl+X. Verify ether5 is free. If it is in the default LAN bridge, remove only that port in WinBox after confirming it is not your management connection. Do not remove the WAN or modify the existing LAN DHCP service. Check that the guest subnet is unused.
/interface bridge add name=br-hotspot protocol-mode=rstp
/interface bridge port add bridge=br-hotspot interface=ether5Run the HotSpot setup wizard
Open IP → Hotspot → Hotspot Setup in WinBox, or run the command below. Let this wizard create the guest IP, DHCP pool and server; do not create duplicate DHCP services beforehand.
/ip hotspot setuphotspot interface: br-hotspot
local address of network: 10.20.30.1/24
masquerade network: yes
address pool of network: 10.20.30.10-10.20.30.250
select certificate: none
ip address of smtp server: 0.0.0.0
dns servers: 1.1.1.1,8.8.8.8
dns name: portal.example.com
name of local hotspot user: setup-test
password for the user: <choose-a-unique-temporary-password>These are wizard answers, not a script to paste. The initial certificate choice is temporary; keep the guest SSID closed until HTTPS is ready. If a suitable source NAT rule already covers this subnet, answer no to masquerade instead of creating a duplicate. Use reachable organization-approved DNS resolvers.
/ip hotspot print detail
/ip hotspot profile print detail
/ip dhcp-server print
/ip firewall nat printThe remaining examples assume the wizard created hotspot1 and hsprof1. Substitute the actual names from the output. Firewall rules must permit guest DHCP, DNS to the intended resolver and the HotSpot services, while keeping router administration and internal subnets blocked. Review rule order against the existing firewall rather than disabling it.
Use the router resolver for the portal name: set the guest DHCP network dns-server to 10.20.30.1 after verifying that this exact network is the wizard-created guest entry. Set approved upstream resolvers in /ip dns and enable allow-remote-requests only after restricting input. The profile dns-name then resolves locally for guests; a public record pointing elsewhere will not override this guest design.
/ip dhcp-server network print detail
/ip dhcp-server network set [find where address="10.20.30.0/24"] dns-server=10.20.30.1
/ip dns set servers=1.1.1.1,8.8.8.8 allow-remote-requests=yes
/ip dns static printVerify the portal A record from a renewed guest lease. If changing the global upstream DNS would affect staff or VPN clients, retain the approved existing servers instead. Rollback restores the recorded DHCP DNS value and prior allow-remote-requests setting; do not remove another segment’s DNS configuration.
Make guest isolation an explicit policy
Apply this on the router after the wizard has created its dynamic HotSpot rules. Preserve those dynamic jumps and established/related handling. Place the guest forward drops before FastTrack and broad LAN permits; place the guest input rules after required HotSpot service handling but before broad router-management permits. Replace staff prefixes with every internal, VPN and management subnet; add any publicly addressed internal networks too.
/ip firewall address-list add list=guest-private address=10.0.0.0/8 comment="HS isolation"
/ip firewall address-list add list=guest-private address=172.16.0.0/12 comment="HS isolation"
/ip firewall address-list add list=guest-private address=192.168.0.0/16 comment="HS isolation"
/ip firewall filter add chain=forward action=drop in-interface=br-hotspot dst-address-list=guest-private comment="HS block internal"
/ip firewall filter add chain=forward action=drop in-interface=br-hotspot out-interface-list=!WAN comment="HS only WAN destinations"
/ip firewall filter add chain=forward action=accept in-interface=br-hotspot out-interface-list=WAN hotspot=auth comment="HS authenticated internet"
/ip firewall filter add chain=input action=accept in-interface=br-hotspot protocol=udp dst-port=67 comment="HS DHCP"
/ip firewall filter add chain=input action=accept in-interface=br-hotspot src-address=10.20.30.0/24 protocol=udp dst-port=53 comment="HS DNS UDP"
/ip firewall filter add chain=input action=accept in-interface=br-hotspot src-address=10.20.30.0/24 protocol=tcp dst-port=53 comment="HS DNS TCP"
/ip firewall filter add chain=input action=drop in-interface=br-hotspot comment="HS deny other router access"The wizard creates NAT/filter chains that redirect DNS and login traffic to local hotspot services. Preserve them and inspect their counters before the final drop; ordinary 53/443 permissions do not replace them. Direct guest-to-guest frames may bypass IP forward, so check AP client isolation and the bridge/hardware path separately. Close any uncontrolled IPv6 path at the guest boundary too.
Expected result: DHCP/portal work, authenticated clients reach only permitted internet destinations, and staff/management remain unreachable. Verification: test with an unauthenticated guest and an authenticated guest, including negative tests to a real staff host and WinBox. Failure analysis: inspect dynamic HotSpot chains and rule order instead of adding accept-all. Rollback: disable the new HS-commented rules in Safe Mode only while the guest SSID is closed.
Create dedicated speed profiles
Set speed in the user profile, which holds shared user settings, rather than the server profile, which controls the portal and authentication. The next example sets 2 Mbps upload and 8 Mbps download per account. Rate-limit is expressed from the router's perspective, so the first value is user upload and the second is user download.
/ip hotspot user profile add name=guest-8m rate-limit=2M/8M shared-users=1 session-timeout=8h idle-timeout=15m add-mac-cookie=no
/ip hotspot user profile add name=guest-20m rate-limit=5M/20M shared-users=1 add-mac-cookie=noThese are per-account speed ceilings, not guaranteed bandwidth. Eight megabits per second is roughly one megabyte per second before overhead. shared-users=1 allows one simultaneous login; it is not a permanent device binding. session-timeout ends a session and does not mean the account expires after eight calendar hours.
# Review the existing FastTrack match before editing it
/ip firewall filter print detail where action=fasttrack-connection
# Conservative guest exclusion before existing FastTrack, after isolation drops
/ip firewall filter add chain=forward action=accept connection-state=established,related in-interface=br-hotspot comment="HS established from guest"
/ip firewall filter add chain=forward action=accept connection-state=established,related out-interface=br-hotspot comment="HS established to guest"Place both established guest accepts before every FastTrack rule so those connections do not reach FastTrack. Keep the isolation drops earlier and leave the HotSpot dynamic unauthenticated checks in force. Existing fasttracked connections may need to expire; test a fresh session. Expected result: dynamic simple queues enforce upload/download ceilings. Verify /queue simple print stats during each direction. Rollback: disable these two exact rules after closing guest access, then restore the recorded FastTrack policy.
Assign a data allowance to each account
Create the account disabled, set its unique password in WinBox, and then enable it so credentials do not remain in a copied script. This example's 10737418240 bytes means 10 GiB of combined upload and download. Use 10000000000 for a decimal 10 GB allowance and state the unit clearly before handing it to users.
/ip hotspot user add name=guest01 server=hotspot1 profile=guest-8m limit-bytes-total=10737418240 disabled=yes comment="10 GiB guest allowance"
# Set a strong password in IP > Hotspot > Users, then:
/ip hotspot user enable [find where name="guest01"]The volume belongs to the user, while the shared speed settings belong to its profile. Reconnecting does not grant a new quota. A local byte limit is not a monthly billing plan and does not automatically reset at the start of the month. For recurring plans, expiry dates and dependable accounting, use a designed RADIUS/User Manager workflow and test its recovery behavior.
/ip hotspot user print stats where name="guest01"
/ip hotspot active print detail
/queue simple printWhen explicitly renewing this one account, disconnect its session first and reset its counters. This clears its accumulated traffic and uptime; record the usage beforehand if you need it. Do not reset every user just to renew one guest.
/ip hotspot active remove [find where user="guest01"]
/ip hotspot user reset-counters [find where name="guest01"]Purpose: attach an allowance to one account rather than the shared speed profile. Expected result: traffic increments its byte counters and access ends at its limit. Verification: use the 20 MiB test account in the acceptance section. Failure analysis: reusing accounts or resetting counters hides real consumption. Rollback: restore the recorded limit and disable the account; reset-counters cannot reconstruct lost usage records.
Enable trusted HTTPS for the portal
What is commonly called SSL here is TLS. Obtain a certificate for your real portal hostname from a CA trusted by client devices. DNS-01 validation on a separate certificate-management host is useful when the router is not publicly reachable; it requires control of the public DNS zone. A self-signed certificate will still warn unmanaged guests.
Import the certificate, its private key and required intermediate chain through System → Certificates → Import in WinBox. An encrypted PKCS#12 bundle can carry the key and certificate. Enter its passphrase in the dialog. Identify the leaf certificate with the private-key K flag and rename it hotspot-tls. Check its SAN hostname, expiry and the router clock.
/certificate print detail
/ip hotspot profile set [find where name="hsprof1"] dns-name=portal.example.com ssl-certificate=hotspot-tls login-by=https https-redirect=noThe guest must resolve the portal hostname to 10.20.30.1. The wizard/profile DNS name creates a router DNS entry, but that only helps clients actually using that resolver. Check the DHCP network DNS setting; if using the router as DNS, enable remote requests only with firewall restrictions to trusted client segments, never an open WAN resolver.
Open https://portal.example.com/login directly and check for a valid certificate before releasing the SSID. HTTPS login protects credentials; it does not allow transparent interception of unrelated HTTPS sites. With https-redirect=no, use captive-portal detection, the direct portal URL or a plain HTTP page to start login. Plan renewal before expiry, import the replacement and reselect its certificate.
Purpose: Protect credentials with the portal hostname certificate.
Expected result: Guest login has a valid SAN/chain and a working private key.
Verification: Open the exact HTTPS login on a real guest after renewing DHCP DNS.
Failure analysis: Check guest DNS, router time, key K flag and intermediate certificates.
Rollback: Close the guest SSID; restore the prior valid certificate/profile configuration.
Build a custom login page
Download the entire generated hotspot folder first. Duplicate it as hotspot-custom, retaining status, logout, redirect and api.json files. Replace only login.html with the downloadable example. Keep assets local so the page works before internet access. On devices with flash storage, use the persistent flash/hotspot-custom path; otherwise use the actual persistent path shown in Files.
<!doctype html>
<html lang="fa" dir="rtl">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>ورود به اینترنت مهمان</title>
<style>
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
background: #101b30;
color: #eef5ff;
font:
16px Tahoma,
sans-serif;
}
main {
width: min(340px, 82vw);
padding: 28px;
background: #1b2b46;
border-radius: 20px;
}
label {
display: block;
margin-top: 18px;
}
input,
button {
box-sizing: border-box;
width: 100%;
padding: 12px;
margin-top: 8px;
border-radius: 8px;
border: 1px solid #8ca4c7;
}
button {
background: #76d6d0;
color: #102337;
cursor: pointer;
}
.error {
color: #ffbaba;
}
p {
line-height: 1.9;
}
</style>
</head>
<body>
<main>
<h1>اینترنت مهمان</h1>
<p>نام کاربری و رمزی را که دریافت کردهاید وارد کنید.</p>
$(if error)
<p class="error" role="alert">
ورود انجام نشد؛ اطلاعات حساب یا اعتبار آن را بررسی کنید.
</p>
$(endif) $(if ssl-login == 'yes')
<form action="https://portal.example.com/login" method="post">
<label for="username">نام کاربری</label
><input
id="username"
name="username"
autocomplete="username"
dir="ltr"
required
/>
<label for="password">رمز عبور</label
><input
id="password"
type="password"
name="password"
autocomplete="current-password"
dir="ltr"
required
/>
<input type="hidden" name="popup" value="false" /><button type="submit">
اتصال به اینترنت
</button>
</form>
$(else)
<p>
<a style="color: #76d6d0" href="https://portal.example.com/login"
>باز کردن صفحه ورود امن</a
>
</p>
$(endif)
<p>حجم و سرعت اینترنت طبق حساب شما محاسبه میشود.</p>
</main>
</body>
</html>Replace both portal.example.com URLs in this file. The password form is shown only on an HTTPS page and submits to the fixed HTTPS hostname. This example is for login-by=https; it does not implement the CHAP JavaScript flow. It deliberately avoids inserting raw error or username values into HTML. Keep the default landing/status flow and test on a real router.
/ip hotspot profile set [find where name="hsprof1"] html-directory=flash/hotspot-customAdjust the path to your device. If discovery fails after replacing an old template, compare api.json with the current RouterOS default. Do not add broad walled-garden exceptions just to load remote fonts or trackers. The downloadable login page uses no external dependencies.
Download the custom login.html
Purpose: Replace only the login form while retaining RouterOS status/discovery files.
Expected result: Local assets load before authentication and the form posts only over HTTPS.
Verification: Test success, bad password, logout and Android/iOS captive windows.
Failure analysis: Check persistent folder path, portal hostname and current api.json.
Rollback: Set html-directory back to the recorded original folder without disabling TLS.
When quotas need a central ledger
For multiple gateways, create the NAS client and its secret on the RADIUS server first. The address below is documentation-only; replace it with a reachable private RADIUS address and enter the same strong secret through WinBox. Carry UDP accounting/authentication over a protected management network/VPN, or use a supported RadSec design. Do not send PAP credentials over an untrusted path.
/radius add service=hotspot address=192.0.2.50 authentication-port=1812 accounting-port=1813 disabled=yes comment="HS central AAA"
# Set the matching secret privately in WinBox, then enable this entry
/radius enable [find where comment="HS central AAA"]
/ip hotspot profile set [find where name=hsprof1] use-radius=yes radius-accounting=yes radius-interim-update=5m
/radius printExpected result: a dedicated RADIUS-only test username authenticates and the backend receives Start, Interim and Stop records. A matching local username can take precedence, so do not use guest01 for this test. Inspect RADIUS counters and backend logs without exposing the shared secret. Before cutover, define rate and quota attributes, stale-session reconciliation and denial behavior during a RADIUS outage. To roll back, restore the previous use-radius and accounting settings, disable the named entry and retain a controlled local emergency account.
Test the limits before handing it over
Accept the setup using a real guest phone: verify its guest IP, warning-free portal certificate and blocked internal access. After login, inspect the active session and dynamic queue and measure upload/download separately. If limits fail, inspect FastTrack, which bypasses simple queues and hotspot processing. Exclude guest traffic in both directions and retest with fresh connections.
For a quota test, create a separate test account with limit-bytes-total=20971520 (20 MiB) and download enough data to exhaust it. Confirm disconnection and failed re-login until renewed. Test a second simultaneous device, logout, a router reboot and both Android/iOS captive windows. Do not assume counters provide billing-grade persistence across abrupt power loss.
After successful testing, disable setup-test and remove unused test accounts. If the custom page fails, point html-directory back to the original saved folder while preserving HTTPS. Before handover, test these commands and the template on the target RouterOS release with actual guest devices.
Recover the portal without erasing guest records
Keep the original HotSpot folder, the complete custom folder, a private certificate/key backup, user/profile records and an encrypted router backup off-device. User Manager has its own database backup requirement. Record certificate expiry and test renewal on a guest device. Never renew a data plan through a global counter reset; preserve accounting evidence first.
/ip hotspot disable [find where name=hotspot1]
/ip hotspot user disable [find where name=guest01]
# Restore the recorded original folder; do not guess its flash path
/ip hotspot profile print detail
/export file=after-hotspot-reviewIf the custom form fails, restore the original recorded html-directory while retaining the valid TLS profile. For a full rollback, close the guest SSID, disable hotspot1 and remove only its guest bridge, DHCP, NAT and filter objects after comparing them with the saved export. Confirm staff routing still works, the guest network stays closed until rebuilt, and the router DNS service remains inaccessible from the public network.
Questions from deployment reviews
Is session-timeout an account expiry date?
No. It limits one session. Recurring validity/renewal belongs to the account plan and its accounting authority.
Why not redirect every HTTPS website to login?
The router cannot present a valid certificate for unrelated websites. Use the trusted portal hostname, captive detection and a plain HTTP entry path.
Official references
HotSpot setup, profiles and limits
HotSpot page variables and customization
Certificate import and private keys