BGP的选路
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BGP的选路相关的知识,希望对你有一定的参考价值。
一、实验要求:
1、AS1去AS2走R2
2、AS2去AS1走R4
3、AS1去AS3走R6
4、AS2去AS3走R6
5、AS3去AS2走R5
6、AS3去AS1走R5
7、每个选路规则只能使用一次
解决以上步骤的选路方法(事先没有规划):
1、local-preference
2、MED
3、Weight
4、Origin
5、AS-path
6、next-hop
二、BGP的选路规则:
1、weight,范围0-65535,默认为0或32768,大优;
2、Local-preference,范围0-65535,大优;
3、本地起源,起源与本地最优先;
4、As-path,经过AS的数量越少越忧,并且EBGP邻居可添加AS的数量;
5、起源码小忧,i-igp=0,e-egp=1,?-incomplete=2;
6、MED,小优;
7、EBGP路由优于IBGP路由,联邦EBGP与普通IBGP不能使用该条进行比较,此时联邦EBGP路由与IBGP相同;
8、最近的IGP邻居,iIGP的metric最小的优;
9、如果配置了maximum-path [ibgp]n,如果存在多条等价路径,会同时加载到路由表;
10、最老的路由,前提必须是external路由,联邦内的EBGP路由当做IBGP 处理;
11、最小的router-id优;
12、多条路径的router-id相同,那么选择cluster-list长度最短的;
13、BGP优选来自最低邻居IP地址的路由,BGP neighbor配置的那个IP地址。
三、配置:
R1#sho run | s pre
ip prefix-list AS2 seq 5 permit 3.3.3.0/24
ip prefix-list AS2 seq 10 permit 4.4.4.0/24
route-map AS2 permit 10
match ip address prefix-list AS2
set local-preference 80 //解决第一步是用的是local-preference
R1#sho run | s bgp
router bgp 1
bgp log-neighbor-changes
network 1.1.1.0 mask 255.255.255.0
network 1.1.1.1 mask 255.255.255.255
neighbor 2.2.2.2 remote-as 1
neighbor 2.2.2.2 update-source Loopback0
neighbor 2.2.2.2 next-hop-self
neighbor 100.1.13.3 remote-as 2
neighbor 100.1.13.3 route-map AS2 in
R2#sho run | s pre
ip prefix-list AS3 seq 5 permit 6.6.6.0/24
ip prefix-list AS3 seq 10 permit 7.7.7.0/24
ip prefix-list AS3 seq 15 permit 5.5.5.0/24
route-map AS3 permit 10
match ip address prefix-list AS3
set weight 10 //解决第三步用的是weight
R2#sho run | s bgp
router bgp 1
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 1.1.1.1 next-hop-self
neighbor 100.1.24.4 remote-as 2
neighbor 100.1.25.5 remote-as 3
neighbor 100.1.26.6 remote-as 3
neighbor 100.1.26.6 route-map AS3 in
R3#sho run | s pre
ip prefix-list AS1 seq 5 permit 1.1.1.0/24
ip prefix-list AS1 seq 10 permit 2.2.2.0/24
route-map AS1 permit 10
match ip address prefix-list AS1
set metric 100 //解决第二步用的是MED
R3#sho run | s bgp
router bgp 2
bgp log-neighbor-changes
network 3.3.3.0 mask 255.255.255.0
neighbor 4.4.4.4 remote-as 2
neighbor 4.4.4.4 update-source Loopback0
neighbor 4.4.4.4 next-hop-self
neighbor 100.1.13.1 remote-as 1
neighbor 100.1.13.1 route-map AS1 in
R4#sho run | s pre
ip prefix-list AS3 seq 5 permit 5.5.5.0/24
ip prefix-list AS3 seq 10 permit 6.6.6.0/24
ip prefix-list AS3 seq 15 permit 7.7.7.0/24
route-map AS3 permit 10
match ip address prefix-list AS3
set origin incomplete //解决第四步用的是origin
R4#sho run | s bgp
router bgp 2
bgp log-neighbor-changes
network 4.4.4.0 mask 255.255.255.0
neighbor 3.3.3.3 remote-as 2
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 100.1.24.2 remote-as 1
neighbor 100.1.45.5 remote-as 3
neighbor 100.1.45.5 route-map AS3 in
neighbor 100.1.46.6 remote-as 3
R5#sho run | s bgp
router bgp 3
bgp log-neighbor-changes
network 5.5.5.0 mask 255.255.255.0
neighbor 6.6.6.6 remote-as 3
neighbor 6.6.6.6 update-source Loopback0
neighbor 6.6.6.6 next-hop-self
neighbor 7.7.7.7 remote-as 3
neighbor 7.7.7.7 update-source Loopback0
neighbor 7.7.7.7 next-hop-self
neighbor 100.1.25.2 remote-as 1
neighbor 100.1.45.4 remote-as 2
R6#sho run | s prefix-list AS1
ip prefix-list AS1 seq 5 permit 1.1.1.0/24
ip prefix-list AS1 seq 10 permit 2.2.2.0/24
route-map AS1 permit 10
match ip address prefix-list AS1
set as-path prepend 1 //第五步用的是as-path
R6#sho run | s prefix-list AS2
ip prefix-list AS2 seq 5 permit 3.3.3.0/24
ip prefix-list AS2 seq 10 permit 4.4.4.0/24
route-map AS2 permit 10
match ip address prefix-list AS2
set ip next-hop 5.5.5.5 //第六步用的是next-hop
R6#SHO run | s bgp
router bgp 3
bgp log-neighbor-changes
network 6.6.6.0 mask 255.255.255.0
neighbor 5.5.5.5 remote-as 3
neighbor 5.5.5.5 update-source Loopback0
neighbor 5.5.5.5 next-hop-self
neighbor 7.7.7.7 remote-as 3
neighbor 7.7.7.7 update-source Loopback0
neighbor 7.7.7.7 next-hop-self
neighbor 100.1.26.2 remote-as 1
neighbor 100.1.26.2 route-map AS1 in
neighbor 100.1.46.4 remote-as 2
neighbor 100.1.46.4 route-map AS2 in
//在第六步,R6去AS2,没有使用next-hop时,加表并优的是R4,加表不优的是R5,由于使用了next-hop,
加表并优的路由变成R5,所以才会看到BGP表中R6去AS2的优和不优的加表路由都成了R5。但实验结果能过达到要求。
R6#traceroute 3.3.3.3 source 6.6.6.6 numeric
Type escape sequence to abort.
Tracing the route to 3.3.3.3
VRF info: (vrf in name/id, vrf out name/id)
1 100.1.56.5 0 msec 1 msec 0 msec
2 100.1.45.4 0 msec 1 msec 0 msec
3 100.1.34.3 1 msec * 1 msec
//测验结果正确,能满足第六步要求
R7#sho run | s bgp
router bgp 3
bgp log-neighbor-changes
network 7.7.7.0 mask 255.255.255.0
neighbor 5.5.5.5 remote-as 3
neighbor 5.5.5.5 update-source Loopback0
neighbor 5.5.5.5 next-hop-self
neighbor 6.6.6.6 remote-as 3
neighbor 6.6.6.6 update-source Loopback0
neighbor 6.6.6.6 next-hop-self
注意:
本实验的第六步选路方案虽实现了要求,但选路方案并不佳。所以,实验前应对实验中所要用到的选路规则进行推演,以便选出最好的选路方案。
以上是关于BGP的选路的主要内容,如果未能解决你的问题,请参考以下文章