BGP选路原则之local preference

简介:

 

我们先做下配置:

R1:interface Serial1/0
 ip address 13.1.1.1 255.255.255.0
 serial restart-delay 0       
interface Serial1/1
 ip address 14.1.1.1 255.255.255.0
 serial restart-delay 0
interface Serial1/2
 ip address 15.1.1.1 255.255.255.0
 serial restart-delay 0
interface Loopback0
 ip address 1.1.1.1 255.255.255.0
router ospf 10
 router-id 1.1.1.1
 log-adjacency-changes
 network 1.1.1.0 0.0.0.255 area 0
 network 13.1.1.0 0.0.0.255 area 0
router bgp 1
 no synchronization
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 neighbor liang peer-group
 neighbor liang remote-as 2
 neighbor liang ebgp-multihop 255
 neighbor liang update-source Loopback0
 neighbor 3.3.3.3 remote-as 1
 neighbor 3.3.3.3 update-source Loopback0
 neighbor 3.3.3.3 next-hop-self
 neighbor 4.4.4.4 peer-group liang
 neighbor 5.5.5.5 peer-group liang
 no auto-summary
ip route 4.4.4.4 255.255.255.255 14.1.1.4
ip route 5.5.5.5 255.255.255.255 15.1.1.5
R2:

interface Loopback0
 ip address 2.2.2.2 255.255.255.0

interface Serial1/0
 ip address 24.1.1.2 255.255.255.0
 serial restart-delay 0        
interface Serial1/1
 ip address 23.1.1.2 255.255.255.0
 serial restart-delay 0
interface Serial1/2
 no ip address
 shutdown
 serial restart-delay 0
inteface Serial1/3
 ip address 25.1.1.2 255.255.255.0
 serial restart-delay 0
router ospf 10
 router-id 2.2.2.2
 log-adjacency-changes
 network 2.2.2.0 0.0.0.255 area 0
 network 23.1.1.0 0.0.0.255 area 0
router bgp 1
 no synchronization
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 neighbor liang peer-group     为了简化配置我们用peer-group
 neighbor liang remote-as 2
 neighbor liang ebgp-multihop 255
 neighbor liang update-source Loopback0
 neighbor 3.3.3.3 remote-as 1
 neighbor 3.3.3.3 update-source Loopback0
 neighbor 3.3.3.3 next-hop-self
 neighbor 4.4.4.4 peer-group liang
 neighbor 5.5.5.5 peer-group liang
 no auto-summary
ip route 4.4.4.4 255.255.255.255 24.1.1.4
ip route 5.5.5.5 255.255.255.255 25.1.1.5

R3:

interface Loopback0
 ip address 3.3.3.3 255.255.255.0
interface Serial1/0
 ip address 13.1.1.3 255.255.255.0
 serial restart-delay 0       
interface Serial1/1
 ip address 23.1.1.3 255.255.255.0
 serial restart-delay 0
router ospf 10
 router-id 3.3.3.3
 log-adjacency-changes
 network 3.3.3.0 0.0.0.255 area 0
 network 13.1.1.0 0.0.0.255 area 0
 network 23.1.1.0 0.0.0.255 area 0
router bgp 1
 no synchronization
 bgp router-id 3.3.3.3
 bgp log-neighbor-changes
 neighbor 1.1.1.1 remote-as 1
 neighbor 1.1.1.1 update-source Loopback0
 neighbor 2.2.2.2 remote-as 1
 neighbor 2.2.2.2 update-source Loopback0
 no auto-summary

其他的配置都差不多不在贴出来了

我们看下BGP表

R1#show ip bgp
BGP table version is 3, local router ID is 1.1.1.1
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
*  6.6.6.0/24       4.4.4.4                                0 2 i
*>                  5.5.5.5                                0 2 i
*  8.8.8.0/24       5.5.5.5                                0 2 i
*>                  4.4.4.4                                0 2 i

R2#show ip bgp
BGP table version is 3, local router ID is 2.2.2.2
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
*  6.6.6.0/24       4.4.4.4                                0 2 i
*>                  5.5.5.5                                0 2 i
*  8.8.8.0/24       5.5.5.5                                0 2 i
*>                  4.4.4.4                                0 2 i

R3#   show ip bgp
BGP table version is 9, 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
* i6.6.6.0/24       2.2.2.2                  0    100      0 2 i
*>i                 1.1.1.1                  0    100      0 2 i
* i8.8.8.0/24       2.2.2.2                  0    100      0 2 i
*>i                 1.1.1.1                  0    100      0 2 i

