要求:
R1、R2、R3建立IBGP邻居
R4和R2、R3、R5、R6建立EBGP邻居
R7、R5、R6建立IBGP邻居
R7和R1上各有两个环回
R1访问100路由经过R1->R3->R4->R5->R7
R7访问10路由经过R7->R6->R4->R3->R1
在AS 3内为100.0.0.0/24的网段分配Community属性为300:100,为200.0.0.0/24的网段分配Community属性为300:200
在AS 1内为10.0.0.0/24的网段分配Community属性为100:10,为20.0.0.0/24的网段分配Community属性为100:20
首先配置IP
R1
R2
R3
R4
R5
R6
R7
配置邻居关系
R1
[R1]bgp 1
[R1-bgp]group IBGP internal
[R1-bgp]peer IBGP connect-interface LoopBack 0
[R1-bgp]peer 2.2.2.2 group IBGP
[R1-bgp]peer 3.3.3.3 group IBGP
[R1]ip route-static 2.2.2.0 24 12.0.0.2
[R1]ip route-static 3.3.3.0 24 13.0.0.2
R2
[R2]bgp 1
[R2-bgp]group IBGP
[R2-bgp]peer IBGP connect-interface LoopBack 0
[R2-bgp]peer IBGP next-hop-local
[R2-bgp]peer 1.1.1.1 group IBGP
[R2-bgp]peer 3.3.3.3 group IBGP
[R2-bgp]peer 24.0.0.2 as-number 2
[R2]ip route-static 1.1.1.0 24 12.0.0.1
[R2]ip route-static 3.3.3.0 24 12.0.0.1
R3
[R3]bgp 1
[R3-bgp]group IBGP
[R3-bgp]peer IBGP connect-interface LoopBack 0
[R3-bgp]peer IBGP next-hop-local
[R3-bgp]peer 2.2.2.2 group IBGP
[R3-bgp]peer 1.1.1.1 group IBGP
[R3-bgp]peer 34.0.0.2 as-number 2
[R3]ip route-static 1.1.1.0 24 13.0.0.1
[R3]ip route-static 2.2.2.0 24 13.0.0.1
R4
[R4]bgp 2
[R4-bgp]group EBGP external
[R4-bgp]peer EBGP as-number 1
[R4-bgp]peer 24.0.0.1 group EBGP
[R4-bgp]peer 34.0.0.1 group EBGP
[R4-bgp]group EBGP3 external
[R4-bgp]peer EBGP3 as-number 3
[R4-bgp]peer 45.0.0.2 group EBGP3
[R4-bgp]peer 46.0.0.2 group EBGP3
R5
[R5]bgp 3
[R5-bgp]group IBGP
[R5-bgp]peer IBGP connect-interface LoopBack 0
[R5-bgp]peer IBGP next-hop-local
[R5-bgp]peer 7.7.7.7 group IBGP
[R5-bgp]peer 6.6.6.6 group IBGP
[R5-bgp]peer 45.0.0.1 as-number 2
[R5]ip route-static 7.7.7.0 24 57.0.0.2
[R5]ip route-static 6.6.6.0 24 57.0.0.2
R6
[R6]bgp 3
[R6-bgp]group IBGP
[R6-bgp]peer IBGP connect-interface LoopBack 0
[R6-bgp]peer IBGP next-hop-local
[R6-bgp]peer 7.7.7.7 group IBGP
[R6-bgp]peer 5.5.5.5 group IBGP
[R6-bgp]peer 46.0.0.1 as-number 2
[R6]ip route-static 7.7.7.0 24 67.0.0.2
[R6]ip route-static 5.5.5.0 24 67.0.0.2
R7
[R7]bgp 3
[R7-bgp]group IBGP
[R7-bgp]peer IBGP connect-interface LoopBack 2
[R7-bgp]peer 5.5.5.5 group IBGP
[R7-bgp]peer 6.6.6.6 group IBGP
[R7]ip route-static 6.6.6.0 24 67.0.0.1
[R7]ip route-static 5.5.5.0 24 57.0.0.1
导入路由,并设置community属性
R7
[R7]route-policy com permit node 10
[R7-route-policy]if-match interface LoopBack 0
[R7-route-policy]apply community 300:100
[R7]route-policy com permit node 20
[R7-route-policy]if-match interface LoopBack 1
[R7-route-policy]apply community 300:200
[R7]bgp 3
[R7-bgp]import-route direct route-policy com
注意:团体值传递需要打开一个开关才能传递,默认不传递
[R7]bgp 3
[R7-bgp]peer IBGP advertise-community
[R5]bgp 3
[R5-bgp]peer 45.0.0.1 advertise-community
[R5-bgp]peer IBGP advertise-ext-community
[R6]bgp 3
[R6-bgp]peer 46.0.0.1 advertise-community
[R6-bgp]peer IBGP advertise-community
[R4]bgp 2
[R4-bgp]peer EBGP advertise-community
[R4-bgp]peer EBGP3 advertise-community
[R2]bgp 1
[R2-bgp]peer IBGP advertise-community
[R2-bgp]peer 24.0.0.2 advertise-community
[R3]bgp 1
[R3-bgp]peer IBGP advertise-community
[R3-bgp]peer 34.0.0.2 advertise-community
[R1]route-policy com permit node 10
[R1-route-policy]if-match interface LoopBack 1
[R1-route-policy]apply community 100:10
[R1-route-policy]if-match interface LoopBack 2
[R1-route-policy]apply community 100:20
[R1]bgp 1
[R1-bgp]import-route direct route-policy com
[R1-bgp]peer IBGP advertise-community
设置路由策略
使用更改MED方法:
[R4]ip community-filter 100 permit 300:100
[R4]route-policy 100 permit node 10
[R4-route-policy]if-match community-filter 100
[R4-route-policy]apply cost 1
[R4]route-policy 100 permit node 20
[R4]bgp 2
[R4-bgp]peer 45.0.0.2 route-policy 100 import
使用更改preferred-value
[R1]ip community-filter 100 permit 300:100
[R1]route-policy 100 permit node 10
[R1-route-policy]if-match community-filter 100
[R1-route-policy]apply preferred-value 1
[R1]route-policy 100 permit node 20
[R1]bgp 1
[R1-bgp]peer 2.2.2.2 route-policy 100 import
更改local-preference
[R4]ip community-filter 10 permit 100:10
[R4]route-policy 10 permit node 10
[R4-route-policy]if-match community-filter 10
[R4-route-policy]apply local-preference 101
[R4]route-policy 10 permit node 20
[R4-bgp]peer 34.0.0.1 route-policy 10 import
[R7]ip community-filter 10 permit 100:10
[R7]route-policy 10 permit node 10
[R7-route-policy]if-match community-filter 10
[R7-route-policy]apply local-preference 101
[R7]route-policy 10 permit node 20
[R7]bgp 3
[R7-bgp]peer 6.6.6.6 route-policy 10 import