Layer 2 Security · Topic 4 of 4
Layer 2 Firewall Filters
Learn Junos Layer 2 firewall filters: port, VLAN and router filter types, processing order, match criteria, actions and how to apply and verify them.
- 6 min
- Layer 2 filters use
family ethernet-switchingunder[edit firewall]. - Types: port filter (interface unit), VLAN filter (
vlans NAME forwarding-options filter), router filter (ineton an IRB). - Input order: port, VLAN, router. Output order: router, VLAN, port.
What it is
A Layer 2 firewall filter is a stateless filter that examines frames as they pass through a switch. It can match on MAC addresses, the Ethernet type and VLAN, and also on IP header fields. It can accept, discard, count, log, rate limit or mirror them.
Layer 2 filters use the protocol family ethernet-switching. They work like the filters you know from routing, with terms, from and then, but they apply to bridged traffic on switch ports and VLANs.
How it works
Filter types by where they are applied
The same filter body can be attached at three places, and each place gives a different filter type.
| Type | Applied to | Family | Acts on |
|---|---|---|---|
| Port filter | A switching port, on the logical unit | ethernet-switching | Frames entering or leaving that port |
| VLAN filter | A VLAN | ethernet-switching | All frames in that VLAN, from any port |
| Router filter | A routed interface, such as an IRB | inet | Routed (Layer 3) packets |
A port filter is the most specific. A VLAN filter covers every port in the VLAN with one attachment, so it suits rules for a whole VLAN. A router filter acts on traffic that is routed between VLANs through an IRB.
Processing order
When a frame meets more than one kind of filter, the switch applies them in a fixed order.
| Direction | Order |
|---|---|
| Input (ingress) | Port filter, then VLAN filter, then router filter |
| Output (egress) | Router filter, then VLAN filter, then port filter |
A frame that is only bridged does not meet the router filter. A discard in an earlier filter ends processing, so the later filters never see that frame.
Match criteria
Common match conditions in the ethernet-switching family are:
| Condition | Matches |
|---|---|
source-mac-address, destination-mac-address | Frame MAC addresses; a prefix or full address |
ether-type | The Ethernet type field, such as arp or ipv4 |
vlan | The VLAN of the frame |
ip-source-address, ip-destination-address | IP addresses inside IP frames |
ip-protocol | IP protocol, such as tcp, udp or icmp |
source-port, destination-port | TCP or UDP ports |
dscp | The DSCP value inside IP frames |
As with other Junos filters, different conditions in one term are combined with AND, and several values of one condition are combined with OR. A term with no from matches every frame.
Actions
| Kind | Action | Effect |
|---|---|---|
| Terminating | accept | Let the frame through |
| Terminating | discard | Drop the frame silently |
| Flow control | next term | Continue with the next term |
| Modifier | count | Add to a named counter |
| Modifier | log, syslog | Record frame details |
| Modifier | policer | Apply a rate limit |
| Modifier | forwarding-class, loss-priority | Set class of service handling |
If a term has only modifier actions, such as count, the frame is accepted. A frame that matches no term meets the implicit discard at the end of the filter.
Configuration and application
First define the filter, then apply it.
user@switch# set firewall family ethernet-switching filter BLOCK-HOST term T1 from source-mac-address 00:50:56:aa:bb:01/48
user@switch# set firewall family ethernet-switching filter BLOCK-HOST term T1 then count BLOCKED
user@switch# set firewall family ethernet-switching filter BLOCK-HOST term T1 then discard
user@switch# set firewall family ethernet-switching filter BLOCK-HOST term T2 then accept
Term T2 has no from and so accepts everything the first term did not match. Without it, the implicit discard would drop all other frames.
Apply it as a port filter, or as a VLAN filter, as input.
user@switch# set interfaces ge-0/0/1 unit 0 family ethernet-switching filter input BLOCK-HOST
user@switch# set vlans SALES forwarding-options filter input BLOCK-HOST
A router filter is a filter in the inet family applied to an IRB unit.
user@switch# set interfaces irb unit 10 family inet filter input ROUTED-RULES
The port filter statement sits on the logical unit under family ethernet-switching. The VLAN filter sits under forwarding-options of the VLAN. Both can also be applied as output.
Monitoring and troubleshooting
user@switch> show firewall
user@switch> show firewall filter BLOCK-HOST
user@switch> show configuration firewall family ethernet-switching
show firewall lists the counters of every filter. A counter that stays at zero means no frame matched that term, so check the match condition and the point of application.
Add a count action to the final term, or add a final counting discard term. When users report a blocked service, the counter shows at once whether the filter is dropping the traffic.
A filter ends with an implicit discard. A port filter that only blocks one MAC address and has no final accept term drops every other frame on the port, including ARP.
Common mistakes
Forgetting the final accept term. Frames not matched by any term are discarded.
Defining a filter and not applying it. A filter does nothing until it is attached to a port or VLAN.
Using the wrong family. Bridged traffic needs ethernet-switching. An inet filter on a switching port does not apply to bridged frames.
Mixing up the order. Input goes port, VLAN, router. Output goes router, VLAN, port.
Expecting stateful behavior. Filters are stateless, so return traffic needs its own term.
What to remember for the exam
- Layer 2 filters use
family ethernet-switchingunder[edit firewall]. - Types: port filter (interface unit), VLAN filter (
vlans NAME forwarding-options filter), router filter (ineton an IRB). - Input order: port, VLAN, router. Output order: router, VLAN, port.
- Match on MAC addresses, ether type, VLAN, IP addresses, IP protocol and ports.
- Terms run top to bottom, the first match wins, and every filter ends with an implicit discard.
- Modifier actions such as
countalone accept the frame. show firewallshows counters.
Check yourself
In which order do an ingress port filter, VLAN filter and router filter apply?
Port filter first, then the VLAN filter, then the router filter.
A filter has one term that discards a single source MAC address and no other term. What happens to all other frames?
They are discarded by the implicit discard at the end of the filter.
How do you apply an
ethernet-switchingfilter to every port in a VLAN with one statement?Attach it as a VLAN filter with
set vlans NAME forwarding-options filter input FILTER-NAME.
Topic 4 of 4 in Layer 2 Security
Test yourself on Layer 2 Security
The full Juniper JNCIS-ENT JN0-352 question bank has 846 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 Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.