BGP路由优选

1.实验拓扑




2.实验目标
 通过修改 AS-Path 属性来影响路径选择
 通过修改 Local Preference 属性来影响路径选择
 通过修改 MED 属性来影响路径选择
 通过修改 preferred-value 属性来影响路径选择
3.关键技术
3.1 通过修改 AS-Path 属性来影响路径选择
 修改AS Path 属性
 在R1 上通过路由策略修改 BGP 路由 172.16.1.0/24 的 AS Path 属性值,使得 R3 优选 R5 发布的 BGP 路由 172.16.1.0/24。
 #创建IP 前缀列表 1,匹配 Loopback1 接口路由
 [R1] ip ip-prefix 1 permit 172.16.1.0 24 greater-equal 24 less-equal 24
 #创建 Route-Policy hcip,并创建节点 10,在其中调用 IP 前缀列表 1,修改AS Path 属性值
 [R1]route-policy hcip permit node 10
 [R1-route-policy] if-match ip-prefix 1
 [R1-route-policy] apply as-path 300 400 additive 【主要增加两个AS】
 [R1-route-policy] quit
 [Rl]route-policy hcip permit node 20
 注意创建一个空节点,对于另外 3 条BGP 路由不执行任何操作。
 #对向 BGP 对等体 R2 通告的 BGP 路应用 Route-Policy
 [R1] bgp 100
 [R1-bgp] peer 10.0.12.2 route-policy hcip export 

3.2 通过修改 Local Preference 属性来影响路径选择
 在 R4 上通过路由策略修改 BGP 路由 172.16.2.0/24 的 Local Preference 属性值,使得 R3 优选R4 通告的 BGP 路由 172.16.2.0/24。
 #创建IP前缀列表1,匹配 BGP 路由 172.16.2.0/24
 [R4] ip ip-prefix 1 permit 172.16.2.0 24 greater-equal 24 less-equal 24
 #创建 Route-Policy hcip,并创建节点 10,在其中调用P 前缀列表 1,修改 Local Preference 属性值
 [R4] route-policy hcip permit node 10
 [R4-route-policy] if-match ip-prefix l
 [R4-route-policy] apply local-preference 200
 [R4-route-policy] quit
 [R4] route-policy hcip permit node 20
 注意创建一个空节点,对于另外 3 条BGP 路由不执行任何操作。
 #对向 BGP 对等体 R3 通告的 BGP 路由应用 Route-Policy
 [R4] bgp 64512
 [R4-bgp] peer 10.0.3.3 route-policy hcip export 

3.3 通过修改 MED 属性来影响路径选择
 在 R2 上通过路由策略修改 BGP 路由 172.16.3.0/24 的 MED 属性值,使得 R3 优选 R5 发布的BGP 路由 172.16.3.0/24。
 #创建IP前缀列表 1,匹配 BGP 路由 172.16.3.0/24
 [R2] ip ip-prefix 1 permit 172.16.3.0 24 greater-equal 24 less-equal 24
 #创建 Route-Policy hcip,并创建节点 10,在其中调用 IP 前缀列表 1修改MED 属性值
 [R2] route-policy hcip permit node 10
 [R2-route-policy] if-match ip-prefix 1
 [R2-route-policy] apply cost 200
 [R2-route-policy] quit
 [R2]route-policy hcip permit node 20
 注意创建一个空节点,对于另外 3 条BGP 路由不执行任何操作。
 #对来自 BGP 对等体 R1的 BGP 路由应用 Route-Policy
 [R2]bgp 64512
 [R2-bgp] peer 10.0.12.1 route-policy hcip import 


3.4 通过修改 preferred-value 属性来影响路径选择
 在 R3上通过路由策略修改 BGP 路由 172.16.4.0/24 的 preferred-value 属性值,使得 R3 优选 R4通告的 BGP 路由 172.16.4.0/24。
 #创建IP前缀列表1,匹配 BGP 路由 172.16.4.0/24
 [R3] ip ip-prefix 1 permit 172.16.4.0 24 greater-equal 24 less-equal 24
 #创建 Route-Policy hcip,并创建节点 10,在其中调用 IP 前缀列表 1,修改 preferred-value 属性值
 [R3]route-policy hcip permit node 10
 [R3-route-policy] if-match ip-prefix 1
 [R3-route-policy] apply preferred-value 300
 [R3-route-policy] quit
 [R3] route-policy hcip permit node 20
 注意创建一个空节点,对于另外 3 条BGP 路由不执行任何操作。
 #对来自 BGP 对等体 R4的 BGP 路由应用 Route-Policy
 [R3]bgp 64512
 [R3-bgp] peer 10.0.4.4 route-policy hcip import