文章目录
- 一、路由器BGP路由的处理过程
- 控制平面和转发平面
- 选路工具
- 二、BGP的选路顺序
- 选路的前提
- 选路顺序
- 三、Local Preference属性选路原则
- Local Preference选路方法
- Local Preference选路时的方向、方式设置
- 直接更改Local Preference值
- 使用route-map更改Local Preference值
- 四、BGP邻居建立配置
一、路由器BGP路由的处理过程
路由器对BGP路由的处理过程,简单来说就是BGP中的选路过程
控制平面和转发平面
一、控制平面 :是从起点到目的地所使用的IGP,BGP等路由协议从而控制产生路由表,VPNV4路由表,标签转发表等,由这些表去控制我们的FIB表,也就是数据转发表
二、转发平面 :也叫做数据平面,根据刚刚产生的路由表,VPNV4路由表,标签转发表从而产生一个数据转发表(FIB表)去进行数据的从起点到目的地的转发,
如图1-1,
选路工具
在 BGP 选路中有两个重要的概念:
一、策略机 : 相当于route-map,能够对属性值进行修改,影响路由表的生成(在控制平面上:是一个过程),从而影响用户的数据转发
①输入策略机:路由进入本地时的route-map,我们可以理解为 in 方向,会影响自身和下游的路由器
②输出策略机:路由离开本地时的route-map,我们可以理解为 out 方向,只会影响下游的路由器,不会影响自身
二、路由决策 : 根据刚刚的策略机(route-map)选择出最佳的路径,并且将最佳的路径添加到路由表中,简单来说就是去哪里,哪条路比较方便或近
如图1-2,就是BGP路由的处理过程
二、BGP的选路顺序
选路的场景主要面对同一个目的网络存在多种去的方式
如图2-1,对于R3来说,去往192.168.10.0/24有去往R1或R2两条路可以选
选路的前提
我们选路的前提是路由的下一跳可达,如果说路由的下一跳不可达的话,那么选路将不具有任何意义
选路顺序
-
我们之前学过的那么多个BGP属性都是能够应用到BGP路由的选路当中的,但是也是存在依照属性进行选路的顺序的,并且如果较为前的属性已经选出最佳路径,那么后面的属性将不会影响到属性
-
例如:路由器已经依照Local Preference选出了最佳的路径,而MED值无论在怎么进行修改都是无济于事的
选路顺序如下
- 优选Weight值较高的;
- 优选Local Preference值较高的;
- 优选AS-Path长度较短的;
- 按照Origin属性为IGP、EGP、Incomplete类型的路由进行选路;(IGP > EGP > Incomplete)
- 优选MED值较小的路由
- 按照EBGP路由,接着是联盟EBGP路由,最后是IBGP路由的顺序
- 优越最近的IGP邻居通告的路由
- 执行等价负载均衡(默认是没有开启等价负载均衡的)
- 优选BGP Router-ID 小的 Peer 通告的路由
- 优选Cluster-list长度较短的路由
- 优选较小的 Peer 地址路由器通告的路由
这么多一串顺序我们将会逐一进行讲解,本文章所分享的是排位第二个的属性,Local Preference属性
讲解Weight属性的文章:【路由交换方向IE认证】BGP选路原则之Weight属性-CSDN博客
三、Local Preference属性选路原则
Local Preference选路方法
1、Loca Preference属性选路的原则为,Local Preference值越大越优先,默认值为100,并且只在IBGP Peer中进行传递
2、当EBGP Peer收到了来自其它 AS 的路由中携带LP属性,则会出发Notifaction报文,即错误通告,最终造成 BGP Peer的会话中断
如图3-1,位于AS 100的R1收到位于AS 200的R2携带Local Preference属性的路由时,R1将会触发Notifaction报文,并且 BGP 的会话也会断开
Local Preference选路时的方向、方式设置
由于Local Preference属性仅在本地 AS 中可以传递的,所以在哪里设置LP值,拥有很多种选择性
将AS 200设置为本公司,如图3-2,拥有三种的方向可以进行设置
- EBGP Peer 的 in 方向
- IBGP 的 in/out 方向
除此之外,我们在配置 route-map 的位置也有多种可能性
- 重分布的时候使用route-map
- IBGP 的 in/out 方向 route-map
- EBGP 的 in 方向上使用 route-map
直接更改Local Preference值
我们可以直接对IBGP Peer的发送固定的LP值,以达到选路的目的
如图3-3,我们将R3发送出去的路由所有的LP值全部都修改为150,使得R4去往1.1.1.1和1.1.2.1都是走R3这条路
在R3上进行配置
R3(config)#router bgp 200
R3(config-router)#bgp default local-preference 150
R3(config-router)#ex
由于BGP更新的时间比较慢,所以要想在R4上看到我们配置的效果,还需要额外地在R4上配置一条命令,进行软刷新的触发
R4>en
R4#clear ip bgp * soft
Reset ALL BGP peers! [yes/no]:yes
R4#show ip bgp
如图3-4,对于R4,1.1.1.1和1.1.2.1下一跳为3.3.3.3的路由LP值都从原来的100修改到了现在的150
并且选路的结果也发生了变化,全部都走3.3.3.3这条路径了,说明我们的配置是成功的
使用route-map更改Local Preference值
由于使用 route-map 的灵活性很大,拥有多种设置的方式和位置,我们以两个案例为主
如图3-5,我们需要控制AS 200出(去AS 100)的路由,可以选择分别是在R2上对R4发出的1.1.2.1这条路由的LP值修改为150,和在R3上对R4发出的1.1.1.1这条路由的LP值修改为150
根据Local Preference属性越大越优先的原则,R4去往1.1.1.1将会走R3这条路,去往1.1.2.1将会走R2这条路
如图3-6,由于选路的本质是属性值的修改,所以我们只要合理地设置属性值的参数,就能达到只更改一台设备,从而实现Local Preference属性的选路
在R3上
R3#en
R3#conf
Enter configuration commands, one per line. End with CNTL/Z.
R3(config)#access-li 10 per 1.1.1.1 0.0.0.0
R3(config)#access-li 20 per 1.1.2.1 0.0.0.0
R3(config)#route-map LP per 10
R3(config-route-map)#mat ip add 10
R3(config-route-map)#set local-pre 150
R3(config-route-map)#ex
R3(config)#route-map LP per 20
R3(config-route-map)#mat ip add 20
R3(config-route-map)#set local-pre 50
R3(config-route-map)#ex
R3(config)#route-map LP per 30
R3(config-route-map)#ex
R3(config)#router bgp 200
R3(config-router)#nei 4.4.4.4 route-map LP out
R3(config-router)#ex
在R4上对BGP路由进行软刷新
R4#en
R4#clear ip bgp * soft
Reset ALL BGP peers! [yes/no]:yes
R4#
如图3-7,在R4上使用show ip bgp 也可以看到路由表上的LocPrf已经发生了变化,并且选路也根据LP属性的原则越大越优先,从而进行了我们的想要的选路
四、BGP邻居建立配置
附上配置过程
R1
Router(config)#hos R1
R1(config)#int g0/0
R1(config-if-GigabitEthernet 0/0)#ip add 12.1.1.1 24
R1(config-if-GigabitEthernet 0/0)#ex
R1(config)#int g0/1
R1(config-if-GigabitEthernet 0/1)#ip add 12.1.2.1 24
R1(config-if-GigabitEthernet 0/1)#ex
R1(config)#int lo0
R1(config-if-Loopback 0)#ip add 1.1.1.1 32
R1(config-if-Loopback 0)#ex
R1(config)#int lo1
R1(config-if-Loopback 1)#ip add 1.1.2.1 32
R1(config-if-Loopback 1)#ip add 1.1.2.1 32
R1(config-if-Loopback 1)#ex
R1(config)#router bgp 100
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#nei 12.1.1.2 remote-as 200
R1(config-router)#nei 12.1.2.3 remote-as 200
R1(config-router)#netw 1.1.1.1 mask 255.255.255.255
R1(config-router)#netw 1.1.2.1 mask 255.255.255.255
R1(config-router)#ex
R2
R2>en
R2#conf
R2(config)#hos R2
R2(config)#int g0/0
R2(config-if-GigabitEthernet 0/0)#ip add 12.1.1.2 24
R2(config-if-GigabitEthernet 0/0)#ex
R2(config)#int g0/1
R2(config-if-GigabitEthernet 0/1)#ip add 12.1.3.2 24
R2(config-if-GigabitEthernet 0/1)#ex
R2(config)#int lo0
R2(config-if-Loopback 0)#ip add 2.2.2.2 32
R2(config-if-Loopback 0)#ex
R2(config)#router ospf 10
R2(config-router)#rou 2.2.2.2
Change router-id and update OSPF process! [yes/no]:yes
R2(config-router)#netw 2.2.2.2 0.0.0.0 area 0
R2(config-router)#netw 12.1.3.0 0.0.0.255 area 0
R2(config-router)#ex
R2(config)#router bgp 200
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#nei 12.1.1.1 remote-as 100
R2(config-router)#nei 4.4.4.4 remote-as 200
R2(config-router)#nei 4.4.4.4 update-sou lo0
R2(config-router)#nei 4.4.4.4 next-hop-self
R2(config-router)#ex
R3
Router>en
Router#conf
Router(config)#hos R3
R3(config)#int g0/0
R3(config-if-GigabitEthernet 0/0)#ip add 12.1.2.3 24
R3(config-if-GigabitEthernet 0/0)#ex
R3(config)#int g0/1
R3(config-if-GigabitEthernet 0/1)#ip add 12.1.4.3 24
R3(config-if-GigabitEthernet 0/1)#ex
R3(config)#int lo0
R3(config-if-Loopback 0)#ip add 3.3.3.3 32
R3(config-if-Loopback 0)#ex
R3(config)#router ospf 10
R3(config-router)#rou 3.3.3.3
Change router-id and update OSPF process! [yes/no]:yes
R3(config-router)#netw 3.3.3.3 0.0.0.0 area 0
R3(config-router)#netw 12.1.4.0 0.0.0.255 area 0
R3(config-router)#ex
R3(config)#router bgp 200
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#nei 12.1.2.1 remote-as 100
R3(config-router)#nei 4.4.4.4 remote-as 200
R3(config-router)#nei 4.4.4.4 update-sou lo0
R3(config-router)#nei 4.4.4.4 next-hop-self
R3(config-router)#ex
R4
R4>en
R4#conf
R4(config)#hos R4
R4(config)#int g0/0
R4(config-if-GigabitEthernet 0/0)#ip add 12.1.3.4 24
R4(config-if-GigabitEthernet 0/0)#ex
R4(config)#int g0/1
R4(config-if-GigabitEthernet 0/1)#ip add 12.1.4.4 24
R4(config-if-GigabitEthernet 0/1)#ex
R4(config)#int lo0
R4(config-if-Loopback 0)#ip add 4.4.4.4 32
R4(config-if-Loopback 0)#ex
R4(config)#int lo1
R4(config-if-Loopback 1)#ip add 4.4.3.4 32
R4(config-if-Loopback 1)#ex
R4(config)#router ospf 10
R4(config-router)#rou 4.4.4.4
Change router-id and update OSPF process! [yes/no]:yes
R4(config-router)#netw 4.4.4.4 0.0.0.0 area 0
R4(config-router)#netw 12.1.3.0 0.0.0.255 area 0
R4(config-router)#netw 12.1.4.0 0.0.0.255 area 0
R4(config-router)#ex
R4(config)#router bgp 200
R4(config-router)#nei 2.2.2.2 remote-as 200
R4(config-router)#nei 2.2.2.2 update-sou lo0
R4(config-router)#nei 3.3.3.3 remote-as 200
R4(config-router)#nei 3.3.3.3 update-sou lo0
R4(config-router)#netw 4.4.4.4 mask 255.255.255.255
R4(config-router)#net 4.4.3.4 mask 255.255.255.255
R4(config-router)#ex