一、搭建实验拓扑图
二、进行配置
对r1,r2进行IP配置及环回
[r1interface g0/0/2
[r1-GigabitEthernet0/0/2]ip address 12.1.1.1 24
[r1-GigabitEthernet0/0/2]interface g0/0/0
[r1-GigabitEthernet0/0/0]ip address 23.1.1.1 24
[r1-GigabitEthernet0/0/0]interface g0/0/1
[r1-GigabitEthernet0/0/1]ip address 34.1.1.1 24
[r1]interface LoopBack 0
[r1-LoopBack0]ip address 1.1.1.1 32
[r2]interface g0/0/0
[r2-GigabitEthernet0/0/0]ip address 12.1.1.2 24
[r2]interface LoopBack 0
[r2-LoopBack0]ip address 2.2.2.2 32
划分vlan
[SW1]interface Vlanif 1
[SW1-Vlanif1]ip address 23.1.1.2 24
[SW2]interface Vlanif 1
[SW2-Vlanif1]ip address 34.1.1.2 24
接口汇聚
[SW1]interface Eth-Trunk 1
[SW1]interface g0/0/2
[SW1-GigabitEthernet0/0/2]eth-trunk 1
[SW1]interface g0/0/3
[SW1-GigabitEthernet0/0/3]eth-trunk 1
[SW1]interface g0/0/7
[SW1-GigabitEthernet0/0/3]eth-trunk 1
[SW2]interface Eth-Trunk 1
[SW2]interface g0/0/2
[SW2-GigabitEthernet0/0/2]eth-trunk 1
[SW2-GigabitEthernet0/0/2]interface g0/0/3
[SW2-GigabitEthernet0/0/3]eth-trunk 1
[SW2-GigabitEthernet0/0/3]interface g0/0/7
[SW2-GigabitEthernet0/0/7]eth-trunk 1
Trunk
[SW1]interface Eth-Trunk 1
[SW1-Eth-Trunk1]port link-type trunk
[SW1-Eth-Trunk1]port trunk allow-pass vlan all
[SW2]interface Eth-Trunk 1
[SW2-Eth-Trunk1]port link-type trunk
[SW2-Eth-Trunk1]port trunk allow-pass vlan all
生成树,创建vlan2,vlan3
SW1
[SW1]interface g0/0/4
[SW1-GigabitEthernet0/0/4]port link-type access
[SW1-GigabitEthernet0/0/4]port default vlan 2
[SW1]interface g0/0/5
[SW1-GigabitEthernet0/0/5]port link-type access
[SW1-GigabitEthernet0/0/5]port default vlan 3
[SW1]interface g0/0/6
[SW1-GigabitEthernet0/0/6]port link-type trunk
[SW1-GigabitEthernet0/0/6]port trunk allow-pass vlan all
SW2
[SW2]interface g0/0/4
[SW2-GigabitEthernet0/0/4]port link-type access
[SW2-GigabitEthernet0/0/4]port default vlan 2
[SW2]interface g0/0/5
[SW2-GigabitEthernet0/0/5]port link-type access
[SW2-GigabitEthernet0/0/5]port default vlan 3
[SW2]interface g0/0/6
[SW2-GigabitEthernet0/0/6]port link-type trunk
[SW2-GigabitEthernet0/0/6]port trunk allow-pass vlan all
SW3
[SW3]vlan 2
[SW3]port-group 1
[SW3-port-group-1]group-member e0/0/1 to e0/0/4
[SW3-port-group-1]port link-type access
[SW3-port-group-1]port default vlan 2
SW4
[SW4]vlan 3
[SW4]port-group 1
[SW4-port-group-1]group-member e0/0/1 to e0/0/4
[SW4-port-group-1]port link-type access
[SW4-port-group-1]port default vlan 3
SW5
[SW5]interface e0/0/1
[SW5-Ethernet0/0/1]port link-type access
[SW5-Ethernet0/0/1]port link-type trunk
[SW5-Ethernet0/0/1]port trunk allow-pass vlan all
[SW5-Ethernet0/0/1]interface e0/0/2
[SW5-Ethernet0/0/2]port link-type trunk
[SW5-Ethernet0/0/2]port trunk allow-pass vlan all
[SW5-Ethernet0/0/2]interface e0/0/3
[SW5-Ethernet0/0/3]port link-type access
[SW5-Ethernet0/0/3]port default vlan 2
[SW5-Ethernet0/0/3]interface e0/0/4
[SW5-Ethernet0/0/4]port link-type access
[SW5-Ethernet0/0/4]port default vlan 3
MSTP
[SW1]stp mode mstp
[SW1]stp region-configuration
[SW1-mst-region]region-name a
[SW1-mst-region]instance 1 vlan 2
[SW1-mst-region]instance 2 vlan 3
[SW1-mst-region]active region-configuration
[SW1]stp instance 1 root primary
[SW1]stp instance 2 root secondary
[SW2]stp mode mstp
[SW2]stp region-configuration
[SW2-mst-region]region-name a
[SW2-mst-region]instance 1 vlan 2
[SW2-mst-region]instance 2 vlan 3
[SW2-mst-region]active region-configuration
[SW2]stp instance 1 root secondary
[SW2]stp instance 2 root primary
OSPF
[r1]ospf 1 router-id 1.1.1.1
[r1-ospf-1]area 0
[r1-ospf-1-area-0.0.0.0]network 34.1.1.1 0.0.0.0
[r1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0
[r1-ospf-1]default-route-advertise
[r1]ip route-static 0.0.0.0 0 12.1.1.2
[SW1]ospf 1 router-id 2.2.2.2
[SW1-ospf-1]area 0
[SW1-ospf-1-area-0.0.0.0]network 0.0.0.0 255.255.255.255
[SW2]ospf 1 router-id 3.3.3.3
[SW2-ospf-1]area 0
[SW2-ospf-1-area-0.0.0.0]network 0.0.0.0 255.255.255.255
SW1
[SW1]interface Vlanif 2
[SW1-Vlanif2]ip address 192.168.1.1 24
[SW1]interface Vlanif 3
[SW1-Vlanif2]ip address 172.16.1.1 24
SW2
[SW1]interface Vlanif 2
[SW1-Vlanif2]ip address 192.168.1.1 24
[SW1]interface Vlanif 3
[SW1-Vlanif2]ip address 172.16.1.1 24
VRRP
[SW1]interface Vlanif 2
[SW1-Vlanif2]vrrp vrid 1 virtual-ip 192.168.1.1
[SW1-Vlanif2]ip address 192.168.1.1 24
[SW1-Vlanif2]vrrp vrid 1 priority 120
[SW1-Vlanif2]vrrp vrid 1 preempt-mode timer delay 20
[SW1]interface Vlanif 3
[SW1-Vlanif3]vrrp vrid 2 virtual-ip 172.16.1.2
[SW2]interface Vlanif 2
[SW2-Vlanif2]vrrp vrid 1 virtual-ip 192.168.1.1
[SW2]interface Vlanif 3
[SW2-Vlanif3]vrrp vrid 2 virtual-ip 172.16.1.2
[SW2-Vlanif3]vrrp vrid 2 priority 120
[SW2-Vlanif3]vrrp vrid 2 preempt-mode timer delay 20
写DHCP
[SW1]ip pool 1
[SW1-ip-pool-1]network 192.168.1.0 mask 24
[SW1-ip-pool-1]gateway-list 192.168.1.1
[SW1-ip-pool-1]dns-list 8.8.8.8
[SW1]interface Vlanif 2
[SW1-Vlanif2]dhcp select global
[SW1]ip pool 2
[SW1-ip-pool-2]network 172.16.1.0 mask 24
[SW1-ip-pool-2]gateway-list 172.16.1.2
[SW1-ip-pool-2]dns-list 8.8.8.8
[SW1]interface Vlanif 3
[SW1-Vlanif3]dhcp select global
[SW2]ip pool 1
[SW2-ip-pool-1]network 192.168.1.0 mask 24
[SW2-ip-pool-1]gateway-list 192.168.1.1
[SW2-ip-pool-1]dns-list 8.8.8.8
[SW2]interface Vlanif 2
[SW2-Vlanif2]dhcp select global
[SW2]ip pool 3
[SW2-ip-pool-3]network 172.16.1.0 mask 24
[SW2-ip-pool-3]gateway-list 172.16.1.2
[SW2-ip-pool-3]dns-list 8.8.8.8
[SW2]interface Vlanif 3
[SW2-Vlanif3]dhcp select global
开启DHCP服务
nat上外网
[r1]acl 2000
[r1-acl-basic-2000]rule permit source any
[r1]interface g0/0/2
[r1-GigabitEthernet0/0/2]nat outbound 2000