Eth-trunk
SW1+SW2
interface Eth-Trunk 0
q
interface GigabitEthernet0/0/2
eth-trunk 0
interface GigabitEthernet0/0/3
eth-trunk 0
VLAN+TRUNK
SW1+SW2
vlan 2
q
interface Eth-Trunk0
port link-type trunk
port trunk allow-pass vlan 2
interface GigabitEthernet0/0/4
port link-type trunk
port trunk allow-pass vlan 2
interface GigabitEthernet0/0/5
port link-type trunk
port trunk allow-pass vlan 2
SW3+SW4
vlan 2
q
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 2
interface Ethernet0/0/2
port link-type access
port default vlan 2
STP
SW1
stp region-configuration
region-name v1 //定义组的名字
instance 1 vlan 1
instance 2 vlan 2
active region-configuration //激活当前配置
stp instance 1 root primary //定义本地为组1的主根
stp instance 2 root secondary //定义本地为组2的备份根
SW2
stp region-configuration
region-name v1
instance 1 vlan 1
instance 2 vlan 2
active region-configuration
stp instance 1 root secondary
stp instance 2 root primary
SW3
stp region-configuration
region-name v1
instance 1 vlan 1
instance 2 vlan 2
active region-configuration
interface Ethernet0/0/1
stp edged-port enable //进入连接PC的接口,进行端口加速
interface Ethernet0/0/2
stp edged-port enable
SW4
stp region-configuration
region-name v1
instance 1 vlan 1
instance 2 vlan 2
active region-configuration
interface Ethernet0/0/1
stp edged-port enable //进入连接PC的接口,进行端口加速
interface Ethernet0/0/2
stp edged-port enable
SVI+VRRP
SW1
interface Vlanif1
ip address 172.16.1.1 255.255.255.128
vrrp vrid 1 virtual-ip 172.16.1.126 //虚拟网关IP
vrrp vrid 1 priority 120 //定义本地为VLAN1的网关
vrrp vrid 1 track interface GigabitEthernet0/0/1 reduced 30 //上行链路追踪
interface Vlanif2
ip address 172.16.1.129 255.255.255.128
vrrp vrid 2 virtual-ip 172.16.1.254 //VLAN2的备份网关
SW2
interface Vlanif1
ip address 172.16.1.2 255.255.255.128
vrrp vrid 1 virtual-ip 172.16.1.126 //VLAN1的备份网关
interface Vlanif2
ip address 172.16.1.130 255.255.255.128
vrrp vrid 2 virtual-ip 172.16.1.254
vrrp vrid 2 priority 120 //定义本地为VLAN1的网关
vrrp vrid 2 track interface GigabitEthernet0/0/1 reduced 30 //上行链路追踪
DHCP
dhcp enable
ip pool v1
gateway-list 172.16.1.126
network 172.16.1.0 mask 255.255.255.128
dns-list 8.8.8.8 114.114.114.114
ip pool v2
gateway-list 172.16.1.254
network 172.16.1.128 mask 255.255.255.128
dns-list 8.8.8.8 114.114.114.114
interface Vlanif1
dhcp select global
interface Vlanif2
dhcp select global
配置IP地址
r1
interface GigabitEthernet0/0/0
ip address 172.16.0.2 255.255.255.252
interface GigabitEthernet0/0/1
ip address 172.16.0.6 255.255.255.252
interface GigabitEthernet0/0/2
ip address 12.1.1.1 255.255.255.0
R2
interface GigabitEthernet0/0/2
ip address 12.1.1.2 255.255.255.0
interface LoopBack0
ip address 2.2.2.2 255.255.255.0
SW1
vlan 100 //创建一个用不到的VLAN
q
interface Vlanif100 //创建管理VLAN用来模拟三层接口
ip address 172.16.0.1 255.255.255.252
interface GigabitEthernet0/0/1 //将该接口划入VLAN100
port link-type access
port default vlan 100
SW2
vlan 100 //创建一个用不到的VLAN
q
interface Vlanif100 //创建管理VLAN用来模拟三层接口
ip address 172.16.0.5 255.255.255.252
interface GigabitEthernet0/0/1 //将该接口划入VLAN100
port link-type access
port default vlan 100
开启OSPF
ospf 1 router-id 1.1.1.1
area 0.0.0.0
network 172.16.0.0 0.0.0.255
SW1
ospf 1 router-id 2.2.2.2
silent-interface all //沉默接口用来规避当OSPF运行在SVI接口时,交换机所有和SVI接口在同一VLAN的接口每10s都会收到一个hello包,相当于每10s就会洪泛一次,会对带宽造成很大的占用。故需要使用沉默接口来禁止三层交换机向下发送hello包。
undo silent-interface Eth-Trunk0 //邻居间需要收发hello包
undo silent-interface Vlanif100
area 0.0.0.0
network 172.16.0.1 0.0.0.0
area 0.0.0.1
abr-summary 172.16.1.0 255.255.255.0 //将区域1的路由汇总为一条给区域0
network 172.16.1.1 0.0.0.0
network 172.16.1.129 0.0.0.0
SW2
ospf 1 router-id 3.3.3.3
silent-interface all
undo silent-interface Eth-Trunk0
undo silent-interface Vlanif100
area 0.0.0.0
network 172.16.0.5 0.0.0.0
area 0.0.0.1
abr-summary 172.16.1.0 255.255.255.0
network 172.16.1.2 0.0.0.0
network 172.16.1.130 0.0.0.0
上网
ip route-static 0.0.0.0 0.0.0.0 12.1.1.2
ospf 1
default-route-advertise
acl number 2000
rule 5 permit source 172.16.0.0 0.0.255.255
interface GigabitEthernet0/0/2
nat outbound 2000