BGP十三条选路---实验(上)

十三条选路原则

  1. 权重weight
  2. 本地优先级(Local Preference)——AS内部传递,默认100,越大越优
  3. 优选本地始发路由(相信自己)——后面举例说明
  4. AS-path(越小越优)——学习到该条目经过多少AS区域
  5. 起源属性oragin(i---IGP学习到的、e---EBGP学习到的、?重复发进来的)(优先级:i>e>?)---可修改
  6. MED多出口鉴别器(邻居一跳AS内传递)
  7. EBGP(200)路由优于IBGP(20)路由——一般不会有这种情况
  8. BGP优选到下一跳IGP度量值低的
  9. 执行等价负载均衡---默认1:最多16\需要配置
  10. 优选最古老的路由
  11. 比较EBGP邻居的RID(越小越优)
  12. cluster-list 长度、越短越优
  13. 优选最小的邻居地址的路由

    基本配置模板(本实验使用GNS3模拟器)

    BGP十三条选路---实验(上)

    这里EGP使用物理口相互建立邻居,IGP使用环回口建立邻居
    物理口建立邻居不需要学习到对方的环回口----方便
    环回口建立邻居比较稳定---稳定(只要还要一个物理口为up则一直为up)

    命令:

    R1:

    //需注意是从用户模式开始配置的
    en
    conf t
    hostname R1
    int lo1
    ip add 1.1.1.1 255.255.255.255
    no sh
    int f0/0
    ip add 12.1.1.1 255.255.255.0
    no sh
    int f1/0
    ip add 24.1.1.1 255.255.255.0
    no sh
    router bgp 100
    bgp router-id 1.1.1.1
    nei 12.1.1.2 remote-as 1
    nei 24.1.1.3 remote-as 1
    net 1.1.1.1 mask 255.255.255.255  //必须与路由表中的相一致
    exit
    do wr   //保存配置,方便后续实验

R2:

en
conf t
hostname R2
int f0/0
ip add 12.1.1.2 255.255.255.0
no sh
exit
int lo1
ip add 2.2.2.2 255.255.255.255
no sh
exit
int f1/0
ip add  32.1.1.2 255.255.255.0
no sh
exit
router bgp 1
bgp router-id 2.2.2.2
nei 12.1.1.1 remote-as 100
nei 4.4.4.4 remote-as 1
nei 4.4.4.4 update-source lo1  //修改更新源---默认互联物理口(即TCP报文从那里发出去)
nei 4.4.4.4 next-hop-self      //大家可以试试不加这条命令
exit
router eigrp 100
net 12.1.1.0 0.0.0.255
net 32.1.1.0 0.0.0.255
net 2.2.2.2 0.0.0.0  //为了后面IGP邻居能够建立起邻居
exit
IGP学习到外部EBGP的路由,原封不动发送给IGP邻居的,如果不指定下一跳,则会导致不是最优(也去不了)R2去R1环回口默认是直接发送给R1,而R3根本不可能直接发送给R1。(连接不同AS路由器上做)

R4:

en
conf t
hostname R4
int f0/0
ip add 32.1.1.4 255.255.255.0
no sh
exit
int lo0
ip add 11.11.11.11 255.255.255.255
no sh
int lo1
ip add 4.4.4.4 255.255.255.255
no sh
exit
int s2/0
ip add  52.1.1.4 255.255.255.255
no sh
exit
router bgp 1
bgp router-id 4.4.4.4
nei 2.2.2.2 remote-as 1
nei 2.2.2.2 update-source lo1
nei 3.3.3.3 remote-as 1
nei 3.3.3.3 update-source lo1
exit
router eigrp 100
net 32.1.1.0 0.0.0.255
net 4.4.4.0 0.0.0.255
net 52.1.1.0 0.0.0.255
exit

R3:

en
conf t
hostname R3
int f0/0
ip add  24.1.1.3 255.255.255.0
no sh
exit
int lo1
ip add 3.3.3.3 255.255.255.255
no sh
exit
int s2/0
ip add 52.1.1.3 255.255.255.0
no sh
exit
router bgp 1
bgp router-id 3.3.3.3
nei 24.1.1.1 remote-as 100
nei 4.4.4.4 remote-as 1
nei 4.4.4.4 next-hop-self
nei 4.4.4.4 update-source lo1
exit
router eigrp 100
net 52.1.1.0 0.0.0.255
net 3.3.3.3 0.0.0.0
net 24.1.1.0 0.0.0.255
exit
do wr

(大家要看看R4的s2/0起来没有,我这边就是要多打一边)--
我们可以看到R4通过学习到R1的1.1.1.1的路由,最优的()是
>i1.1.1.1/32 2.2.2.2


一、权重Weight(cisco私有)

传播范围:本路由内(不可传递)
缺省值:本路由器=32768,其他=0

两种配置方法:

    1. OSFP内配置 针对邻居
    1. route-map 针对条目

拓扑图

BGP十三条选路---实验(上)

第一种:

现在R4去往1.1.1.1走的是R2,我们来对它进行修改,使其走向R3

   Network          Next Hop            Metric LocPrf Weight Path
*>i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
* i                        3.3.3.3                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i

R4:

