1.建立BGP邻居关系
R1配置
[r1]bgp 64512
[r1-bgp]router-id 1.1.1.1
[r1-bgp]confederation id 100
[r1-bgp]confederation peer-as 64513
[r1-bgp]confederation peer-as 64514
[r1-bgp]peer 15.1.1.2 as-number 64514
[r1-bgp]peer 2.2.2.2 as-number 64513
[r1-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[r1-bgp]peer 2.2.2.2 ebgp-max-hop
[r1-bgp]import-route direct
R2配置
[r2]bgp 64513
[r2-bgp]router-id 2.2.2.2
[r2-bgp]confederation id 100
[r2-bgp]confederation peer-as 64512
[r2-bgp]peer 1.1.1.1 as-number 64512
[r2-bgp]peer 1.1.1.1 connect-interface LoopBack 0
[r2-bgp]peer 1.1.1.1 ebgp-max-hop
[r2-bgp]peer 3.3.3.3 as-number 64513
[r2-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[r2-bgp]peer 3.3.3.3 next-hop-local
R3配置
[r3]bgp 64513
[r3-bgp]router-id 3.3.3.3
[r3-bgp]confederation id 100
[r3-bgp]peer 2.2.2.2 as-number 64513
[r3-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[r3-bgp]peer 4.4.4.4 as-number 64513
[r3-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[r3-bgp]peer 2.2.2.2 reflect-client
[r3-bgp]peer 4.4.4.4 reflect-client
R4配置
[r4]bgp 64513
[r4-bgp]router-id 4.4.4.4
[r4-bgp]confederation id 100
[r4-bgp]peer 3.3.3.3 as-number 64513
[r4-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[r4-bgp]peer 49.1.1.2 as-number 102
[r4-bgp]peer 3.3.3.3 next-hop-local
[r4-bgp]peer 48.1.1.2 as-number 101
[r4-bgp]import-route direct
R9上配置
[r9]bgp 102
[r9-bgp]router-id 9.9.9.9
[r9-bgp]peer 49.1.1.1 as-number 100
[r9-bgp]network 9.9.9.9 32
[r9-bgp]peer 89.1.1.1 as-number 101
[r9-bgp]import-route direct
2.R1访问R8走R5
[r1]ip ip
[r1]ip ip-prefix aa permit 8.8.8.8 32
[r1]route-policy bb permit n 10
[r1-route-policy]if-match ip-prefix aa
[r1-route-policy]apply preferred-value 1
[r1-route-policy]quit
[r1]route-policy bb permit node 20
[r1]bgp 64512
[r1-bgp]peer 15.1.1.2 route-policy bb import
3.r5访问r4的环回都走r6
EBGP邻居关系使用AS-PATH
[r8]ip ip-prefix cc permit 4.4.4.4 32
[r8]route-policy dd permit node 10
[r8-route-policy]if-match ip-prefix cc
[r8-route-policy]apply as-path 2 3 4 additive
[r8]route-policy dd permit node 20
[r8]bgp 64515
[r8-bgp]peer 48.1.1.1 route-policy dd import (进入口)
4.r9访问r1的环回走r8
[r9]ip ip-prefix xx permit 1.1.1.1 32
[r9]route-policy yy permit node 10
[r9-route-policy]if-match ip-prefix xx
[r9-route-policy]apply as-path 3 4 5 additive
[r9]route-policy yy permit node 20
[r9]bgp 102
[r9-bgp]peer 49.1.1.1 route-policy yy import
5.全网可达
总结:BGP建设邻居的时候联邦中的peer-as是写联邦的小AS不写大AS,跨EBGP时候需要将每个边界路由器上导入直连在BGP中,否则无法进行发送与回包,双向选路中需要分辨是进接口还是出接口,在preferred-value中越大越优都是进接口,在AS-PATH中需要在改烂的路段的路由器上写指令,也同时是进接口。写route-policy时需要多配置一条node20使其他没有选中的道路中可以走这条路。