Layer 2 Security · Topic 6 of 7
BPDU Guard and Port Security
Protect access ports with BPDU guard and edge ports, and control which MAC addresses may use a port with learning limits, static entries and flooding.
- 5 min
- An edge port faces end devices, and should never receive a BPDU.
bpdu-guard=yesshuts a port that receives a BPDU.restricted-role=yeskeeps the port from becoming a root port, but leaves it up.
What it is
BPDU guard stops unwanted switches from joining the tree, and port security controls which devices may use a port.
Both protect the access edge, where untrusted people plug in cables. They answer two different questions. BPDU guard asks whether a switch is attached, and port security asks which host is attached.
Use them together on every port that faces users.
How it works
BPDU guard reacts to a message, and port security restricts addresses.
BPDU guard
An edge port should only ever face an end device, so it should never receive a BPDU.
/interface bridge port set [find interface=ether5] edge=yes bpdu-guard=yes
If a BPDU arrives on such a port, a switch must be attached. The bridge protects itself by shutting the port. An administrator then looks for the cause and brings the port back by hand.
This prevents a rogue or misconfigured switch from changing the root, and from creating a loop behind the port.
BPDU guard compared with related options
| Option | What it does | Port stays up |
|---|---|---|
edge=yes | Forwards at once, assumes an end device | Yes |
restricted-role=yes | Port cannot become a root port | Yes |
bpdu-guard=yes | Shuts the port on BPDU arrival | No |
Choose bpdu-guard on ports where no switch should ever appear. Use restricted-role where a switch may be legitimate, but must never become the root.
Combine edge=yes and bpdu-guard=yes on every port that faces an ordinary host.
Port security goals
Port security limits which MAC addresses may use a port.
The aims are to stop a user from plugging in a hub with many hosts, to stop address spoofing, and to keep unknown devices off the network. It does not replace authentication, because a MAC address can be copied.
Controlling MAC learning
The simplest control is to limit how addresses are learned.
- Static entries: list the allowed MAC address and its port in the host table of the switch chip.
- Learning limit: cap the number of addresses a port may learn, where the chip supports it.
- Learning off: stop the port from learning addresses, so only static entries work.
/interface ethernet switch host add mac-address=00:11:22:33:44:55 ports=ether2
/interface bridge port set [find interface=ether2] learn=no
The first line creates a static host entry in the switch host table. The second stops the bridge port from learning dynamic addresses, on RouterOS versions that have the setting. Without learning, the bridge does not know where hosts are, so it floods frames for them unless you limit flooding.
Limiting unknown traffic
Turn off flooding of unknown unicast on a locked port.
/interface bridge port set [find interface=ether2] unknown-unicast-flood=no
Now frames for unknown destinations are not sent out of the port.
Port security with switch rules
Switch rules can drop frames that enter a port with a given source MAC address.
The rule runs in the chip at wire speed, and it uses an empty new-dst-ports, as the previous page shows. Each rule covers one case, so this suits blocking a few known bad addresses. A full list of allowed hosts is better done with static host entries and learning off.
Where it fits
Port security suits fixed devices, such as cameras, printers and phones.
For laptops and mobile devices, 802.1X is a better fit, because it authenticates the user or device and not only the address. The next page covers it.
Checking
/interface bridge host print
/interface ethernet switch host print
Look for the addresses learned on each port, and confirm that unknown addresses do not appear on locked ports.
What to remember for the exam
Seven facts cover most questions on this topic.
- An edge port faces end devices, and should never receive a BPDU.
bpdu-guard=yesshuts a port that receives a BPDU.restricted-role=yeskeeps the port from becoming a root port, but leaves it up.- Port security limits which MAC addresses may use a port.
- Static host entries, learning limits and learning off are the main tools.
- Without learning, restrict flooding of unknown unicast on the port.
- A MAC address can be copied, so port security is weaker than 802.1X.
A port with learning off and unknown unicast flooding off, and with no static entries, leaves the bridge unable to deliver frames to any host behind it.
Common mistakes
These four mistakes appear often.
Using BPDU guard on legitimate switch links. The uplink shuts down when the neighbour sends a BPDU.
Turning learning off without static entries. Frames for those hosts are flooded, and if flooding is also limited no host can communicate.
Trusting MAC addresses as identity. Anyone can clone an address.
Forgetting to restore a guarded port. The port stays down until someone enables it again.
Check yourself
Work through these three questions.
What does BPDU guard do?
It shuts down a port that receives a BPDU, because a switch should not be attached to an edge port.
How does
restricted-rolediffer frombpdu-guard?restricted-rolekeeps the port from becoming a root port and leaves it up, whilebpdu-guardshuts the port.Why is port security weaker than 802.1X?
A MAC address can be copied, while 802.1X authenticates with credentials.
Topic 6 of 7 in Layer 2 Security
Test yourself on Layer 2 Security
The full MikroTik MTCSWE question bank has 484 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by MikroTik. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.