实验拓扑
实验需求
更改BGP路由的属性让R4访问R1优先选R2这条路
实验步骤
1. 按照图示配置IP地址及环回口地址
R1
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 10.1.12.1 24
[R1-GigabitEthernet0/0/2]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 10.1.13.1 24.
[R1-GigabitEthernet0/0/1]int lo0
[R1-LoopBack0]ip add 1.1.1.1 32
R2
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 10.1.12.2 24
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]ip add 10.1.24.2 24
R3
R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip add 10.1.13.3 24
[R3-GigabitEthernet0/0/0]int g0/0/1
[R3-GigabitEthernet0/0/1]ip add 10.1.34.3 24
R4
[R4]int g0/0/0
[R4-GigabitEthernet0/0/0]ip add 10.1.34.4 24
[R4-GigabitEthernet0/0/0]int g0/0/1
[R4-GigabitEthernet0/0/1]ip add 10.1.24.4 24
2. 配置BGP并建立邻居
R1
[R1]bgp 100
[R1-bgp]peer 10.1.12.2 as-number 200
[R1-bgp]peer 10.1.13.3 as-number 100
R2
[R2]bgp 200
[R2-bgp]peer 10.1.12.1 as-number 100
[R2-bgp]peer 10.1.24.4 as-number 300
R3
[R3]bgp 100
[R3-bgp]peer 10.1.13.1 as-number 100
[R3-bgp]peer 10.1.34.4 as-number 300
R4
[R4]bgp 300
[R4-bgp]peer 10.1.24.2 as-number 200
[R4-bgp]peer 10.1.34.3 as-number 100
3. 在R1上查看邻居状态
[R1]dis bgp peer
BGP local router ID : 10.1.12.1
Local AS number : 100
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
10.1.12.2 4 200 3 4 0 00:01:39 Established 0
10.1.13.3 4 100 2 3 0 00:00:49 Established 0
4.在R4上查看邻居状态
[R4-bgp]dis bgp peer
BGP local router ID : 10.1.34.4
Local AS number : 300
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
10.1.24.2 4 200 2 2 0 00:00:11 Established 0
10.1.34.3 4 100 2 2 0 00:00:02 Established 0
5.将R1的环回口宣告进BGP,并在R4上查看路由的走向
此时对BGP路由属性没有做任何修改
[R1-bgp]net 1.1.1.1 32
[R4-bgp]dis bgp routing-table
BGP Local router ID is 10.1.34.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: 2
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 1.1.1.1/32 10.1.34.3 0 100i
* 10.1.24.2 0 200 100i
6.配置BGP的团体属性让路由优先走10.1.24.2
在R1上对走向R2、R3的路由增加一个团体属性,并开启团体属性通告(默认没有开启)
[R1]route-policy 123 permit node 10
[R1-route-policy]apply community 100:1
[R1]route-policy 321 permit node 10
[R1-route-policy]apply community 100:2
[R1-bgp]peer 10.1.12.2 route-policy 123 export
[R1-bgp]peer 10.1.13.3 route-policy 321 export
[R1-bgp]peer 10.1.13.3 advertise-community
[R1-bgp]peer 10.1.12.2 advertise-community
7. 在R2和R3上开启团体属性通告
[R2-bgp]peer 10.1.24.4 advertise-community
[R3-bgp]peer 10.1.34.4 advertise-community
8. 在R4上匹配R1上团体属性,并调用route-policy匹配规则
团体属性匹配上100:1的路由优先级更改为210,团体属性匹配上100:2的路由优先级更改为30,在BGP的进口上调用route-policy
[R4]ip community-filter 1 permit 100:1
[R4]ip community-filter 2 permit 100:2
[R4]route-policy 111 permit node 10
[R4-route-policy]if-match community-filter 1
[R4-route-policy]apply local-preference 210
[R4]route-policy 111 permit node 20
[R4-route-policy]if-match community-filter 2
[R4-route-policy]apply local-preference 30
[R4]bgp 300
[R4-bgp]peer 10.1.24.2 route-policy 111 import
[R4-bgp]peer 10.1.34.3 route-policy 111 import
9. 在R4上查看到团体属性配置
[R4]dis bgp routing-table community
BGP Local router ID is 10.1.34.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: 2
Network NextHop MED LocPrf PrefVal Community
*> 1.1.1.1/32 10.1.24.2 210 0 <100:1>
* 10.1.34.3 30 0 <100:2>
10. 在R4上查看BGP 路由表,发现R4到R1的已优先走10.1.24.2,配置已生效
[R4]dis bgp routing-table
BGP Local router ID is 10.1.34.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: 2
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 1.1.1.1/32 10.1.24.2 210 0 200 100i
* 10.1.34.3 30 0 100i
个人小结:
公认属性:所有BGP路由器都必须识别并支持的属性。
公认必遵:BGP的Update消息中必须包含的属性。
公认任意:不必存在于BGP的Update消息中,可以根据需求*选择的属性。
可选属性:不要求所有的BGP路由器都能够识别的属性。
可选过渡:BGP不能识别该属性,但可以接收该属性并将其发布给它的邻居的属性。
可选非过渡:BGP可以忽略包含该属性的消息并且不向它的邻居发布。
BGP属性 - Origin
Origin的3种属性:
i表明BGP路由通过network命令注入;
e表明BGP路由是从EGP学来的,EGP协议在现网中很难见到,但可以通过路由策略将路由的Origin属性修改为e;
? 即Incomplete表明BGP路由通过其它方式学到路由信息,如使用import命令引入的路由。
3种Origin属性的优先级为:i>e>Incomplete(?)。
BGP属性 - Community (团体属性)
0-65535
NO_export 收到此属性的路由后,不将该路由发布到其他AS
NO_advertise 收到此属性的路由后,不将该路由通告给任何其他的BGP邻居
NO_export_ subconfed 不传给其他人以外也不传给联盟的AS