Scenario: the switch ports run 802.1X, but printers, IP phones and cameras cannot do 802.1X. When the switch gets no EAP, it asks with the device’s MAC address as the user name instead (MAC Authentication Bypass). Known devices go into their VLAN; unknown ones are rejected, and the switch puts them into a guest or quarantine VLAN.
Example directory: rradius-server/examples/scenarios/wired-mab/
| File | Contents |
|---|---|
rradius.toml | Configuration file: no [auth], everything goes to the script |
migrations/1_schema.sql | mac_devices (MAC, VLAN, note) |
migrations/2_demo_data.sql | One printer (VLAN 30), one IP phone (VLAN 40) |
The script is the repository’s examples/mac-auth.lua, which the configuration points to directly.
Steps
1. Change the client and start
The example client is the whole switch management range 10.40.0.0/24. For local testing, change it to 127.0.0.1:
cd rradius-server
./target/release/rradius-server --config examples/scenarios/wired-mab/rradius.toml
2. Simulate the switch’s request
A switch’s MAB request puts the MAC address in User-Name, User-Password and Calling-Station-Id, written differently by each vendor:
echo 'User-Name=00-11-22-AA-BB-CC,User-Password=00-11-22-AA-BB-CC,Calling-Station-Id=00-11-22-AA-BB-CC' \
| radclient 127.0.0.1:1812 auth switches-shared-secret-change-me
You get an Access-Accept with the three VLAN 30 attributes (Tunnel-Type = VLAN, Tunnel-Medium-Type = IEEE-802, Tunnel-Private-Group-Id = 30).
User-Name | Calling-Station-Id | Result |
|---|---|---|
00-11-22-AA-BB-CC | 00-11-22-AA-BB-CC | Accept, VLAN 30 |
00a0.c912.3456 (Cisco style) | 00:a0:c9:12:34:56 | Accept, VLAN 40 |
001122aabbcc | 00:00:00:00:00:01 | Reject: the name differs from the actual device |
00ffffffffff | 00:ff:ff:ff:ff:ff | Reject: unknown |
What the script does
- Normalises MAC addresses: removes
-,:and., lowercases, and requires exactly 12 hexadecimal characters. So the table stores001122aabbcchowever the switch writes it. User-NameandCalling-Station-Idmust be the same MAC. The name is what the device says;Calling-Station-Idis what the switch sees. If they differ, the login is rejected.- Does not check the password. MAB has no secret to compare; it relies on the address alone.
- Handles only RADIUS authentication. Accounting is always answered, and TACACS+ is always rejected.
Limits of this approach
- A MAC address is not a secret. Anyone who can see the device’s label or the cable can impersonate it. Put these devices in VLANs that reach only the services they need (printers only the print server, phones only the SIP server), never into a general network.
- What happens to unknown devices after the reject is the switch’s failure handling (a guest VLAN, or staying quarantined, for example). That is switch configuration, not rradius.
- To put unknown devices straight into a guest VLAN, change the script to return
acceptwith the guest VLAN when nothing is found. That means anyone who plugs in a cable gets online, so check what the guest VLAN can reach first.
Together with 802.1X on the same switch
When a port tries 802.1X first and falls back to MAB, both kinds of request come from the same client. To handle that:
- Keep EAP and MAB apart: add
[radius.eap](chapter 3) and a chain for ordinary accounts, withmac-auth.luaas aluahandler after it. The comment at the top ofmac-auth.luaexplains the order: the handler that checks passwords judges the name first, and the MAC is looked at only when that handler does not know it. - In a PEAP chain, an
acceptfrom aluahandler does not count; some handler must actually have checked a password, so the MAB rule never lets PEAP through without one.
Adding devices
For now, devices are added with a new migration file, for example 3_add_cameras.sql:
INSERT INTO mac_devices (mac, vlan, note) VALUES ('0011223344aa', '50', 'front door camera');
Put it in migrations/ and restart. For many devices that change often, see chapter 19.