目录
正文
一、Path 属性介绍
- Path 即 AS-PAHT,它记录路由条目所经过的 AS 路径,在 BGP 路由优选属性中排在第(5)位,是一个常用的属性。
- 属性类型:公认必遵。
- AS-PATH 属性是一个直观的属性。
- 图中的 1 和 5 就是 AS-PATH 属性,这代表他们到达当前路由器时经过了哪些 AS。
- AS-PATH 属性遵守防环原则,AS 不接受带有自身 Path 属性的路由条目。
- Path 属性用于优选路由时,比较的是 Path 的数量,而不是数值的大小。数量越小越优。
二、基础实验
2.1 实验说明
2.1.1 实验目的
- 通过修改 Path 属性的值,影响选路结果。
2.1.2 知识体系
- 本实验为【BGP 的选路原则 基础篇 精讲】的扩展实验,实验基础配置与基础实验相同。建议先完成基础实验的学习,再来进行本实验。
- 其他关联内容学习传送门
- ospf 基础
- bgp 基础:【BGP 基础实验 精讲】
- 路由策略 route-policy:【路由策略【ospf】【route-policy】【filter-policy】【ip-prefix】综合实验 精讲】
2.1.3 拓扑图
2.1.4 实验基础配置
- 继承自【BGP 的选路原则 基础篇 精讲】<3.3 基础配置>,复制粘贴可用。
2.2 实验步骤
- 在 R2 上查看通往 192.168.1.0 的路由条目
- 属性说明
- 路由条目 ① 指向 12.1.1.1,Path 为 1,通过路由前的标记 > 可知此路由条目为当前的优选路由条目。
- 路由条目 ② 为空白(null),这代表它继承上一条路由的 Network 属性,即 192.168.1.0。
- 使用路由策略【ip-prefix】+【route-policy】修改路由条目 ① 的 Path 属性。
- route-policy 的预习传送门【路由策略【ospf】【route-policy】【filter-policy】【ip-prefix】综合实验 精讲】
- 在 R2 进行配置
# 创建 ip-prefix,命名为 192.168.1.0,抓取 192.168.1.0/24 的路由条目 [R2] ip ip-prefix 192.168.1.0 index 10 permit 192.168.1.0 24 # 在 route-policy 中匹配 ip-prefix 192.168.1.0 # 在 route-policy 中修改 as-path 的属性值 # 注意:修改 as-path 的属性值,一定只能添加指定的 as 编号,例如我们希望路由条目 ① 退出优先,那么就给路由条目添加原来的 Path 值,使它的 Path 数量增加,达到退出优选的目的。 # addtive:添加 # overwrite:覆盖 # none overwrite:清空 # 为 route-policy AS-PATH 配置兜底策略,放行所有路由 # 查核配置 |
# 在 bgp 指认邻居 12.1.1.1 时,挂载 route-policy AS-PATH,修改其 Path 属性。 [R2] bgp 234 |
- 验证结果
<R2> display bgp routing-table # 指向 12.1.1.1 的路由条目,Path 变成了 1 1 1 1,相当于经过了 4 个路径,导致它在优选路由中败选。 |
三、华为官方考试题
3.1 拓扑图
3.2 基础实验配置
3.2.1 知识体系
- 本实验为【BGP 的选路原则 基础篇 精讲】的扩展实验,实验基础配置与基础实验相同。建议先完成基础实验的学习,再来进行本实验。
- 本实验拓扑参考官方考试题。
- 其他关联内容学习传送门
- ospf 基础
- bgp 基础:【BGP 基础实验 精讲】
- 路由策略:
- acl 和 通配符掩码:【网络中的通配符掩码】
- route-policy:【路由策略【ospf】【route-policy】【filter-policy】【ip-prefix】综合实验 精讲】
- BGP import-route
- 配置脚本中路由策略综合配置(蓝字)的解释请参考下列章节内容
3.2.2 配置脚本
- 脚本已验证,可以放心使用
- R1
system-view sysname R1 undo info-center enable acl number 2000
rule 5 permit source 172.16.0.0 0.0.255.0 route-policy BID permit node 10 if-match acl 2000 interface GigabitEthernet 0/0/1 ip address 12.1.1.1 24 interface GigabitEthernet 0/0/2 ip address 14.1.1.1 24 interface Ethernet 0/0/0 ip address 172.16.1.254 24 interface LoopBack 0 ip address 1.1.1.1 32 ospf 1 router-id 1.1.1.1 area 0 network 12.1.1.1 0.0.0.0 network 1.1.1.1 0.0.0.0 bgp 12 router-id 1.1.1.1 peer 2.2.2.2 as-number 12 peer 2.2.2.2 connect-interface Loopback 0 peer 2.2.2.2 next-hop-local peer 14.1.1.4 as-number 34 network 10.1.1.1 32 import-route direct route-policy BID |
- R2
system-view sysname R2 undo info-center enable acl number 2000
rule 5 permit source 172.16.0.0 0.0.255.0 route-policy BID permit node 10 if-match acl 2000 interface GigabitEthernet 0/0/0 ip address 12.1.1.2 24 interface GigabitEthernet 0/0/1 ip address 23.1.1.2 24 interface Ethernet 0/0/0 ip address 172.16.2.254 24 interface LoopBack 0 ip address 2.2.2.2 32 ospf 1 router-id 2.2.2.2 area 0 network 12.1.1.2 0.0.0.0 network 2.2.2.2 0.0.0.0 bgp 12 router-id 2.2.2.2 peer 1.1.1.1 as-number 12 peer 1.1.1.1 connect-interface Loopback 0 peer 1.1.1.1 next-hop-local peer 23.1.1.3 as-number 34 import-route direct route-policy BID |
- R3
system-view sysname R3 undo info-center enable acl number 2000
rule 5 permit source 172.16.0.0 0.0.255.0 route-policy BID permit node 10 if-match acl 2000 interface GigabitEthernet 0/0/1 ip address 23.1.1.3 24 interface GigabitEthernet 0/0/0 ip address 34.1.1.3 24 interface Ethernet 0/0/0 ip address 172.16.3.254 24 interface LoopBack 0 ip address 3.3.3.3 32 ospf 1 router-id 3.3.3.3 area 0 network 34.1.1.3 0.0.0.0 network 3.3.3.3 0.0.0.0 bgp 34 router-id 3.3.3.3 peer 4.4.4.4 as-number 34 peer 4.4.4.4 connect-interface Loopback 0 peer 4.4.4.4 next-hop-local peer 23.1.1.2 as-number 12 import-route direct route-policy BID |
- R4
system-view sysname R4 undo info-center enable acl number 2000
rule 5 permit source 172.16.0.0 0.0.255.0 route-policy BID permit node 10 if-match acl 2000 interface GigabitEthernet 0/0/0 ip address 14.1.1.4 24 interface GigabitEthernet 0/0/1 ip address 34.1.1.4 24 interface Ethernet 0/0/0 ip address 172.16.4.254 24 interface LoopBack 0 ip address 4.4.4.4 32 ospf 1 router-id 4.4.4.4 area 0 network 34.1.1.4 0.0.0.0 network 4.4.4.4 0.0.0.0 bgp 34 router-id 4.4.4.4 peer 3.3.3.3 as-number 34 peer 3.3.3.3 connect-interface Loopback 0 peer 3.3.3.3 next-hop-local peer 14.1.1.1 as-number 12 import-route direct route-policy BID |
3.2.3 配置验证
- 根据路由之间的连线,确认 bgp 邻居建立情况
# 此处仅以 R1 为视角进行操作,剩下的路由器请自行验证。 # 确认和邻居到达 Established 状态,则邻居建立成功。 |
- 确认 bgp 路由表是否学习完所有条目。
# 此处仅以 R1 为视角进行操作,剩下的路由器请自行验证。 # 确认所有路由器都学习到了 4 台 PC 所在网段的子网地址。 |
3.3 场景分析
- 首先先来思考两个问题
- PC4 通往 PC1 走什么路径?
- PC3 通往 PC1 走什么路径?
- 判断过程请参考【BGP 的选路原则 基础篇 精讲】
- PC4 --> PC1
对于 R4 而言,根据 BGP 的路由优选原则【(8)优选从 EBGP 学来的路由(EBGP>IBGP)】,判断 EBGP(R1)>IBGP【R3】,所以路径是【R4 --> R1】。 |
- PC3 --> PC1
对于 R3 而言,根据 BGP 的路由优选原则【(8)优选从 EBGP 学来的路由(EBGP>IBGP)】,判断 EBGP(R2)>IBGP【R4】,所以路径是【R3 --> R2 --> R1】。 |
- 根据分析,当前 AS34 的 PC 通往 R1 的路径如下图所示
3.4 题目需求解析
- 题目需求
需求概括: 让 AS34 所有通往 PC1 的路径从 R4 经过。 场景 1: 假设网络工程师为 AS 12 的管理员,只拥有 AS 12 的配置权限。 场景 2: 假设网络工程师为 AS 34 的管理员,只拥有 AS 34 的配置权限。 |
- 根据需求,我们需要实现的路径为下图所示。
3.5 场景 1 解题思路
- 假设我们是 AS 12 的管理员,只有 AS12 的权限,无法查看 AS34 的配置。已知 AS12 和 AS 34 是对称拓扑,那么我们就观察 AS12 当前 bgp 的路由条目,来分析情况。
<R1> display bgp routing-table |
# 情况分析 由此我们可推测从 R3 --> R1 的优选路由走 R2(EBGP),并且应该携带一条 Path 属性,属性值为 12。 |
- 既然携带了 Path 属性,那么我们在路由条目发送给 AS34 之前修改 Path 属性,使【R3 --> R2 --> R1】这条路径变成【R3 --> R4 --> R1】。
- 配置目标:在 R2 发送路由条目给 R3 之前,增加的 Path 数量,使【R3 --> R2】的路由变成非优选。
# 在初始配置中已经存在了 acl 2000,为了区别,新创建一个 acl 2001 # 创建 acl 2001 # 创建规则,精确抓取指定的路由条目 172.16.1.0 [R2-acl-basic-2001] rule 5 permit source 172.16.1.0 0.0.0.0 # 创建 route-policy,命名为 RTTE(Route transmission to EBGP,路由传送给 EBGP 邻居) [R2] route-policy RTTE permit node 10 # 匹配 acl 2001 [R2-route-policy] if-match acl 2001 # 以追加(additive)方式修改 as-path,增加两条 AS12 的 Path 信息。 [R2-route-policy] apply as-path 12 12 additive # 配置兜底规则,放行所有路由条目。在 BGP 之间传递路由条目一定配置兜底策略,否则在实际应用场景中会阻断路由的传播,引起重大故障。 [R2] route-policy RTTE permit node 20
# 进入 BGP,在路由发送给 EBGP 邻居时挂载 route-policy RTTE [R2] bgp 12 |
配置参考资料: |
- 验证结果
# 假设只有 AS 12 的情况下 # 指定路由条目 172.16.1.0 添加 Path 属性值成功,原来的 1 个 12,变成了 3 个连续 12。 |
# 现在切换到 R3 的视角 # 查看 bgp 路由表 <R3> display bgp routing-talbe # 可以看到 172.16.1.0 HextHop 23.1.1.2 的路由条目 Path 值已经修改成功,并且成为非优选路由。
# PC3 # Tracert 172.16.1.1 # 结果:172.16.3.254(R3)--> 34.1.1.4(R4)--> 14.1.1.1(R1)--> 172.16.1.1(PC1) # Tracert 172.16.1.1 # 结果:172.16.4.254(R4)--> 14.1.1.1(R1)--> 172.16.1.1(PC1) |
- 结论:结果符合预期。
1、在 R2 上修改了【R2 --(172.16.1.0)--> R3】的 path 属性值成功。 |
3.5 场景 2 解题思路
- 温馨提示:实验前注意还原基础配置
- 当前视角切换至 AS 34,进行场景分析
在 AS 12 上,我们是实现的是 【R2 --(172.16.1.0)--> R3】。 |
- 在 R3 上进行配置
# 在初始配置中已经存在了 acl 2000,为了区别,新创建一个 acl 2001 # 创建 acl 2001 # 创建规则,精确抓取指定的路由条目 172.16.1.0 [R3-acl-basic-2001] rule 5 permit source 172.16.1.0 0.0.0.0 # 创建 route-policy,命名为 RTTE(Route transmission to EBGP,路由传送给 EBGP 邻居) [R3] route-policy RTTE permit node 10 # 匹配 acl 2001 [R3-route-policy] if-match acl 2001 # 以追加(additive)方式修改 as-path,增加两条 AS12 的 Path 信息。 [R3-route-policy] apply as-path 12 12 additive # 配置兜底规则,放行所有路由条目。在 BGP 之间传递路由条目一定配置兜底策略,否则在实际应用场景中会阻断路由的传播,引起重大故障。 [R3] route-policy RTTE permit node 20
# 进入 BGP,在路由发送给 EBGP 邻居时挂载 route-policy RTTE [R3] bgp 34 |
# 与 AS12 的配置对比,尽最后两条语句进行了更改 1、bgp ID:bpg 12 换成 bgp 34 2、邻居:R3 改成 R2(23.1.1.2) 3、路由策略方向:export 改成 import |
- 验证结果
# 在 R3 上查看接收到从 R2 发送的路由条目信息 # Path 修改成功
# Path 修改成功,且路由条目变成了非优选路径 # Tracert 测试 |