发现R3到6.6.6.0和8.8.8.0 下一跳都是R1

我们的要求是R3访问6.6.6.0/24 走R1 R4 访问8.8.8.0/24走R2 R5

第一种方式我们在R1 R2的out方向做

R1

access-list 1 permit 6.6.6.0
access-list 2 permit 8.8.8.0
route-map to-r3 permit 10
 match ip address 1
 set local-preference 400
route-map to-r3 permit 20
 match ip address 2
 set local-preference 300
route-map to-r3 permit 30
R1(config)#router bgp 1
R1(config-router)#neighbor 3.3.3.3 route-map to-r3

R2


access-list 1 permit 6.6.6.0
access-list 2 permit 8.8.8.0
route-map to-r3 permit 10
 match ip address 1
 set local-preference 300
route-map to-r3 permit 20
 match ip address 2
 set local-preference 400
R2(config)#router bgp 1
R2(config-router)#neighbor 3.3.3.3 route-map to-r3 out

我们需要的R3上软清下

R3#clear ip bgp * soft
R3#   show ip bgp     
BGP table version is 12, 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
* i6.6.6.0/24       2.2.2.2                  0    300      0 2 i
*>i                 1.1.1.1                  0    400      0 2 i
*>i8.8.8.0/24       2.2.2.2                  0    400      0 2 i
* i                 1.1.1.1                  0    300      0 2 i
 

发现第一跳确实变了,但我们看下R2 R1的BGP表

R1#show ip bgp
BGP table version is 3, local router ID is 1.1.1.1
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
* 6.6.6.0/24 4.4.4.4 0 2 i
*> 5.5.5.5 0 2 i
* 8.8.8.0/24 5.5.5.5 0 2 i
*> 4.4.4.4 0 2 i

R2#show ip bgp   直接走R4了 还不是我们想要的要求
BGP table version is 3, local router ID is 2.2.2.2
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
* 6.6.6.0/24 4.4.4.4         0 2 i        
*> 5.5.5.5 0 2 i
* 8.8.8.0/24 5.5.5.5 0 2 i
*> 4.4.4.4 0 2 i

我们只是控制了R3到R1R2的选路

我们在R3 R4的in方向做

R1

access-list 1 permit 6.6.6.0
route-map liang permit 10
 match ip address 1
 set local-preference 500
route-map liang permit 20
neighbor 4.4.4.4 route-map liang in

R2

access-list 1 permit 8.8.8.0
route-map liang permit 10
 match ip address 1
 set local-preference 500
route-map liang permit 20
neighbor 5.5.5.5 route-map liang in

软清一下在R1 R2  R3

R1#show ip bgp
BGP table version is 4, local router ID is 1.1.1.1
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
*> 6.6.6.0/24       4.4.4.4                       500      0 2 i
*                   5.5.5.5                                0 2 i
*  8.8.8.0/24       5.5.5.5                                0 2 i
*>                  4.4.4.4                                0 2 i

R2#show ip bgp
BGP table version is 4, local router ID is 2.2.2.2
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
*  6.6.6.0/24       4.4.4.4                                0 2 i
*>                  5.5.5.5                                0 2 i
*> 8.8.8.0/24       5.5.5.5                       500      0 2 i
*                   4.4.4.4                                0 2 i

R3#   show ip bgp
BGP table version is 17, 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
* i6.6.6.0/24       2.2.2.2                  0    100      0 2 i
*>i                 1.1.1.1                  0    500      0 2 i
*>i8.8.8.0/24       2.2.2.2                  0    500      0 2 i
* i                 1.1.1.1                  0    100      0 2 i

我们的目的达到了!

总结:

loacl preference 有三种不同的方法进行配置
1.通过IGP路由引入BGP是关联route-map
2.针对IBGP peer 应用in and out 方向进行配置,对从peer收到或者通过的给peer的所有或部分进行设置
3.针对EBGP peer 应用in 方向的route-map针对peer接受到的所有或部分路由进行设置



本文转自q狼的诱惑 51CTO博客,原文链接:http://blog.51cto.com/liangrui/557941,如需转载请自行联系原作者

相关文章
|
2月前
|
存储 负载均衡 网络协议
Cisco-动态路由(EIGRP)
Cisco-动态路由(EIGRP)
|
网络协议 数据安全/隐私保护
ip-prefix在OSPF和BGP中路由过滤的应用举例。
ip-prefix,路由过路在ospf和bgp中的应用。
6579 0
|
网络架构 网络协议 Shell
|
网络协议 网络架构 数据库