本產品的文件集力求使用無偏見用語。針對本文件集的目的,無偏見係定義為未根據年齡、身心障礙、性別、種族身分、民族身分、性別傾向、社會經濟地位及交織性表示歧視的用語。由於本產品軟體使用者介面中硬式編碼的語言、根據 RFP 文件使用的語言,或引用第三方產品的語言,因此本文件中可能會出現例外狀況。深入瞭解思科如何使用包容性用語。
思科已使用電腦和人工技術翻譯本文件,讓全世界的使用者能夠以自己的語言理解支援內容。請注意,即使是最佳機器翻譯,也不如專業譯者翻譯的內容準確。Cisco Systems, Inc. 對這些翻譯的準確度概不負責,並建議一律查看原始英文文件(提供連結)。
本文檔介紹如何使用set ip default next-hop 和set ip next-hop 命令配置基於策略的路由(PBR)。
本文件沒有特定需求。
本文檔中的資訊基於支援基於策略的路由的軟體。
可以使用Cisco Feature Navigator確定此配置支援的硬體和軟體。
備註:只有註冊的思科使用者能夠存取內部工具與資訊。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
如需文件慣例的詳細資訊,請參閱思科技術提示慣例。
本檔案使用set ip default next-hop和set ip next-hop命令提供原則型路由(PBR)的範例組態。
set ip default next-hop 命令驗證目標IP地址在路由表中是否存在,以及:
如果存在目的IP地址,該命令不會根據策略路由資料包,而是根據路由表轉發資料包。
如果目標IP地址不存在,命令策略將路由資料包並將其傳送到指定的下一跳。
set ip next-hop 命令用於驗證指定的下一跳是否存在,以及:
如果路由表中存在下一跳,則命令policy將資料包路由到下一跳。
本節提供設定本檔案所述功能的資訊。
此文件使用以下網路設定:
本節使用以下配置:
R1 |
---|
R1#show running-config Building configuration... ! ! interface Ethernet0/0 ip address 10.100.100.1 255.255.255.0 ip policy route-map blah ! interface Serial1/0 ip address 10.10.10.1 255.255.255.0 ! interface Serial2/0 ip address 10.20.20.1 255.255.255.0 ! router ospf 1 !--- OSPF is not configured on Serial1/0. log-adjacency-changes network 10.20.20.0 0.0.0.255 area 0 network 10.100.100.0 0.0.0.255 area 0 ! ip classless no ip http server ! access-list 100 permit ip host 10.100.100.3 host 10.200.200.4 ! route-map blah permit 10 match ip address 100 set ip default next-hop 10.10.10.2 ! end |
R2 |
---|
R2#show running-config Building configuration... ! ! interface Ethernet0/0 ip address 10.200.200.2 255.255.255.0 ip policy route-map blah ! interface Serial1/0 ip address 10.10.10.2 255.255.255.0 fair-queue ! interface Serial2/0 ip address 10.20.20.2 255.255.255.0 ! router ospf 1 !--- OSPF is not configured on Serial1/0. log-adjacency-changes network 10.20.20.0 0.0.0.255 area 0 network 10.200.200.0 0.0.0.255 area 0 ! ip classless no ip http server ! access-list 100 permit ip host 10.200.200.4 host 10.100.100.3 ! route-map blah permit 10 match ip address 100 set ip default next-hop 10.10.10.1 ! end |
使用命令set ip default next-hop時,當目標路由存在於路由表中時,使用正常轉發(請勿對資料包進行策略路由)。
R1#show ip route 10.200.200.4 Routing entry for 10.200.200.0/24 Known via "ospf 1", distance 110, metric 74, type intra area Last update from 10.20.20.2 on Serial2/0, 00:11:48 ago Routing Descriptor Blocks: * 10.20.20.2, from 10.30.30.3, 00:11:48 ago, via Serial2/0 Route metric is 74, traffic share count is 1 R1#debug ip policy Policy routing debugging is on *Dec 4 12:50:57.363: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 4 12:50:57.363: IP: route map blah, item 10, permit *Dec 4 12:50:57.363: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial2/0), len 100, policy rejected -- normal forwarding *Dec 4 12:50:57.431: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 4 12:50:57.431: IP: route map blah, item 10, permit *Dec 4 12:50:57.431: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial2/0), len 100, policy rejected -- normal forwarding *Dec 4 12:50:57.491: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 4 12:50:57.491: IP: route map blah, item 10, permit *Dec 4 12:50:57.491: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial2/0), len 100, policy rejected -- normal forwarding R2#show ip route 10.100.100.3 Routing entry for 10.100.100.0/24 Known via "ospf 1", distance 110, metric 74, type intra area Last update from 10.20.20.1 on Serial2/0, 00:11:42 ago Routing Descriptor Blocks: * 10.20.20.1, from 10.100.100.1, 00:11:42 ago, via Serial2/0 Route metric is 74, traffic share count is 1 R2#debug ip policy Policy routing debugging is on *Dec 4 12:50:57.779: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3, len 100, policy match *Dec 4 12:50:57.779: IP: route map blah, item 10, permit *Dec 4 12:50:57.779: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3 (Serial2/0), len 100, policy rejected -- normal forwarding *Dec 4 12:50:57.839: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3, len 100, policy match *Dec 4 12:50:57.839: IP: route map blah, item 10, permit *Dec 4 12:50:57.839: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3 (Serial2/0), len 100, policy rejected -- normal forwarding *Dec 4 12:50:57.911: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3, len 100, policy match *Dec 4 12:50:57.911: IP: route map blah, item 10, permit *Dec 4 12:50:57.911: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3 (Serial2/0), len 100, policy rejected -- normal forwarding
當Serial 2/0關閉並且目的地址從路由表中消失時,資料包將進行策略路由。
R1#show ip route 10.200.200.0 % Network not in table R1# *Dec 5 13:26:27.567: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:26:27.567: IP: route map blah, item 10, permit *Dec 5 13:26:27.567: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0),len 100, policy routed *Dec 5 13:26:27.567: IP: Ethernet0/0 to Serial1/0 10.10.10.2 *Dec 5 13:26:27.655: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:26:27.655: IP: route map blah, item 10, permit *Dec 5 13:26:27.655: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0),len 100, policy routed *Dec 5 13:26:27.655: IP: Ethernet0/0 to Serial1/0 10.10.10.2 *Dec 5 13:26:27.727: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:26:27.727: IP: route map blah, item 10, permit *Dec 5 13:26:27.727: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0),len 100, policy routed *Dec 5 13:26:27.727: IP: Ethernet0/0 to Serial1/0 10.10.10.2
本節使用以下配置:
R1 |
---|
R1#show running-config Building configuration... ! |
R2 |
---|
R2#show running-config Building configuration... ! |
使用命令set ip next-hop,路由器會驗證路由表中是否有下一跳10.10.10.2。如果路由表中存在目的路由,則當下一跳可到達時,策略路由資料包。
R1#show ip route 10.10.10.2Routing entry for 10.10.10.0/24 Known via "connected", distance 0, metric 0 (connected, via interface) Routing Descriptor Blocks: * directly connected, via Serial1/0 Route metric is 0, traffic share count is 1
R1#show ip route 10.200.200.4
Routing entry for 10.200.200.0/24
Known via "ospf 1", distance 110, metric 74,
type intra area Last update from 10.20.20.2 on Serial2/0, 00:11:48 ago
Routing Descriptor Blocks: * 10.20.20.2, from 10.30.30.3, 00:11:48 ago,
via Serial2/0 Route metric is 74, traffic share count is 1
R1#debug ip policy Policy routing debugging is on
*Dec 4 12:53:38.271: IP: s=10.100.100.3 (Ethernet0/0), d=10.200.200.4, len 100, policy match
*Dec 4 12:53:38.271: IP: route map blah, item 10, permit
*Dec 4 12:53:38.271: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0), len 100, policy routed *Dec 4 12:53:38.271:
IP: Ethernet0/0 to Serial1/0 10.10.10.2 *Dec 4 12:53:38.355:
IP: s=10.100.100.3 (Ethernet0/0), d=10.200.200.4, len 100, policy match *Dec 4 12:53:38.355:
IP: route map blah, item 10, permit *Dec 4 12:53:38.355:
IP: s=10.100.100.3 (Ethernet0/0), d=10.200.200.4 (Serial1/0), len 100, policy routed
*Dec 4 12:53:38.355: IP: Ethernet0/0 to Serial1/0 10.10.10.2
*Dec 4 12:53:38.483: IP: s=10.100.100.3 (Ethernet0/0), d=10.200.200.4, len 100, policy match
*Dec 4 12:53:38.483: IP: route map blah, item 10, permit
R2#show ip route 10.100.100.3 Routing entry for 10.100.100.0/24 Known via "ospf 1",
distance 110, metric 74, type intra area Last update from 10.20.20.1 on Serial2/0,
00:11:42 ago Routing Descriptor Blocks: * 10.20.20.1, from 10.100.100.1, 00:11:42 ago,
via Serial2/0 Route metric is 74, traffic share count is 1 R2#debug ip policy
Policy routing debugging is on *Dec 4 12:53:38.691:
IP: s=10.200.200.4 (Ethernet0/0), d=10.100.100.3, len 100, policy match *Dec 4 12:53:38.691:
IP: route map blah, item 10, permit *Dec 4 12:53:38.691: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3 (Serial1/0), len 100, policy routed
*Dec 4 12:53:38.691: IP: Ethernet0/0 to Serial1/0 10.10.10.1 *Dec 4 12:53:38.799:
IP: s=10.200.200.4 (Ethernet0/0), d=10.100.100.3, len 100, policy match
*Dec 4 12:53:38.799: IP: route map blah, item 10, permit
*Dec 4 12:53:38.799: IP: s=10.200.200.4 (Ethernet0/0), d=10.100.100.3 (Serial1/0), len 100, policy routed
*Dec 4 12:53:38.799: IP: Ethernet0/0 to Serial1/0 10.10.10.1 *Dec 4 12:53:38.899:
IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3, len 100, policy match
*Dec 4 12:53:38.899: IP: route map blah, item 10, permit
當目的IP地址從路由中消失時,資料包將進行策略路由。
*Dec 5 13:33:23.607: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:33:23.607: IP: route map blah, item 10, permit *Dec 5 13:33:23.607: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0),len 100, policy routed *Dec 5 13:33:23.607: IP: Ethernet0/0 to Serial1/0 10.10.10.2 *Dec 5 13:33:23.707: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:33:23.707: IP: route map blah, item 10, permit *Dec 5 13:33:23.707: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0),len 100, policy routed *Dec 5 13:33:23.707: IP: Ethernet0/0 to Serial1/0 10.10.10.2 *Dec 5 13:33:23.847: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:33:23.847: IP: route map blah, item 10, permit
當Serial 1/0介面關閉時,路由表中下一跳10.10.10.2丟失,資料包將跟蹤正常的路由表。
*Dec 5 13:40:38.887: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:40:38.887: IP: route map blah, item 10, permit *Dec 5 13:40:38.887: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial2/0), len 100, policy rejected -- normal forwarding *Dec 5 13:40:39.047: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:40:39.047: IP: route map blah, item 10, permit *Dec 5 13:40:39.047: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial2/0), len 100, policy rejected -- normal forwarding *Dec 5 13:40:39.115: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:40:39.115: IP: route map blah, item 10, permit *Dec 5 13:40:39.115: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial2/0), len 100, policy rejected -- normal forwarding
本節使用以下配置:
R1 |
---|
R1#show running-config Building configuration... ! |
R2 |
---|
R2#show running-config Building configuration... ! ! interface Ethernet0/0 ip address 10.200.200.2 255.255.255.0 ip policy route-map blah ! interface Serial1/0 ip address 10.10.10.2 255.255.255.0 fair-queue ! interface Serial2/0 ip address 10.20.20.2 255.255.255.0 ! ip route 0.0.0.0 0.0.0.0 10.20.20.1 ! ip classless no ip http server ! ! ! access-list 100 permit ip host 10.200.200.4 host 10.100.100.3 ! route-map blah permit 10 match ip address 100 set ip default next-hop 10.10.10.1 ! end |
使用命令set ip default next-hop時,如果到目標的唯一路由是預設路由(路由表中沒有該目標的特定路由),資料包將進行策略路由。
R1#show ip route 10.200.200.4 % Network not in table R1# R1#show ip route 0.0.0.0 Routing entry for 0.0.0.0/0, supernet Known via "static", distance 1, metric 0, candidate default path Routing Descriptor Blocks: * 10.20.20.2 Route metric is 0, traffic share count is 1 R1# *Dec 4 12:58:55.191: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 4 12:58:55.191: IP: route map blah, item 10, permit *Dec 4 12:58:55.191: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0), len 100, policy routed *Dec 4 12:58:55.191: IP: Ethernet0/0 to Serial1/0 10.10.10.2 *Dec 4 12:58:55.291: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 4 12:58:55.291: IP: route map blah, item 10, permit *Dec 4 12:58:55.291: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0), len 100, policy routed *Dec 4 12:58:55.291: IP: Ethernet0/0 to Serial1/0 10.10.10.2 *Dec 4 12:58:55.391: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 4 12:58:55.391: IP: route map blah, item 10, permit *Dec 4 12:58:55.391: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0), len 100, policy routed *Dec 4 12:58:55.391: IP: Ethernet0/0 to Serial1/0 10.10.10.2 R2#show ip route 10.100.100.3 % Network not in table R2#show ip route 0.0.0.0 Routing entry for 0.0.0.0/0, supernet Known via "static", distance 1, metric 0, candidate default path Routing Descriptor Blocks: * 10.20.20.1 Route metric is 0, traffic share count is 1 R2# *Dec 4 12:58:20.819: %SYS-5-CONFIG_I: Configured from console by console *Dec 4 12:58:55.611: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3, len 100, policy match *Dec 4 12:58:55.611: IP: route map blah, item 10, permit *Dec 4 12:58:55.611: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3 (Serial1/0), len 100, policy routed *Dec 4 12:58:55.611: IP: Ethernet0/0 to Serial1/0 10.10.10.1 *Dec 4 12:58:55.739: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3, len 100, policy match *Dec 4 12:58:55.739: IP: route map blah, item 10, permit *Dec 4 12:58:55.739: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3 (Serial1/0), len 100, policy routed *Dec 4 12:58:55.739: IP: Ethernet0/0 to Serial1/0 10.10.10.1 *Dec 4 12:58:55.799: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3, len 100, policy match *Dec 4 12:58:55.799: IP: route map blah, item 10, permit *Dec 4 12:58:55.799: IP: s=10.200.200.4 (Ethernet0/0),
d=10.100.100.3 (Serial1/0), len 100, policy routed *Dec 4 12:58:55.799: IP: Ethernet0/0 to Serial1/0 10.10.10.1
當由於Serial 2/0關閉而不存在預設路由時,資料包將進行策略路由。
R1#show ip route 0.0.0.0 % Network not in table R1# *Dec 5 13:02:31.283: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:02:31.283: IP: route map blah, item 10, permit *Dec 5 13:02:31.283: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0),len 100, policy routed *Dec 5 13:02:31.283: IP: Ethernet0/0 to Serial1/0 10.10.10.2 *Dec 5 13:02:31.375: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:02:31.375: IP: route map blah, item 10, permit *Dec 5 13:02:31.375: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0),len 100, policy routed *Dec 5 13:02:31.375: IP: Ethernet0/0 to Serial1/0 10.10.10.2 *Dec 5 13:02:31.435: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 13:02:31.435: IP: route map blah, item 10, permit *Dec 5 13:02:31.435: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial1/0),len 100, policy routed *Dec 5 13:02:31.435: IP: Ethernet0/0 to Serial1/0 10.10.10.2
在Serial2/0開啟而Serial 1/0關閉的情況下,您將丟失下一跳,資料包將跟蹤正常轉發(路由表)-策略被拒絕。
R1#debug ip policy Policy routing debugging is on R1# *Dec 5 12:46:49.543: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 12:46:49.543: IP: route map blah, item 10, permit *Dec 5 12:46:49.543: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial2/0),len 100, policy rejected -- normal forwarding *Dec 5 12:46:49.623: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 12:46:49.623: IP: route map blah, item 10, permit *Dec 5 12:46:49.623: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial2/0),len 100, policy rejected -- normal forwarding *Dec 5 12:46:49.691: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4, len 100, policy match *Dec 5 12:46:49.691: IP: route map blah, item 10, permit *Dec 5 12:46:49.691: IP: s=10.100.100.3 (Ethernet0/0),
d=10.200.200.4 (Serial2/0),len 100, policy rejected -- normal forwarding
修訂 | 發佈日期 | 意見 |
---|---|---|
2.0 |
20-Nov-2023 |
重新認證 |
1.0 |
05-Dec-2003 |
初始版本 |