//用户模式开始
en
conf t
router bgp 1
neighbor 3.3.3.3 weight 100 //将邻居3.3.3.3发送的条目权重值改为100
记得在特权模式下软清一下:clear ip bgp * so
————————————————————————————————————————————————————————————————————————————————————————————
可以看到确实是走R3了
   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                      3.3.3.3                  0    100    100 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i

确实是很方便,但是会导致什么情况呢!

大家看我在R1再宣告一条路由
en
conf t
int lo2
ip add 8.8.8.8 255.255.255.255
no sh
exit
router bgp 100
net 8.8.8.8 mask 255.255.255.255

再看R4的BGP路由表
   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                 3.3.3.3                  0    100    100 100 i
*>i8.8.8.8/32       3.3.3.3                  0    100    100 100 i
* i                 2.2.2.2                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i
还是走R3--就有点不太灵活了!

Weight第二种

利用前缀列表或access-list抓取相应的条目
R4:

en
conf t
access-list 10 permit 1.1.1.1 //抓取对应的条目
route-map Weight permit //route-map来修改权重
            match ip address 10 //绑定我们写好的ACL列表
            set weight 100
            exit
router bgp 1
neighbor 3.3.3.3 route-map Weight in //接收方向调用

//这样我们可以看到只有R3传过来的1.1.1.1 才会加100weight
   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                      3.3.3.3                  0    100    100 100 i
*>i8.8.8.8/32       2.2.2.2                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i

本地优先级(Local Preference)

传播范围:AS内进行传播
缺省值:100
比较方式:越大越优
BGP十三条选路---实验(上)
同样R4去往1.1.1.1 走R3

第一种(修改本地默认优先级)

R3:

//用户模式开始配置
en
conf t
router bgp 1
bgp default locall-preference 110
//软清理一下
R3#clear ip bgp * so
//没有so则硬清,生产环境不要硬清

R4上查看:


   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                      3.3.3.3                  0    110      0 100 i
*>i8.8.8.8/32       3.3.3.3                  0    110      0 100 i
* i                          2.2.2.2                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i
//确实是可以,与上面情况一致,不太灵活

第二种(in/out修改)

IN方向

R4:

//用户模式开始配置
en
conf t
access-list 10 permit 1.1.1.1 //抓取路由条目
route-map Local permit
            match ip address 10  //与ACL相绑定
            set local-preference 110 //修改本地优先级
            exit
router bgp 1
neighbor 3.3.3.3 route-map Local in  //in方向进行调用

查看R4 BGP路由表

   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                      3.3.3.3                  0    110      0 100 i
*>i8.8.8.8/32       2.2.2.2                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i
我们看到只有3.3.3.3发出来的条目1.1.1.1被加上*>和对应的本地优先级

OUT方向

R3:

//用户模式开始配置
en
conf t
ip prefix-list Local-out permit 1.1.1.1/32  //前缀列表抓取条目
route-map Local-out permit  
                    match ip address prefix-list Local-out  //绑定前缀列表
                    set local-preference 120  //修改BGP本地优先级
                    exit
router bgp 1
nei 4.4.4.4 route-map Local-out out //out方向调用

R4 BGP路由:

   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                      3.3.3.3                  0     120      0 100 i
*>i8.8.8.8/32       2.2.2.2                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i

BGP十三条选路---实验(上)

优选本地始发的路由(看现象)

R1上看去往1.1.1.1下一跳是不是0.0.0.0

做个小案例:
R4:

//用户模式开始配置
//R4去往1.1.1.1 这个路由一般走R2或R3
en
conf t
ip route 1.1.1.1 255.255.255.255 null 0
router bgp 1
net 1.1.1.1 mask 255.255.255.255
exit
do sh ip bgp
//相信自己,将Next Hop改为自己0.0.0.0
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       0.0.0.0                  0         32768 i

AS-path(越短越优)

如果收到本区域的AS则丢弃
边界路由器上做,针对对方IGP内
R1:

en
conf t
access-list 10 permit 1.1.1.1
route-map AS-Path
                match ip address 10
              set as-path prepend 2 4 5 6 7 8 
                exit
router bgp 1
                neighbor 12.1.1.2 route-map AS-Path out 

如果收到本区域内的AS

R1:

en
conf t
access-list 10 permit 1.1.1.1
route-map AS-Path
                match ip address 10
              set as-path prepend 1 2 4 5 6 7 8 
                exit
router bgp 1
                neighbor 12.1.1.2 route-map AS-Path out 

R2直接就丢弃了(气死我了)

强制要求R2接收(嘿嘿)
BGP十三条选路---实验(上)
R2-in方向:

//用户模式配置
en
conf t
router bgp 1
            neighbor 12.1.1.1 allowas-in

再来查看R2的BGP路由表:
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       12.1.1.1                 0             0 100 1 2 3 4 5 6 7 8 i
*>i11.11.11.11/32   4.4.4.4                  0    100      0 i

限制AS

//用户模式配置
en
conf t
router bgp 1
        bgp maxas-limit [数量]
        R5(config-router)#bgp bestpath as-path ignore //忽略AS-path

猜你喜欢

转载自blog.51cto.com/15080497/2587052