选路原则:

wKioL1LoleDgVJW0AAJ3XfYUqXM352.jpg

研究属性的方向:

1、传播范围  weight 在本地设备上有用

2、默认值    

3、属性取值的优先级

试验拓扑图:

wKioL1LopIXgPGIVAAD13x7hp0Q299.jpg

一、预配

   R1:

   interface s1/0

   ip address 12.1.1.1 255.255.255.0

   no shut

   interface s1/1

   ip address 13.1.1.1 255.255.255.0

   no shut

   interface lo0

   ip address 1.1.1.1 255.255.255.0

   no shut

   R2:

   interface s1/0

   ip address 12.1.1.2 255.255.255.0

   no shut

   interface s1/1

   ip address 24.1.1.2 255.255.255.0

   no shut

   interface lo0

   ip address 2.2.2.2 255.255.255.0

   no shut

   R3:

   interface s1/1

   ip address 13.1.1.3 255.255.255.0

   no shut

   interface f0/0

   ip address 34.1.1.3 255.255.255.0

   no shut

   interface lo0

   ip address 3.3.3.3 255.255.255.0

   no shut

   R4:

   interface s1/1

   ip address 24.1.1.4 255.255.255.0

   no shut

   interface f0/0

   ip address 34.1.1.4 255.255.255.0

   no shut

   interface lo0

   ip address 4.4.4.4 255.255.255.0

   no shut

二、配置IGP路由协议

   R1:

   router ospf 110

   router-id 1.1.1.1

   network 13.1.1.0 0.0.0.255 area 0

   network 1.1.1.0 0.0.0.255 area 0

   R3:

   router ospf 110

   router-id 3.3.3.3

   network 13.1.1.0 0.0.0.255 area 0

   network 3.3.3.0 0.0.0.255 area 0

   network 34.1.1.0 0.0.0.255 area 0

   R4:

   router ospf 110

   router-id 4.4.4.4

   network 4.4.4.0 0.0.0.255 area 0

   network 34.1.1.0 0.0.0.255 area 0

三、配置邻居关系

   R2:

   router bgp 2

   bgp router-id 2.2.2.2

   neighbor 12.1.1.1 remote-as 1

   neighbor 24.1.1.4 remote-as 1

   no synchronization

   no auto-summary

   R1:

   router bgp 1

   bgp router-id 1.1.1.1

   neighbor 12.1.1.2 remote-as 2

   neighbor 3.3.3.3 remote-as 1

   neighbor 3.3.3.3 update-source lo0

   neighbor 3.3.3.3 next-hop-self

   R4:

   router bgp 1

   bgp router-id 4.4.4.4

   neighbor 24.1.1.2 remote-as 2

   neighbor 3.3.3.3 remote-as 1

   neighbor 3.3.3.3 update-source lo0

   neighbor 3.3.3.3 next-hop-self

   R3:

   router bgp 1

   bgp router-id 3.3.3.3

   neighbor 1.1.1.1 remote-as 1

   neighbor 1.1.1.1 update-source lo0

   neighbor 4.4.4.4 remote-as 1

   neighbor 4.4.4.4 update-source lo0

四、通告2.2.2.0/24路由

   R2:

   router bgp 2

   network 2.2.2.0 mask 255.255.255.0

五、在R3上验证选路原则

R3#show ip bgp

BGP table version is 2, local router ID is 3.3.3.3

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete


  Network          Next Hop            Metric LocPrf Weight Path

* i2.2.2.0/24       4.4.4.4                  0    100      0 2 i

*>i                 1.1.1.1                  0    100      0 2 i

呵呵,我们已经保证两条链路的最优,说明现在已经做出了选路结果

我们看下,说明哪个属性做出了选路

R3#show ip bgp 2.2.2.0/24

BGP routing table entry for 2.2.2.0/24, version 2

