7.3 Firewall Filters & Policers
Key Takeaways
Junos stateless firewall filters operate directly in the Packet Forwarding Engine (PFE) hardware ASICs at line rate on incoming or outgoing interface traffic.
Stateless firewall filters consist of terms containing match conditions and actions; unlike stateful firewalls, every Junos filter terminates with an implicit discard action.
Filter actions are categorized into terminating actions ('accept', 'discard', 'reject') and non-terminating action modifiers ('count', 'log', 'syslog', 'policer').
Traffic policers enforce rate limits using token bucket algorithms, dropping or marking out-of-profile packets without delaying them in buffer queues.
Applying a protective firewall filter to the loopback interface ('lo0.0') on ingress secures the Routing Engine control and management plane from unauthorized access and denial-of-service floods without impacting transit traffic.
Firewall Filters & Policers
While routing policies control the exchange of routing information in the control plane, Firewall Filters inspect and control actual data packets traversing the router or destined to the local host. In Junos OS, firewall filters are stateless access control lists (ACLs) processed directly in the Packet Forwarding Engine (PFE) hardware ASICs at wire speed. Combined with Traffic Policers, firewall filters defend network infrastructure against denial-of-service (DoS) attacks, enforce quality of service (QoS) boundaries, and protect the Routing Engine (RE). Mastering firewall filter mechanics, action modifiers, and loopback filtering is critical for enterprise network security and the JNCIS-ENT examination.
1. Stateless Firewall Filter Architecture in Junos OS
Unlike stateful firewalls (such as the Juniper SRX Series running flow-based processing) that maintain dynamic session state tables for TCP and UDP flows, Junos stateless firewall filters evaluate each packet independently. Every packet is inspected against configured criteria without awareness of preceding or subsequent packets in the stream.
+---------------------------------------------------------------------------------------------------+
| JUNOS STATELESS HARDWARE PACKET FILTERING (PFE) |
+---------------------------------------------------------------------------------------------------+
| |
| Ingress Packet ===> [ PFE Hardware Parser ] ===> [ Ingress Firewall Filter ] ===> Lookup/FIB |
| | (Term Match & Actions) |
| v |
| Accept / Count / Policer / Drop |
| |
| Egress Packet <=== [ Physical Interface ] <=== [ Egress Firewall Filter ] <=== Switching/QoS |
| |
+---------------------------------------------------------------------------------------------------+
Directionality and Interface Application
Firewall filters are configured under the [edit firewall family inet filter <filter-name>] hierarchy for IPv4, or family inet6 for IPv6, and applied to logical interfaces (unit):
[edit interfaces ge-0/0/0 unit 0 family inet]
set filter input transit-in
set filter output transit-out
input: Evaluates packets arriving on the interface before the PFE performs route lookup.output: Evaluates packets after forwarding lookup and egress interface selection, immediately prior to frame transmission.
2. Filter Structure & Match Conditions
A Junos firewall filter is composed of ordered terms. Each term contains from match statements and then action statements:
[edit firewall family inet filter secure-edge]
term allow-web {
from {
source-address 192.168.1.0/24;
destination-port [ 80 443 ];
protocol tcp;
}
then {
count web-counter;
accept;
}
}
Primary Match Conditions
- Layer 3 Addresses:
source-address,destination-address,source-prefix-list,destination-prefix-list. - Layer 4 Protocols:
protocol tcp,protocol udp,protocol icmp,protocol ospf,protocol igmp. - Port Numbers:
source-port,destination-port, orport(matches either source or destination). Ports can be specified by number (22), symbolic name (ssh,bgp,ntp), lists ([ 80 443 8080 ]), or ranges (1024-65535). - TCP Flags:
tcp-flags "syn & !ack"(matches TCP connection initiation packets) ortcp-established(matches ACK or RST flags; it does not verify connection state). - ICMP Criteria:
icmp-type echo-request,icmp-type echo-reply,icmp-type destination-unreachable,icmp-code. - QoS / CoS Markings:
dscp,traffic-class,precedence.
3. Action Processing: Terminating vs. Action Modifiers
Actions inside a firewall filter term are divided into terminating actions and non-terminating action modifiers.
Terminating Actions
A terminating action determines the final forwarding disposition of the packet and stops further term evaluation:
| Action | Forwarding Behavior | ICMP Response Generated? |
|---|---|---|
accept | Transmits the packet to the next stage of the PFE pipeline. | No |
discard | Silently drops the packet in hardware without notifying the sender. | No (Stealth drop) |
reject | Drops the packet and returns an ICMP error message to the sender. | Yes (ICMP Unreachable or TCP Reset) |
When reject is configured, Junos can optionally return specific rejection codes:
reject: Defaults to ICMP destination unreachable (host unreachable).reject tcp-reset: Returns a TCP RST packet for TCP connections, cleanly tearing down client sockets.reject icmp-admin-prohibited: Returns ICMP type 3 code 13 (administratively prohibited).
Non-Terminating Actions (Action Modifiers)
Action modifiers add counting, logging, policing or marking. A matching term with only nonterminating actions has an implicit accept; it does not automatically continue into the next term. Use a supported explicit next term when continuation is intended. Unmatched packets reaching the end of the whole filter encounter implicit discard:
count <counter-name>: Increments a hardware packet and byte counter. Counters are inspected operationally viashow firewall counter filter <filter> <counter>.log: Captures packet header metadata into a local buffer on the PFE, viewed withshow firewall log.syslog: Transmits an alert to the system log daemon (syslogd).policer <policer-name>: Subjects matched traffic to a bandwidth and burst-size rate limiter.loss-priority (low | medium-low | medium-high | high): Sets packet drop precedence for CoS schedulers.forwarding-class <class-name>: Directs the packet into a designated egress queue (e.g.,expedited-forwarding).
The Implicit Discard Rule
Critical Junos Firewall Rule: Every stateless firewall filter concludes with an implicit discard! If a packet does not match any configured term, Junos drops the packet silently. If an administrator creates a filter matching only SSH traffic with
then acceptand applies it to an interface, all other traffic (HTTP, DNS, OSPF, ICMP) will be dropped! To permit non-matching transit traffic, an explicit final term must be added:
[edit firewall family inet filter filter-name]
set term permit-all then accept
4. Traffic Policing: Token Bucket Rate Limiting
While firewall filters permit or deny packets based on header fields, Policers enforce bandwidth limits. A policer monitors traffic volume using a token bucket algorithm:
[edit firewall policer <policer-name>]
set if-exceeding bandwidth-limit <bps> burst-size-limit <bytes>
set then <action>
Single-Rate Two-Color Policer
A two-color policer classifies traffic into two states:
- Conforming (Green / In-Profile): Traffic within the bandwidth and burst limits is forwarded normally.
- Non-Conforming (Red / Out-of-Profile): Traffic exceeding the limits triggers the configured action (
discardorloss-priority high).
[edit firewall policer limit-icmp]
set if-exceeding bandwidth-limit 1m burst-size-limit 62k
set then discard
Burst Size Formula: Configuring an adequate
burst-size-limitis crucial to prevent premature packet drops during normal TCP window bursts. Juniper recommends sizing the burst bucket to accommodate at least 5 milliseconds of traffic at the burst rate:Burst Size (Bytes) = (Bandwidth Limit (bps) * 0.005 seconds) / 8
Two-Rate Three-Color Policer (trTCM / RFC 2698)
For advanced QoS, Junos supports two-rate three-color marking (trTCM) policers configured with:
- CIR (Committed Information Rate) & CBS (Committed Burst Size)
- PIR (Peak Information Rate) & PBS (Peak Burst Size)
Packets are metered into three colors: Green (conforming to CIR), Yellow (exceeding CIR but conforming to PIR), and Red (exceeding PIR, dropped or marked with high loss priority).
Policing vs. Shaping
| Feature | Traffic Policing | Traffic Shaping |
|---|---|---|
| Mechanism | Drops or remarks excess packets immediately. | Buffers excess packets in queues and transmits them smoothly. |
| Buffering | No buffering. Does not introduce delay or jitter. | Requires memory buffers. Introduces transmission delay. |
| Direction | Supported on both ingress and egress. | Supported exclusively on egress. |
| Implementation | Firewall filter action modifier or interface policer. | Class of Service (CoS) queue scheduler. |
5. Securing the Routing Engine: Loopback Protection (lo0.0)
In Junos architecture, transit traffic flows directly through the PFE switching fabric from ingress port to egress port and never impacts the Routing Engine. However, exception traffic (packets addressed directly to the router's own IP addresses, routing protocol sessions, and management connections) must be punted across the internal bus to the Routing Engine processor.
If malicious or misconfigured hosts flood the router with packets, the RE's CPU can be overwhelmed, leading to dropped OSPF/BGP keepalives, routing instability, and loss of management access. To protect the RE, enterprise administrators apply a stateless firewall filter to the loopback interface (lo0.0).
The Loopback Architecture Principle: Applying a filter to
lo0.0on ingress (input) filters all traffic destined to the local Routing Engine, regardless of which physical interface received the packet. Transit traffic flowing through the chassis is completely unaffected by thelo0.0filter!
IPv4 protect-re Teaching Example
[edit policy-options]
set prefix-list mgmt-stations 10.200.1.0/24
set prefix-list bgp-neighbors 192.168.12.2/32
[edit firewall policer icmp-policer]
set if-exceeding bandwidth-limit 1m burst-size-limit 62k
set then discard
[edit firewall family inet filter protect-re]
term permit-established-tcp {
from {
protocol tcp;
tcp-established;
}
then accept;
}
term permit-mgmt-ssh {
from {
source-prefix-list mgmt-stations;
destination-port 22;
protocol tcp;
}
then {
count ssh-mgmt-count;
accept;
}
}
term permit-bgp {
from {
source-prefix-list bgp-neighbors;
destination-port 179;
protocol tcp;
}
then accept;
}
term permit-ospf {
from {
protocol ospf;
}
then accept;
}
term rate-limit-icmp {
from {
protocol icmp;
icmp-type [ echo-request echo-reply ];
}
then {
policer icmp-policer;
count icmp-count;
accept;
}
}
term discard-all-other {
then {
count re-violation-count;
discard;
}
}
[edit interfaces lo0 unit 0 family inet]
set filter input protect-re
Operational Verification Commands
user@router> show firewall filter protect-re
user@router> show firewall counter filter protect-re ssh-mgmt-count
user@router> show firewall counter filter protect-re re-violation-count
user@router> clear firewall filter protect-re counter re-violation-count
user@router> show firewall log
Output note: Command output shown here is a schematic teaching example, not a captured device session. Field names and feature support depend on platform and Junos release.
This IPv4 example is deliberately limited. tcp-established only checks flags and can be spoofed; it is not a stateful security boundary. Before applying any RE filter, add the required management services, diagnostic ICMP errors, routing protocols, BFD and return traffic for that device. Protect IPv6 separately with family inet6. Test the policy and use a confirmed commit to avoid management lockout.
An administrator configures a stateless firewall filter to permit web traffic and applies it as an input filter on interface ge-0/0/0.0. The filter contains only two terms matching destination ports 80 and 443 with an action of accept. Immediately afterward, users behind that interface report that DNS queries, corporate email, and ICMP ping traffic are completely failing. What caused this widespread disruption?
Applying a firewall filter converts the physical interface into a Layer 2 trunk port, blocking Layer 3 forwarding.
The Packet Forwarding Engine ran out of hardware counter registers, causing a software fallback stall.
Junos stateless firewall filters have an implicit discard at the end of every filter; because no term matched DNS, email, or ICMP, all other traffic was silently dropped.
The router's ARP resolution daemon was disabled because the input filter lacked a source-mac match condition.
Why is an enterprise security firewall filter designed to protect the local Routing Engine applied as an input filter on the loopback interface (lo0.0) rather than on individual physical interfaces?
Physical interfaces in Junos OS only support egress firewall filters, requiring ingress filtering to occur on loopback ports.
Applying a filter to lo0.0 activates stateful flow inspection on the Packet Forwarding Engine for all transit sessions.
Physical interface filters only inspect Layer 2 Ethernet headers, whereas lo0.0 filters evaluate Layer 3 and Layer 4 headers.
Traffic destined to any of the router's local IP addresses must pass through the lo0.0 logical interface before reaching the Routing Engine, providing centralized protection across all incoming interfaces without impacting transit traffic.
In a Junos OS firewall filter term, an administrator configures: set term secure-ssh from protocol tcp set term secure-ssh from destination-port 22 set term secure-ssh then count ssh-counter set term secure-ssh then policer mgmt-100k set term secure-ssh then accept How does the Packet Forwarding Engine process a packet that matches this term?
The PFE executes only the 'count' action because Junos prohibits configuring multiple actions within a single term.
The PFE increments 'ssh-counter', meters the packet against the 'mgmt-100k' policer, and if conforming, executes the terminating 'accept' action to forward the packet.
The PFE immediately forwards the packet upon reading 'accept', bypassing both the counter and the policer.
The PFE rejects the packet and sends an ICMP unreachable message because policers cannot be combined with counters in hardware.
Sections you finish are checked off in the contents.