前言
路由策略(route-policy):通过改变路由的属性,来改变网络流量经过的路径。3种方式:控制路由的发布,控制路由的接收,控制路由的引入,解决网络中环路问题。还可以支持多种网络管理和优化功能,从而提高网络的效率和可靠性。
拓扑图
在上面拓扑图中左边的网络运行ospf并引入外部路由,右边的网络运行ISIS。然后在R2和R3上相互引入ospf、isis。然后检查网络中有没有环路与次优路径问题。
基础配置(包含ospf和isis)
R1
#
interface GigabitEthernet0/0/0
ip address 10.0.12.1 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 10.0.13.1 255.255.255.0
#
interface GigabitEthernet0/0/2
ip address 10.0.15.1 255.255.255.0
#
interface LoopBack0
ip address 192.168.1.1 255.255.255.0
ospf network-type broadcast ##设置ospf类型为广播
#
ospf 1 router-id 10.0.1.1
import-route direct ##引入直连路由
area 0.0.0.0
network 10.0.12.0 0.0.0.255
network 10.0.13.0 0.0.0.255
network 10.0.15.0 0.0.0.255
#
R2
#
isis 1
network-entity 49.0000.0000.2222.00 ##创建 ISIS 网络实体标识符
is-name R2
#
interface GigabitEthernet0/0/0
ip address 10.0.12.2 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 10.0.24.2 255.255.255.0
isis enable 1 ##在接口下使能isis
#
interface LoopBack0
ip address 10.0.2.2 255.255.255.0
#
ospf 1 router-id 10.0.2.2
area 0.0.0.0
network 10.0.12.0 0.0.0.255
#
R3
#
isis 1
network-entity 49.0000.0000.3333.00
is-name R3
#
interface GigabitEthernet0/0/0
ip address 10.0.13.3 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 10.0.34.3 255.255.255.0
isis enable 1
#
interface LoopBack0
ip address 10.0.3.3 255.255.255.255
#
ospf 1 router-id 10.0.3.3
area 0.0.0.0
network 10.0.13.0 0.0.0.255
#
R4
#
isis 1
network-entity 49.0000.0000.4444.00
is-name R4
#
interface GigabitEthernet0/0/0
ip address 10.0.34.4 255.255.255.0
isis enable 1
#
interface GigabitEthernet0/0/1
ip address 10.0.24.4 255.255.255.0
isis enable 1
#
R5
#
interface GigabitEthernet0/0/0
ip address 10.0.15.5 255.255.255.0
ospf cost 100 ##使环路产生的更明显
#
interface LoopBack0
ip address 10.0.5.5 255.255.255.255
#
ospf 1 router-id 10.0.5.5
import-route direct
area 0.0.0.0
network 10.0.15.0 0.0.0.255
#
检查邻居建立关系与路由表
ospf
<R1>display ospf peer brief
OSPF Process 1 with Router ID 10.0.1.1
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/0 10.0.2.2 Full
0.0.0.0 GigabitEthernet0/0/1 10.0.3.3 Full
0.0.0.0 GigabitEthernet0/0/2 10.0.5.5 Full
----------------------------------------------------------------------------
## 状态都为full,表示建立成功
<R3>display ospf routing
OSPF Process 1 with Router ID 10.0.3.3
Routing Tables
Routing for Network
Destination Cost Type NextHop AdvRouter Area
10.0.13.0/24 1 Transit 10.0.13.3 10.0.3.3 0.0.0.0
10.0.12.0/24 2 Transit 10.0.13.1 10.0.1.1 0.0.0.0
10.0.15.0/24 2 Transit 10.0.13.1 10.0.5.5 0.0.0.0
Routing for ASEs
Destination Cost Type Tag NextHop AdvRouter
10.0.5.5/32 1 Type2 1 10.0.13.1 10.0.5.5
192.168.1.0/24 1 Type2 1 10.0.13.1 10.0.1.1
Total Nets: 5
Intra Area: 3 Inter Area: 0 ASE: 2 NSSA: 0
## 3条区域内路由 0条区域间路由 2条外部路由 0条NSSA路由
isis
<R4>display isis peer
Peer information for ISIS(1)
System Id Interface Circuit Id State HoldTime Type PRI
-------------------------------------------------------------------------------
R3 GE0/0/0 R3.01 Up 7s L1(L1L2) 64
R3 GE0/0/0 R3.01 Up 8s L2(L1L2) 64
R2 GE0/0/1 R2.01 Up 8s L1(L1L2) 64
R2 GE0/0/1 R2.01 Up 8s L2(L1L2) 64
Total Peer(s): 4
<R4>display isis route
Route information for ISIS(1)
-----------------------------
ISIS(1) Level-1 Forwarding Table
--------------------------------
IPV4 Destination IntCost ExtCost ExitInterface NextHop Flags
-------------------------------------------------------------------------------
10.0.24.0/24 10 NULL GE0/0/1 Direct D/-/L/-
10.0.34.0/24 10 NULL GE0/0/0 Direct D/-/L/-
Flags: D-Direct, A-Added to URT, L-Advertised in LSPs, S-IGP Shortcut,
U-Up/Down Bit Set
ISIS(1) Level-2 Forwarding Table
--------------------------------
IPV4 Destination IntCost ExtCost ExitInterface NextHop Flags
-------------------------------------------------------------------------------
10.0.24.0/24 10 NULL GE0/0/1 Direct D/-/L/-
10.0.34.0/24 10 NULL GE0/0/0 Direct D/-/L/-
Flags: D-Direct, A-Added to URT, L-Advertised in LSPs, S-IGP Shortcut,
U-Up/Down Bit Set
## 表明isis也建立成功
相互引入路由
R2
#
isis 1
network-entity 49.0000.0000.2222.00
import-route ospf 1 ##在isis引入ospf
#
ospf 1 router-id 10.0.2.2
import-route isis 1 ##在ospf引入isis
#
R3
#
isis 1
network-entity 49.0000.0000.3333.00
import-route ospf 1
#
ospf 1 router-id 10.0.3.3
import-route isis 1
#
查看网络中的环路与次优路径
[R3-isis-1]tracert 10.0.5.5
traceroute to 10.0.5.5(10.0.5.5), max hops: 30 ,packet length: 40,press CTRL_C
to break
1 10.0.34.4 20 ms 10 ms 10 ms
2 10.0.24.2 20 ms 30 ms 20 ms
3 10.0.12.1 30 ms 20 ms 20 ms
4 10.0.13.3 20 ms 20 ms 20 ms
5 10.0.34.4 30 ms 40 ms 30 ms
[R3]tracert 192.168.1.1
traceroute to 192.168.1.1(192.168.1.1), max hops: 30 ,packet length: 40,press
CTRL_C to break
1 10.0.34.4 40 ms 20 ms 20 ms
2 10.0.24.2 20 ms 20 ms 20 ms
3 10.0.12.1 20 ms 20 ms 30 ms
在R3上对于两个目标 IP 地址 10.0.5.5 和 192.168.1.1 的 traceroute 结果。发现到达10.0.5.5的流量出现了环路,到达192.168.1.1的流量不是最优路径。后面我会一一分析为什么产生这个原因,和该怎么解决。
次优问题
R3
<R3>display ip routing-table
192.168.1.0/24 ISIS-L2 15 84 D 10.0.34.4 GigabitEthernet
0/0/1
我们发现192.168.1.1这条路由信息是R4上学到的。
R4
<R4>display ip routing-table
192.168.1.0/24 ISIS-L2 15 74 D 10.0.24.2 GigabitEthernet
0/0/1
我们发现192.168.1.1这条路由信息是R2上学到的。
R2
<R2>display ip routing-table
192.168.1.0/24 O_ASE 150 1 D 10.0.12.1 GigabitEthernet
0/0/0
而192.168.1.1路由是R1引入的外部路由。
解决方法
R2
#
ip ip-prefix net192 index 10 permit 192.168.1.0 24
#
route-policy net192 deny node 10
if-match ip-prefix net192
#
route-policy net192 permit node 20
#
isis 1
import-route ospf 1 route-policy net192
创建一个名为net192的IP前缀索引为10,允许192.168.1.0/24的地址通过。 路由策略net192拒绝节点10的操作,如果匹配IP前缀net192。 路由策略net192允许节点20的操作。拒绝192.168.1.1的网段通过ospf引入到路由表中。
再次到R3查看就发现已经是最优路径了
<R3>tracert 192.168.1.1
traceroute to 192.168.1.1(192.168.1.1), max hops: 30 ,packet length: 40,press
CTRL_C to break
1 10.0.13.1 20 ms 10 ms 20 ms
R4
[R2-ospf-1]tracert 192.168.1.1
traceroute to 192.168.1.1(192.168.1.1), max hops: 30 ,packet length: 40,press
CTRL_C to break
1 10.0.24.4 20 ms 10 ms 20 ms
2 10.0.34.3 20 ms 10 ms 10 ms
3 10.0.13.1 20 ms 30 ms 20 ms
而R4上出现了次优路径的问题
查看路由表
[R2]display ip routing-table
192.168.1.0/24 ISIS-L2 15 84 D 10.0.24.4 GigabitEthernet
0/0/1
我们可以通过修改优先级ospf引入外部路由的Proto是150,isis引入外部Proto是15,我们在进行acl匹配相应网段并在ospf中降低Proto为14。
解决办法
#
acl number 2000
rule 1 permit source 192.168.1.0 0.0.0.255
#
route-policy hcip permit node 10
if-match acl 2000
apply preference 14
#
#
ospf 1 router-id 10.0.2.2
import-route isis 1
preference ase route-policy hcip 150
ACL 2000号规则 1 允许源地址为192.168.1.0 0.0.0.255的数据包通过。 路由策略hcip允许节点10匹配ACL 2000,并应用优先级为14。 OSPF协议实例1的路由器ID设定为10.0.2.2。 导入ISIS协议实例1的路由。 ASE路由的优先级设定为150,并遵循路由策略hcip。
查看
[R2]tracert 192.168.1.1
traceroute to 192.168.1.1(192.168.1.1), max hops: 30 ,packet length: 40,press
CTRL_C to break
1 10.0.12.1 20 ms 20 ms 20 ms
问题解决
环路问题
R3
#
acl number 2000
rule 5 deny source 10.0.5.5 0
rule 10 permit
#
isis 1
filter-policy 2000 import
创建一个访问控制列表 (ACL),用于过滤流量:
拒绝来自 10.0.5.5 的流量。
允许所有其他流量。
在 IS-IS 协议中使用这个 ACL 作为过滤策略,来决定哪些路由可以被导入,该 ACL 通过拒绝与 10.0.5.5 匹配的流量,从而控制 IS-IS 路由的类型和数量。
总结
路由策略工具
Filter-policy 过滤策略:路由信息过滤工具,能接受,发布,引入的路由进行过滤。只过滤
路由信息,无法过滤LSA
Route-policy 路由策略:用于过滤路由信息,以及过滤后路由信息设置路由属性,由一个或多个node(或关系)构成,每个节点都可以是一系统条件语句if-match(与关系),执行apply的集合。