Routing Policy and Firewall Filters · Topic 2 of 4
Routing Policy Structure, Match Criteria and Actions
Learn Junos policy-statement terms, from and then, route filter match types such as exact, orlonger and upto, prefix lists and policy actions for JN0-106.
- 6 min
- Policy:
policy-statement>term>from(conditions) >then(actions). - Terms run in order; no
frommeans match all. - Different conditions are AND; multiple values of one condition are OR.
What it is
A Junos routing policy is a policy-statement made of one or more terms. Each term has a from section with match conditions and a then section with actions. A route that meets all the conditions in from gets the actions in then.
Match types tell a route filter how a route's prefix must relate to the prefix you configured: exactly the same, longer, or within a range of lengths.
How it works
Policy structure
policy-options {
policy-statement BGP-IN {
term REJECT-PRIVATE {
from {
route-filter 10.0.0.0/8 orlonger;
route-filter 172.16.0.0/12 orlonger;
route-filter 192.168.0.0/16 orlonger;
}
then reject;
}
term SET-LP {
from {
protocol bgp;
neighbor 192.0.2.1;
}
then {
local-preference 200;
accept;
}
}
}
}
Rules for terms:
- Terms are evaluated in the order they appear. Use
insertin configuration mode to move one, for exampleinsert policy-options policy-statement BGP-IN term SET-LP before term REJECT-PRIVATE. - A term with no
frommatches every route. - A term with no terminating action lets a matching route carry on to the next term, keeping any changes already made.
Match conditions
| Condition | Matches |
|---|---|
protocol | Source of the route: static, direct, ospf, bgp, aggregate and others |
route-filter | The prefix and its length, with a match type |
prefix-list | A named list of prefixes, matched exactly |
prefix-list-filter | A named prefix list with a match type such as orlonger |
neighbor | The neighbor that sent the route |
interface | The interface the route was learned on |
area | The OSPF area |
as-path | A BGP AS path regular expression |
community | A BGP community |
tag, metric | Route tag or metric values |
Logic inside from: different conditions are combined with AND. Several values of the same condition, such as two route filters, are combined with OR. In the example above, term SET-LP needs protocol bgp AND neighbor 192.0.2.1.
There is also a to section, used less often, that matches on where the route is going, such as the neighbor it is advertised to.
Route filter match types
All examples use route-filter 192.168.0.0/16 with the given match type.
| Match type | Matches | Example that matches |
|---|---|---|
exact | Only 192.168.0.0/16 | 192.168.0.0/16 |
orlonger | The /16 and any more specific prefix inside it | 192.168.0.0/16, 192.168.5.0/24 |
longer | Only more specific prefixes, not the /16 itself | 192.168.5.0/24 |
upto /24 | Prefix lengths /16 to /24 inside it | 192.168.5.0/24, but not a /25 |
prefix-length-range /20-/24 | Prefix lengths /20 to /24 inside it | 192.168.16.0/20, but not the /16 |
through 192.168.16.0/20 | Routes on the direct path from the /16 to that prefix | 192.168.0.0/16, 192.168.16.0/20 |
How route filters are evaluated
When a term has several route filters, Junos OS first finds the route filter whose prefix is the longest match for the route, then checks that filter's match type. If the match type fails, the term does not match, even if a shorter route filter in the same term would have matched.
Example: a term has route-filter 10.0.0.0/8 orlonger and route-filter 10.1.0.0/16 exact. The route 10.1.1.0/24 has 10.1.0.0/16 as its longest matching filter. That filter needs an exact /16, so the term does not match the route, although the /8 orlonger filter alone would have matched it.
A route filter can also carry its own action, which applies only when that filter matches:
user@router# set policy-options policy-statement BGP-IN term T1 from route-filter 10.0.0.0/8 orlonger reject
Prefix lists
A prefix list is a reusable named set of prefixes, defined under [edit policy-options prefix-list]. Used with from prefix-list, each entry matches only exactly. Use prefix-list-filter NAME orlonger (or exact, longer) when you need a match type.
user@router# set policy-options prefix-list CUSTOMERS 203.0.113.0/24
user@router# set policy-options policy-statement OUT term 1 from prefix-list CUSTOMERS
user@router# set policy-options policy-statement OUT term 1 then accept
Actions
| Kind | Actions | Effect |
|---|---|---|
| Terminating | accept, reject | Final decision; evaluation stops |
| Flow control | next term, next policy | Skip to the next term or the next policy |
| Modifying | local-preference, metric, preference, community add, community set, community delete, next-hop, tag, as-path-prepend | Change route attributes; evaluation carries on unless a terminating action follows |
A term that only modifies attributes, with no accept or reject, changes the route and passes it on. If nothing later accepts or rejects it, the protocol default policy decides.
Common mistakes
Assuming longer includes the configured prefix. longer excludes it; orlonger includes it.
Expecting a shorter route filter to rescue a route. Only the longest matching route filter in the term is checked.
Using prefix-list for a range of lengths. A prefix list matches exactly. Use prefix-list-filter or a route filter for ranges.
A final term with no from and then accept accepts everything left. Put it last, or every term after it is useless.
What to remember for the exam
- Policy:
policy-statement>term>from(conditions) >then(actions). - Terms run in order; no
frommeans match all. - Different conditions are AND; multiple values of one condition are OR.
- Match types:
exact,orlonger,longer,upto,prefix-length-range,through. - The longest matching route filter is chosen first, then its match type is checked.
prefix-listmatches exactly;prefix-list-filteradds a match type.- Terminating:
accept,reject. Flow control:next term,next policy.
Check yourself
Does
route-filter 172.16.0.0/16 longermatch the route 172.16.0.0/16?No.
longermatches only prefixes more specific than /16; useorlongerto include the /16 itself.A term has
from protocol staticandfrom route-filter 10.0.0.0/8 orlonger. Which routes match?Only static routes inside 10.0.0.0/8, because different conditions are combined with AND.
What happens to a route matched by a term whose only action is
metric 10?Its metric is set to 10 and evaluation continues with the next term or policy.
Topic 2 of 4 in Routing Policy and Firewall Filters
Test yourself on Routing Policy and Firewall Filters
The full Juniper JNCIA-Junos JN0-106 question bank has 1,155 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.