1.先配置好IP和环回
[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip add 12.1.1.1 24
[R1-GigabitEthernet0/0/0]int l 0
[R1-LoopBack0]ip add 1.1.1.1 24
其他同理
2.在R2,R3,R4上配置OSPF
ospf 1
area 0.0.0.0
network 3.3.3.3 0.0.0.0
network 23.1.1.2 0.0.0.0
network 34.1.1.1 0.0.0.0
其他同理
3.配置bgp
[R1]bgp 1
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 12.1.1.2 as-number 2
[R2]bgp 2
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 12.1.1.1 as-number 1
[R2-bgp]peer 3.3.3.3 as-number 2
[R2-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[R3]bgp 2
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 2.2.2.2 as-number 2
[R3-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[R3-bgp]peer 4.4.4.4 as-number 2
[R3-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[R4]bgp 2
[R4-bgp]router-id 4.4.4.4
[R4-bgp]peer 3.3.3.3 as-number 2
[R4-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[R4]ip route-static 5.5.5.0 24 45.1.1.2
[R4]ip route-static 5.5.5.0 24 54.1.1.2
[R4]bgp 2
[R4-bgp]peer 5.5.5.5 as-number 3
[R4-bgp]peer 5.5.5.5 connect-interface LoopBack 0
[R4-bgp]peer 5.5.5.5 ebgp-max-hop 2
[R5]ip route-static 4.4.4.0 24 45.1.1.1
[R5]ip route-static 4.4.4.0 24 54.1.1.1
[R5-bgp]router-id 5.5.5.5
[R5-bgp]peer 4.4.4.4 as-number 2
[R5-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[R5-bgp]peer 4.4.4.4 ebgp-max-hop 2
R1上宣告
[R1-bgp]network 1.1.1.0 24
发现R3上不优
R2下一跳改为自己:
[R2-bgp]peer 3.3.3.3 next-hop-local
R3无法发给R4(IBGP不能共享给IBGP)
[R2-bgp]peer 4.4.4.4 as-number 2
[R2-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[R4-bgp]peer 2.2.2.2 as-number 2
[R4-bgp]peer 2.2.2.2 connect-interface LoopBack 0
R4学到了但是不优
和上面同理下一跳改为自己
[R2-bgp]peer 4.4.4.4 next-hop-local
在R5上宣告
[R5-bgp]network 5.5.5.0 24
[R5-LoopBack1]ip add 99.1.1.1 24
[R5]bgp 3
[R5-bgp]network 99.1.1.0 24
[R4]bgp 2
[R4-bgp]peer 2.2.2.2 next-hop-local
[R4-bgp]peer 3.3.3.3 next-hop-local
5.5.5.0不优是因为前面建邻的时候用的是5.5.5.0
所以可以改成
[R4]ip route-static 5.5.5.5 32 45.1.1.2
[R4]ip route-static 5.5.5.5 32 54.1.1.2
R5上同理