可以使用 找到与 IP 匹配的路由show route 192.0.2.123
。在长前缀列表中查找匹配前缀(如果有)的等效方法是什么?...快速确定地确定 IP 是否与前缀列表匹配?...生成IP匹配的所有前缀列表的列表?
如何在 JUNOS CLI 上根据前缀列表测试 IP
网络工程
瞻博网络
命令行
字首
2021-07-07 17:23:50
1个回答
在 Junos 中,您有以下命令:
test policy <<POLICY-NAME>> <<Prefix>>
但是,它并不能完全满足您的要求。
首先,创建您的前缀列表并在策略中匹配它:
policy-options {
prefix-list SOME-PREFIXES {
172.16.10.1/32;
172.16.10.32/27;
172.16.10.50/32;
172.16.10.96/29;
172.16.10.104/29;
172.16.10.128/27;
}
policy-statement ACCEPT-PREFIXES {
term MATCH-PREFIXES {
from {
prefix-list SOME-PREFIXES;
}
then accept;
}
then reject;
}
}
现在,给定 inet.0 中的以下路由:
bdale@0ffnet-lab-gw> show route 172.16.10.0/24
inet.0: 98 destinations, 100 routes (98 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.10.0/24 *[Direct/0] 6d 05:39:58
> via vlan.10
172.16.10.21/32 *[Access-internal/12] 6d 05:31:47
> to 172.16.10.254 via vlan.10
172.16.10.22/32 *[Access-internal/12] 6d 05:39:43
> to 172.16.10.254 via vlan.10
172.16.10.23/32 *[Access-internal/12] 6d 05:39:42
> to 172.16.10.254 via vlan.10
172.16.10.24/32 *[Access-internal/12] 5d 21:25:31
> to 172.16.10.254 via vlan.10
172.16.10.25/32 *[Access-internal/12] 6d 05:38:15
> to 172.16.10.254 via vlan.10
172.16.10.28/32 *[Access-internal/12] 6d 05:39:26
> to 172.16.10.254 via vlan.10
172.16.10.32/32 *[Access-internal/12] 15:13:51
> to 172.16.10.254 via vlan.10
172.16.10.34/32 *[Access-internal/12] 14:51:36
> to 172.16.10.254 via vlan.10
172.16.10.37/32 *[Access-internal/12] 14:50:48
> to 172.16.10.254 via vlan.10
172.16.10.50/32 *[Access-internal/12] 6d 05:39:32
> to 172.16.10.254 via vlan.10
172.16.10.51/32 *[Access-internal/12] 6d 05:39:28
> to 172.16.10.254 via vlan.10
...
运行测试:
bdale@0ffnet-lab-gw> test policy ACCEPT-PREFIXES 172.16.10.0/24
inet.0: 98 destinations, 100 routes (98 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.10.50/32 *[Access-internal/12] 6d 05:43:06
> to 172.16.10.254 via vlan.10
Policy ACCEPT-PREFIXES: 1 prefix accepted, 21 prefix rejected
你会看到你只得到一场比赛。
您在测试命令中输入的前缀基本上是说“向我显示与此前缀匹配或更长的所有路由” - 类似于show route
命令的工作方式。
然而,当匹配一个前缀列表时,前缀是精确匹配的,所以即使我们的前缀列表有一个覆盖前缀(例如:)172.16.10.32/27
,它也不会导致匹配,因为那个精确的前缀不在路由表中。