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
In a nutshell
  • Layer 2 filters use family ethernet-switching under [edit firewall].
  • Types: port filter (interface unit), VLAN filter (vlans NAME forwarding-options filter), router filter (inet on 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.

FrameTerm 1from matchmatchTerm 1then actionTerm 1from matchno matchTerm 2no matchImplicit discard

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.

TypeApplied toFamilyActs on
Port filterA switching port, on the logical unitethernet-switchingFrames entering or leaving that port
VLAN filterA VLANethernet-switchingAll frames in that VLAN, from any port
Router filterA routed interface, such as an IRBinetRouted (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.

DirectionOrder
Input (ingress)Port filter, then VLAN filter, then router filter
Output (egress)Router filter, then VLAN filter, then port filter
Frame entersingress portPort filterVLAN filterRouter filterrouted traffic onlyRouted packet leavesRouter filterVLAN filterPort filteregress port

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:

ConditionMatches
source-mac-address, destination-mac-addressFrame MAC addresses; a prefix or full address
ether-typeThe Ethernet type field, such as arp or ipv4
vlanThe VLAN of the frame
ip-source-address, ip-destination-addressIP addresses inside IP frames
ip-protocolIP protocol, such as tcp, udp or icmp
source-port, destination-portTCP or UDP ports
dscpThe 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

KindActionEffect
TerminatingacceptLet the frame through
TerminatingdiscardDrop the frame silently
Flow controlnext termContinue with the next term
ModifiercountAdd to a named counter
Modifierlog, syslogRecord frame details
ModifierpolicerApply a rate limit
Modifierforwarding-class, loss-prioritySet 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.

Define filterfirewall family ethernet switchingApply as port filterinterface unitCommitVerifyshow firewallDefine filterfirewall family ethernet switchingApply as VLAN filtervlan forwarding optionsCommitVerifyshow firewall

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.

Exam tip

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.

Watch out

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-switching under [edit firewall].
  • Types: port filter (interface unit), VLAN filter (vlans NAME forwarding-options filter), router filter (inet on 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 count alone accept the frame.
  • show firewall shows 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-switching filter 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.