Paths: (2 available, best #2, table Default-IP-Routing-Table)

 Not advertised to any peer

 2

   4.4.4.4 (metric 1) from 4.4.4.4 (4.4.4.4)

     Origin IGP, metric 0, localpref 100, valid, internal

 2

   1.1.1.1 (metric 1) from 1.1.1.1 (1.1.1.1)

     Origin IGP, metric 0, localpref 100, valid, internal, best

呵呵,好像是RID最小的被选中了。

1、weight 在本机内默认值为32768 其他设备上是0,传递范围是本机

  neighbor 4.4.4.4 weight 1  最简单的添加权值的方法


  修改weight的值,改变选路

  现在让2.2.2.0/24的最优路径在R3上体现为4.4.4.4为下一跳

  R3:

  router bpg 1

  neighbor 4.4.4.4 weight 1

R3(config-router)#do show ip bgp      

BGP table version is 3, local router ID is 3.3.3.3

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete


  Network          Next Hop            Metric LocPrf Weight Path

*>i2.2.2.0/24       4.4.4.4                  0    100      1 2 i

* i                 1.1.1.1                  0    100      0 2 i

现在需求是让下一跳为1.1.1.1的路由最优(在R3上)

分析怎样能实现该目的。连接R3有两条链路,我们可以在接受方向上抓取2.2.2.0/24路由

并加权值为2,可是两条链路我们都可以抓取啊?

做如下策略:

1、做prefix-list抓取相应的条目

  ip prefix-list 2 permit 2.2.2.0/24


2、做route-map

  route-map w permit 10

  match ip address prefix-list 2

  set weight 2

  route-map w permit 20(空语句用来放行其他路由)

3、应用route-map

  neighbor 1.1.1.1 route-map w in

考虑到weight属性只能在本设备内有作用,所以不能做out方向的策略

weight是思科私有的属性


2、local preference

  在IBGP范围中传递

  默认值为100

  越大越优

  告诉IBGP邻居如何离开AS

  一条简单的命令,在该拓扑中,在R1和R4上做

   router bgp 1

   bgp default local-prefecence 111

R3(config-router)#do show ip b    

BGP table version is 7, local router ID is 3.3.3.3

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete


  Network          Next Hop            Metric LocPrf Weight Path

* i2.2.2.0/24       4.4.4.4                  0    100      0 2 i

*>i                 1.1.1.1                  0    111      0 2 i


通过使用route-map实现改变local-preference属性

    R1:

    access-list 1 permit 2.2.2.0 0.0.0.255

    route-map lpf permit 10

    match ip address 1

    set local-preference 111

    route-map lpf permit 20

    router bgp 1

    neighbor 12.1.1.2 route-map lpf in

或者 neighbor 3.3.3.3 route-map lpf out

R1#show ip bgp 2.2.2.0/24

BGP routing table entry for 2.2.2.0/24, version 4

Paths: (1 available, best #1, table Default-IP-Routing-Table)

Flag: 0x800

 Advertised to update-groups:

       2

 2

   12.1.1.2 from 12.1.1.2 (2.2.2.2)

     Origin IGP, metric 0, localpref 111, valid, external, best


3、as path

  传播范围是在所有,但是配置在AS边界路由器上配置,在其他路由器上配置是不起作用的

  为了防止影响EBGP的水平分割,可以将所经过的AS号,重复写就可以了

  例如:2 2 2 2 就可以了

4、MED也就是metric

  传播范围只能在一个AS内

  默认值0

  越小越好

  告诉EBGP邻居怎样进入到本AS


如何解决IBGP的水平分割:要有条件的解决IBGP的水平分割问题,条件就是不能形成环路

1、路由反射器RR

  是典型的c/s 模型,server就是RR

  1、RR从EBGP收到路由

     转发给客户端也会给非客户端

  2、RR从客户端收到路由

     给反射给客户端 EBGP邻居 非客户端

  3、RR从非客户端收到路由

     不会反射给非客户端

  在这里的“条件“就是讲R2和R4之间的链路down掉

  R2:

  interface s1/0

  shutdown

  R4:show ip bgp 就收不到2.2.2.0/24的路由了

  R3:show ip bgp neighbors 4.4.4.4 advertised-routes 没有发送给该路由条目

  我们在R3上做如下命令:

  router bgp 1

  neighbor 1.1.1.1 route-reflector-client

  neighbor 4.4.4.4 route-reflector-client

  就是将R3作为RR,R1和R4做为客户端

  R4:show ip bgp 就可以看到2.2.2.0/24的路由了

 

2、联邦

  思想就是将大的AS分成小的AS

  1、router bgp 小AS号(私有AS号)

  2、声明所在的大AS号

     bgp confederation identifier 1

  3、小AS号之间互指peer

     bgp confederation peers 小AS号


  R1:

  no router bgp 1

  router bgp 64512

  bgp router-id 1.1.1.1

  neighbor 12.1.1.2 remote-as 2

  neighbor 3.3.3.3 remote-as 64512

  neighbor 3.3.3.3 update-source lo0

  neighbor 3.3.3.3 next-hop-self

  bgp confederation identifier 1 指明大的AS号

  R3:

  no router bgp 1

  router bgp 64512

  bgp router-id 3.3.3.3

  neighbor 1.1.1.1 remote-as 64512

  neighbor 1.1.1.1 update-source lo0

  neighbor 4.4.4.4 remote-as 64513

  neighbor 4.4.4.4 update-source lo0

  neighbor 4.4.4.4 ebgp-multihop

  bgp confederation identifier 1

  bgp confederation peers 64513

  R4:

  no router bgp 1

  router bgp 64513

  bgp router-id 4.4.4.4

  neighbor 3.3.3.3 remote-as 64512

  neighbor 3.3.3.3 update-source lo0

  neighbor 3.3.3.3 ebgp-multihop

  bgp confederation identifier 1

  bgp confederation peers 64512

 

我们在R4上做

R4#show ip bgp

*Mar  1 01:18:11.691: %SYS-5-CONFIG_I: Configured from console by console

R4#show ip bgp

BGP table version is 2, local router ID is 4.4.4.4

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete


  Network          Next Hop            Metric LocPrf Weight Path

*> 2.2.2.0/24       1.1.1.1                  0    100      0 (64512) 2 i

R4#show ip bgp 2.2.2.0/24

BGP routing table entry for 2.2.2.0/24, version 2

Paths: (1 available, best #1, table Default-IP-Routing-Table)

 Not advertised to any peer

 (64512) 2

   1.1.1.1 (metric 75) from 3.3.3.3 (3.3.3.3)

     Origin IGP, metric 0, localpref 100, valid, confed-external, best


社团属性:Community,可选的,路由器有可能不识别此属性

         neighbor X.X.X.X send-community 就可以认识该属性

         传递性:社团属性只在neighbor邻居有效

1、no-advertise      

   携带此属性的路由不会通告给任何BGP邻居

   R2:

   ip prefix-list 1 permit 2.2.2.0/24

   route-map com permit 10

   match ip address prefix-list 1

   set community no-advertise

   route-map com permit 20

   router bgp 2

   neighbor 12.1.1.1 route-map com out

   如果就这么多的命令的话:在R1上是看不到该路由的该属性的

   

R1(config-router)#do show ip bgp 2.2.2.0/24

BGP routing table entry for 2.2.2.0/24, version 2

Paths: (1 available, best #1, table Default-IP-Routing-Table)

 Advertised to update-groups:

       2

 2

   12.1.1.2 from 12.1.1.2 (2.2.2.2)

     Origin IGP, metric 0, localpref 100, valid, external, best

    因为R1不识别此属性,如果需要识别的话,在R2上需加这条命令

   neighbor 12.1.1.1 send-community

R1(config-router)#do show ip bgp 2.2.2.0/24

BGP routing table entry for 2.2.2.0/24, version 3

Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to any peer)

Flag: 0x880

 Not advertised to any peer

 2

   12.1.1.2 from 12.1.1.2 (2.2.2.2)

     Origin IGP, metric 0, localpref 100, valid, external, best

     Community: no-advertise

呵呵,在R3上就看不到2.2.2.0/24这条路由了


2、no-export

   携带此属性的路由不会传出大AS

3、Local-AS

   携带此属性的路由不会传出小AS

社团属性是在干涉路由条目的传播范围