One can find routes matching an IP using show route What is the equivalent way to find matching prefixes, if any, in a long prefix list? ... to determine quickly and conclusively whether or not an IP matches a prefix list? ... to generate a list of all prefix lists that an IP matches?

  • Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer.
    – Ron Maupin
    Aug 9, 2017 at 23:08

1 Answer 1


In Junos you have the command:

test policy <<POLICY-NAME>> <<Prefix>>

however, it doesn't do quite what you are asking.

Firstly, create your prefix-list and match it in a policy:

policy-options {
    prefix-list SOME-PREFIXES {;;;;;;
    policy-statement ACCEPT-PREFIXES {
        term MATCH-PREFIXES {
            from {
                prefix-list SOME-PREFIXES;
            then accept;
        then reject;

Now, given the following routes in inet.0:

bdale@0ffnet-lab-gw> show route 

inet.0: 98 destinations, 100 routes (98 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both     *[Direct/0] 6d 05:39:58
                    > via vlan.10    *[Access-internal/12] 6d 05:31:47
                    > to via vlan.10    *[Access-internal/12] 6d 05:39:43
                    > to via vlan.10    *[Access-internal/12] 6d 05:39:42
                    > to via vlan.10    *[Access-internal/12] 5d 21:25:31
                    > to via vlan.10    *[Access-internal/12] 6d 05:38:15
                    > to via vlan.10    *[Access-internal/12] 6d 05:39:26
                    > to via vlan.10    *[Access-internal/12] 15:13:51
                    > to via vlan.10    *[Access-internal/12] 14:51:36
                    > to via vlan.10    *[Access-internal/12] 14:50:48
                    > to via vlan.10    *[Access-internal/12] 6d 05:39:32
                    > to via vlan.10    *[Access-internal/12] 6d 05:39:28
                    > to via vlan.10

run the test:

bdale@0ffnet-lab-gw> test policy ACCEPT-PREFIXES 

inet.0: 98 destinations, 100 routes (98 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both    *[Access-internal/12] 6d 05:43:06
                    > to via vlan.10

Policy ACCEPT-PREFIXES: 1 prefix accepted, 21 prefix rejected

And you'll see you only get one match.

The prefix you enter into the test command basically says "show me all the routes that match this prefix or longer" - in a similar to the way a show route command works.

However, when matching a prefix list, prefixes are matched exactly, so even though our prefix list has a covering prefix (eg: that doesn't cause a match because that exact prefix isn't in the routing table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.