第一步:搭建拓扑图
第二步:配置IP地址以及VLAN
R1配置
interface GigabitEthernet0/0/0
ip address 192.168.100.9 30
interface GigabitEthernet0/0/1
ip address 192.168.100.17 30
interface GigabitEthernet0/0/2
ip address 10.10.10.41 30
interface GigabitEthernet4/0/0
ip address 10.10.10.1 30
interface GigabitEthernet4/0/1
ip address 10.10.10.5 30
interface LoopBack0
ip address 1.1.1.1 30
R2配置
interface GigabitEthernet0/0/0
ip address 192.168.100.13 30
interface GigabitEthernet0/0/1
ip address 192.168.100.5 30
interface GigabitEthernet0/0/2
ip address 10.10.10.42 30
interface GigabitEthernet4/0/0
ip address 10.10.10.13 30
interface GigabitEthernet4/0/1
ip address 10.10.10.9 30
interface LoopBack0
ip address 2.2.2.2 32
R3配置
interface GigabitEthernet0/0/0
ip address 192.168.100.10 30
interface GigabitEthernet0/0/1
interface GigabitEthernet0/0/2
ip address 192.168.100.6 30
interface GigabitEthernet4/0/0
ip address 192.168.100.1 30
interface LoopBack0
ip address 3.3.3.3 32
R4配置
interface GigabitEthernet0/0/0
ip address 192.168.100.14 30
interface GigabitEthernet0/0/1
interface GigabitEthernet0/0/2
ip address 192.168.100.18 30
interface GigabitEthernet4/0/0
ip address 192.168.100.2 30
interface LoopBack0
ip address 4.4.4.4 32
R5配置
interface GigabitEthernet0/0/0
ip address 10.10.10.2 2 30
interface GigabitEthernet0/0/1
ip address 10.10.10.10 30
interface GigabitEthernet0/0/2
ip address 10.10.10.17 30
interface GigabitEthernet4/0/0
ip address 10.10.10.21 30
interface LoopBack0
ip address 5.5.5.5 32
R6配置
interface GigabitEthernet0/0/0
ip address 10.10.10.14 30
interface GigabitEthernet0/0/1
ip address 10.10.10.18 30
interface GigabitEthernet0/0/2
ip address 10.10.10.6 30
interface GigabitEthernet4/0/0
ip address 10.10.10.25 30
interface LoopBack0
ip address 6.6.6.6 32
R7配置
interface GigabitEthernet0/0/0
ip address 10.10.10.26 30
interface GigabitEthernet0/0/1
ip address 10.10.10.22 30
interface GigabitEthernet0/0/2
ip address 10.10.10.29 30
interface GigabitEthernet4/0/0
ip address 10.10.10.33 30
interface LoopBack0
ip address 7.7.7.7 30
R8 配置
interface GigabitEthernet0/0/0
ip address 10.10.10.30 30
interface GigabitEthernet0/0/1
ip address 10.10.10.37 30
interface GigabitEthernet0/0/2
ip address 10.10.10.34 30
interface LoopBack0
ip address 8.8.8.8 32
R9配置
interface GigabitEthernet0/0/0
ip address 10.10.10.38 30
interface GigabitEthernet0/0/1
ip address 192.168.200.2 30
interface GigabitEthernet0/0/2
interface LoopBack0
ip address 9.9.9.9 32
R10配置
interface GigabitEthernet0/0/0
ip address 192.168.200.1 30
interface GigabitEthernet0/0/1.1
dot1q termination vid 10
ip address 192.168.3.254 24
arp broadcast enable
interface GigabitEthernet0/0/1.2
dot1q termination vid 20
ip address 192.168.4.254 24
arp broadcast enable
interface LoopBack0
ip address 10.10.10.10 24
LSW配置
vlan batch 10 20
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 to 20
interface GigabitEthernet0/0/2
port link-type access
port default vlan 20
interface GigabitEthernet0/0/3
port link-type access
port default vlan 10
第三步:启用OSPF协议
ospf 100 router-id 1.1.1.1
area 0.0.0.0
network 1.1.1.1 0.0.0.0
network 10.10.10.41 0.0.0.0
network 192.168.100.9 0.0.0.0
network 192.168.100.17 0.0.0.0
ospf 100 router-id 2.2.2.2
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 10.10.10.42 0.0.0.0
network 192.168.100.5 0.0.0.0
network 192.168.100.13 0.0.0.0
ospf 100 router-id 3.3.3.3
area 0.0.0.0
network 192.168.1.254 0.0.0.0
network 192.168.100.1 0.0.0.0
network 192.168.100.6 0.0.0.0
network 192.168.100.10 0.0.0.0
ospf 100 router-id 4.4.4.4
area 0.0.0.0
network 192.168.2.254 0.0.0.0
network 192.168.100.2 0.0.0.0
network 192.168.100.14 0.0.0.0
network 192.168.100.18 0.0.0.0
ospf 10 router-id 5.5.5.5
area 0.0.0.0
network 5.5.5.5 0.0.0.0
network 10.10.10.17 0.0.0.0
network 10.10.10.21 0.0.0.0
ospf 10 router-id 6.6.6.6
area 0.0.0.0
network 6.6.6.6 0.0.0.0
network 10.10.10.18 0.0.0.0
network 10.10.10.25 0.0.0.0
ospf 10 router-id 7.7.7.7
area 0.0.0.0
network 7.7.7.7 0.0.0.0
network 10.10.10.22 0.0.0.0
network 10.10.10.26 0.0.0.0
network 10.10.10.29 0.0.0.0
network 10.10.10.33 0.0.0.0
ospf 10 router-id 8.8.8.8
area 0.0.0.0
network 8.8.8.8 0.0.0.0
network 10.10.10.30 0.0.0.0
network 10.10.10.34 0.0.0.0
network 10.10.10.37 0.0.0.0
ospf 200 router-id 9.9.9.9
area 0.0.0.0
network 192.168.200.2 0.0.0.0
ospf 200 router-id 10.10.10.10
area 0.0.0.0
network 192.168.3.254 0.0.0.0
network 192.168.4.254 0.0.0.0
network 192.168.200.1 0.0.0.0
第四步:配置BGP
R1
bgp 100
router-id 1.1.1.1
peer 2.2.2.2 as-number 100
peer 2.2.2.2 connect-interface LoopBack0
peer 10.10.10.2 as-number 200
peer 10.10.10.6 as-number 200
R2
bgp 100
router-id 2.2.2.2
peer 1.1.1.1 as-number 100
peer 1.1.1.1 connect-interface LoopBack0
peer 10.10.10.10 as-number 200
peer 10.10.10.14 as-number 200
R5
bgp 200
router-id 5.5.5.5
peer 6.6.6.6 as-number 200
peer 6.6.6.6 connect-interface LoopBack0
peer 6.6.6.6 next-hop-local
peer 7.7.7.7 as-number 200
peer 7.7.7.7 connect-interface LoopBack0
peer 7.7.7.7 next-hop-local
peer 8.8.8.8 as-number 200
peer 8.8.8.8 connect-interface LoopBack0
peer 8.8.8.8 next-hop-local
peer 10.10.10.1 as-number 100
peer 10.10.10.9 as-number 100
R6
bgp 200
router-id 6.6.6.6
peer 5.5.5.5 as-number 200
peer 5.5.5.5 connect-interface LoopBack0
peer 5.5.5.5 next-hop-local
peer 7.7.7.7 as-number 200
peer 7.7.7.7 connect-interface LoopBack0
peer 7.7.7.7 next-hop-local
peer 8.8.8.8 as-number 200
peer 8.8.8.8 connect-interface LoopBack0
peer 8.8.8.8 next-hop-local
peer 10.10.10.5 as-number 100
peer 10.10.10.13 as-number 100
R7
bgp 200
router-id 7.7.7.7
peer 5.5.5.5 as-number 200
peer 5.5.5.5 connect-interface LoopBack0
peer 6.6.6.6 as-number 200
peer 6.6.6.6 connect-interface LoopBack0
peer 8.8.8.8 as-number 200
peer 8.8.8.8 connect-interface LoopBack0
R8
bgp 200
router-id 8.8.8.8
peer 5.5.5.5 as-number 200
peer 5.5.5.5 connect-interface LoopBack0
peer 5.5.5.5 next-hop-local
peer 6.6.6.6 as-number 200
peer 6.6.6.6 connect-interface LoopBack0
peer 6.6.6.6 next-hop-local
peer 7.7.7.7 as-number 200
peer 7.7.7.7 connect-interface LoopBack0
peer 7.7.7.7 next-hop-local
peer 10.10.10.38 as-number 100
R9
bgp 100
router-id 9.9.9.9
peer 10.10.10.37 as-number 200
宣告用户网段
[R1]bgp 100
[R1-bgp]network 192.168.1.0 24
[R1-bgp]network 192.168.2.0 24
[R1]bgp 100
[R1-bgp]network 192.168.1.0 24
[R1-bgp]network 192.168.2.0 24
[R9]bgp 100
[R9-bgp]network 192.168.3.0 24
[R9-bgp]network 192.168.4.0 24
R1上没有R 3R4
[R1-bgp]peer 10.10.10.2 allow-as-loop
[R1-bgp]peer 10.10.10.6 allow-as-loop
[R2-bgp]peer 10.10.10.10 allow-as-loop
[R2-bgp]peer 10.10.10.14 allow-as-loop
[R9-bgp]peer 10.10.10.37 allow-as-loop
第五步:重发布
R1
[R1]ospf 100
[R1-ospf-100]import-route bgp type 1
R2
[R2]ospf 100
[R2-ospf-100]import-route bgp type 1
R9
[R9]ospf 200
[R9-ospf-200]import-route bgp type 1
第六步:解决次优路径
[R1]bgp 100
[R1-bgp-af-ipv4]preference 140 255 255
[R2]bgp 100
[R2-bgp-af-ipv4]preference 140 255 255
第七步:解决优化剩余问题
[R1]ip ip-prefix 1 permit 192.168.2.0 24
[R1]route-policy 1 permit node 10
[R1-route-policy]if-match ip-prefix 1
[R1-route-policy]apply cost 10
[R1]route-policy 1 permit node 20
[R1]bgp 100
[R1-bgp]peer 10.10.10.2 route-policy 1 export
[R1-bgp]peer 10.10.10.6 route-policy 1 export
[R2]ip ip-prefix 1 permit 192.168.1.0 24
[R2]route-policy 1 permit node 10
[R2-route-policy]if-match ip-prefix 1
[R2-route-policy]apply cost 10
[R2]route-policy 1 permit node 20
[R2]bgp 100
[R2-bgp]peer 10.10.10.10 route-policy 1 export
[R2-bgp]peer 10.10.10.14 route-policy 1 export