路由的权重值,越大越优,在路由器本地配置,只影响本设备的优选,默认为0,从其他bgp对等体学到的默认为0
用于告诉as中的路由器,哪条路径是首选,只能传递给ibgp对等体,不能传递给ebgp对等体
是前往目标网段的路由经过的AS号列表
标识了bgp路由的起源,igp>egp>incomplete
用于向外部对等体指出进入本AS的首选路径
用于指定达到目标网段的下一跳地址
<R5>
#
ospf 1 router-id 5.5.5.5
area 0.0.0.0
network 5.5.5.5 0.0.0.0
network 45.1.1.0 0.0.0.255
#
<R4>
#
ospf 1 router-id 4.4.4.4
area 0.0.0.0
network 4.4.4.4 0.0.0.0
network 34.1.1.0 0.0.0.255
network 45.1.1.0 0.0.0.255
#
<R3>
#
ospf 1 router-id 3.3.3.3
area 0.0.0.0
network 3.3.3.3 0.0.0.0
network 34.1.1.0 0.0.0.255
#
然后R1,R3建立ebgp邻居,R3,R4,R5建立ibgp邻居,R5,R2建立ebgp邻居
<R1>
#
bgp 100
router-id 1.1.1.1
peer 13.1.1.2 as-number 300
#
<R2>
bgp 200
router-id 2.2.2.2
peer 25.1.1.2 as-number 300
<R3>
#
bgp 300
router-id 3.3.3.3
peer 4.4.4.4 as-number 300
peer 4.4.4.4 connect-interface LoopBack0
peer 5.5.5.5 as-number 300
peer 5.5.5.5 connect-interface LoopBack0
peer 13.1.1.1 as-number 100
<R4>
#
bgp 300
router-id 4.4.4.4
peer 3.3.3.3 as-number 300
peer 3.3.3.3 connect-interface LoopBack0
peer 5.5.5.5 as-number 300
peer 5.5.5.5 connect-interface LoopBack0
<R5>
#
bgp 300
router-id 5.5.5.5
peer 3.3.3.3 as-number 300
peer 3.3.3.3 connect-interface LoopBack0
peer 4.4.4.4 as-number 300
peer 4.4.4.4 connect-interface LoopBack0
peer 25.1.1.1 as-number 200
#
<R5> dis bgp pe
BGP local router ID : 5.5.5.5
Local AS number : 300
Total number of peers : 3 Peers in established state : 3
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
3.3.3.3 4 300 109 106 0 01:41:30 Established
2
4.4.4.4 4 300 207 228 0 03:23:48 Established
0
25.1.1.1 4 200 91 90 0 01:28:26 Established
1
<R5>
<R3>dis bgp pe
BGP local router ID : 3.3.3.3
Local AS number : 300
Total number of peers : 3 Peers in established state : 3
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
4.4.4.4 4 300 209 271 0 03:25:50 Established
0
5.5.5.5 4 300 107 111 0 01:42:26 Established
1
13.1.1.1 4 100 102 101 0 01:38:03 Established
2
<R3>
将100.1.1.1引入bgp内,在R4上查看bgp路由表,发现100从3.3.3.3走最优
<R4>dis bgp ro
BGP Local router ID is 4.4.4.4
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 1.1.1.1/32 3.3.3.3 0 100 0 100i
*>i 100.1.1.0/24 3.3.3.3 0 100 0 100i
* i 5.5.5.5 0 100 0 200i
<R4>
我们可以修改preferred-value值来改变路径,在R4上配置
[R4-bgp]peer 5.5.5.5 preferred-value 100
[R4-bgp]dis bgp ro
BGP Local router ID is 4.4.4.4
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 1.1.1.1/32 3.3.3.3 0 100 0 100i
*>i 100.1.1.0/24 5.5.5.5 0 100 100 200i
* i 3.3.3.3 0 100 0 100i
[R4-bgp]
也可以修改local_preference来改变路由优先,在R5上配置
[R5-bgp]default local-preference 200
[R4-bgp]dis bgp ro
BGP Local router ID is 4.4.4.4
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 1.1.1.1/32 3.3.3.3 0 100 0 100i
*>i 100.1.1.0/24 5.5.5.5 0 200 0 200i
* i 3.3.3.3 0 100 0 100i
[R4-bgp]
可以修改AS_path,来改变路由优先,先写一条acl
#
acl number 2000
rule 5 permit source 100.1.1.0 0.0.0.255
[R3]route-policy 1 permit node 10
Info: New Sequence of this List.
[R3-route-policy]if-match acl 2000
[R3-route-policy]apply as-path 20 additive
[R3-route-policy]q
[R3]route-policy 1 pe no 20
Info: New Sequence of this List.
[R3-route-policy]bgp 300
[R3-bgp]peer 4.4.4.4 route-policy 1 export
在R4上看
[R4-bgp]dis bgp ro
BGP Local router ID is 4.4.4.4
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 1.1.1.1/32 3.3.3.3 0 100 0 100i
*>i 100.1.1.0/24 5.5.5.5 0 100 0 200i
* i 3.3.3.3 0 100 0 20 100i
[R4-bgp]
可以修改Origin来改变路由选择,在R1上引入直连
[R1-bgp]im direct
[R4-bgp]dis bgp ro
BGP Local router ID is 4.4.4.4
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 1.1.1.1/32 3.3.3.3 0 100 0 100i
*>i 100.1.1.0/24 5.5.5.5 0 100 0 200i
* i 3.3.3.3 0 100 0 100?
[R4-bgp]
可以看到igp优于incomplete
可以修改med来改变路径选择,在R3上配置
[R3]route-policy 1 permit node 10
Info: New Sequence of this List.
[R3-route-policy]apply cost 100
[R3-route-policy]q
[R3]route-policy 1 permit node 20
Info: New Sequence of this List.
[R3-route-policy]q
[R3]bgp 300
[R3-bgp]peer 13.1.1.1 route-policy 1 import
注意,要比较不同的as的路由,使用compare-different-as-med开启不同as之间的比较
可以看到R4上5.5.5.5的路径优先
[R4-bgp]dis bgp ro
BGP Local router ID is 4.4.4.4
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 1.1.1.1/32 3.3.3.3 100 100 0 100i
*>i 100.1.1.0/24 5.5.5.5 0 100 0 200i
* i 3.3.3.3 100 100 0 100i
[R4-bgp]