一、配置接口IP地址与环回地址
[r1-GigabitEthernet0/0/0]ip address 12.0.0.1 24 [r1-GigabitEthernet0/0/1]ip address 13.0.0.1 24 [r1-GigabitEthernet0/0/2]ip address 15.0.0.1 24 [r1-LoopBack0]ip address 1.1.1.1 32 [r1-LoopBack1]ip address 192.168.100.1 24
[r2-GigabitEthernet0/0/0]ip address 24.0.0.2 24 [r2-GigabitEthernet0/0/1]ip address 12.0.0.2 24 [r2-LoopBack0]ip address 2.2.2.2 32 [r2-LoopBack1]ip address 192.168.20.1 24
[r3-GigabitEthernet0/0/0]ip address 34.0.0.3 24 [r3-GigabitEthernet0/0/1]ip address 13.0.0.3 24 [r3-LoopBack0]ip address 3.3.3.3 32 [r3-LoopBack1]ip address 192.168.30.1 24
[r4-GigabitEthernet0/0/0]ip address 24.0.0.4 24 [r4-GigabitEthernet0/0/1]ip address 34.0.0.4 24 [r4-LoopBack0]ip address 192.168.1.1 24 [r4-LoopBack1]ip address 192.168.2.1 24 [r4-LoopBack2]ip address 192.168.3.1 24
[r5-GigabitEthernet0/0/0]ip address 15.0.0.5 24 [r5-LoopBack0]ip address 192.168.10.1 24 [r5-LoopBack1]IP address 192.168.11.1 24 [r5-LoopBack2]ip address 192.168.12.1 24
二、配置OSPF配通路由器
[r1]ospf 1 router-id 1.1.1.1 [r1-ospf-1]a 0 [r1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0 [r1-ospf-1-area-0.0.0.0]network 192.168.100.0 0.0.0.255 [r1-ospf-1-area-0.0.0.0]network 12.0.0.1 0.0.0.0 [r1-ospf-1-area-0.0.0.0]network 13.0.0.1 0.0.0.0 [r1-ospf-1-area-0.0.0.0]network 15.0.0.1 0.0.0.0
[r2]ospf 1 router-id 2.2.2.2 [r2-ospf-1]a 0 [r2-ospf-1-area-0.0.0.0]network 24.0.0.2 0.0.0.0 [r2-ospf-1-area-0.0.0.0]network 12.0.0.2 0.0.0.0 [r2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0 [r2-ospf-1-area-0.0.0.0]network 192.168.20.0 0.0.0.255
[r3]ospf 1 router-id 3.3.3.3 [r3-ospf-1]a 0 [r3-ospf-1-area-0.0.0.0]network 13.0.0.3 0.0.0.0 [r3-ospf-1-area-0.0.0.0]network 34.0.0.3 0.0.0.0 [r3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0 [r3-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255
三、运行BGP
[r1]bgp 123 [r1-bgp]router-id 1.1.1.1 [r1-bgp]peer 12.0.0.2 as-number 123 [r1-bgp]peer 12.0.0.2 connect-interface l 0 [r1-bgp]peer 13.0.0.3 as-number 123 [r1-bgp]peer 13.0.0.3 connect-interface l 0 [r1-bgp]peer 15.0.0.5 as-number 500 [r1-bgp]peer 15.0.0.5 connect-interface l 0
[r1]bgp 123
[r1-bgp]network 192.168.100.0 24
[r2]bgp 123 [r2-bgp]router-id 2.2.2.2 [r2-bgp]peer 12.0.0.1 as-number 123 [r2-bgp]peer 12.0.0.1 connect-interface l 0 [r2-bgp]peer 24.0.0.4 as-number 400 [r2-bgp]peer 24.0.0.4 connect-interface l 0
[r2]bgp 123
[r2-bgp]network 192.168.20.0 24
[r3]bgp 123 [r3-bgp]router-id 3.3.3.3 [r3-bgp]peer 13.0.0.1 as-number 123 [r3-bgp]peer 13.0.0.1 connect-interface l 0 [r3-bgp]peer 34.0.0.4 as-number 400 [r3-bgp]peer 34.0.0.4 connect-interface l 0
[r3]bgp 123
[r3-bgp]network 192.168.30.0 24
[r4]bgp 400 [r4-bgp]router-id 4.4.4.4 [r4-bgp]peer 24.0.0.2 as-number 123 [r4-bgp]peer 34.0.0.3 as-number 123
[r4]bgp 400
[r4-bgp]network 192.168.1.0 24
[r4-bgp]network 192.168.2.0 24
[r4-bgp]network 192.168.3.0 24
[r5]bgp 500 [r5-bgp]router-id 5.5.5.5 [r5-bgp]peer 15.0.0.1 as-number 123
[r5]bgp 500
[r5-bgp]network 192.168.10.0 24
[r5-bgp]network 192.168.11.0 24
[r5-bgp]network 192.168.12.0 24
四、使用preval策略,确保R4通过R2到达192.168.10.0/24
[r4]ip ip-prefix PV permit 192.168.10.0 24 [r4]route-policy PV permit node 10 Info: New Sequence of this List. [r4-route-policy]if-match ip-prefix PV [r4-route-policy]apply preferred-value 100 [r4-route-policy]q [r4]route-policy PV permit node 20 [r4]bgp 400 [r4-bgp]peer 24.0.0.2 route-policy PV import
五、使用AS_PATH策略,确保R4通过R3到达192.168.11.0/24
[r4]route-policy AS permit node 11 Info: New Sequence of this List. [r4-route-policy]if-match ip-prefix AS [r4-route-policy]apply as-path 400 123 overwrite [r4-route-policy]q [r4]route-policy AS permit node 21 Info: New Sequence of this List. [r4-route-policy]q [r4]bgp 400 [r4-bgp]peer 34.0.0.3 route-policy AS export
六、使用MED策略,确保R4通过R3到达192.168.12.0/24
[r3]ip ip-prefix MED permit 192.168.12.0 24 [r3]route-policy MED permit node 10[r3-route-policy]if-match ip-prefix MED [r3-route-policy]apply cost 20 [r3]route-policy MED permit node 20 [r3]bgp 123 [r3-bgp]peer 34.0.0.4 route-policy MED export [r4]bgp 400 [r4-bgp]default med 10
七、使用Local Preference策略,确保R1通过R2到达192.168.1.0,R1通过R3到达192.168.2.0
[r1]ip ip-prefix LP permit 192.168.1.0 24 [r1]route-policy LP permit node 10 [r1-route-policy]if-match ip-prefix LP [r1-route-policy]apply local-preference 200 [r1]route-policy LP permit node 20 Info: New Sequence of this List. [r1-route-policy]bgp 123 [r1-bgp]peer 12.0.0.2 route-policy LP import [r1]ip ip-prefix LP2 permit 192.168.2.0 24 [r1]route-policy LP2 permit node 11 [r1-route-policy]if-match ip-prefix LP2 [r1-route-policy]apply local-preference 200 [r1]route-policy LP2 permit node 21 [r1]bgp 123 [r1-bgp]peer 13.0.0.3 route-policy LP2 import
八、配置负载均衡,确保R1通过R2和R3到达192.168.3.0
[r1]bgp 123 [r1-bgp]maximum load-balancing 2 [r1-bgp]load-balancing as-path-ignore
九、使用AS策略,AS 500不接受任何始发于AS 123的路由
[r1]ip as-path-filter 1 deny _123$ [r1]ip as-path-filter 1 permit .* [r1]bgp 123 [r1-bgp]peer 15.0.0.5 as-path-filter 1 export