首先对交换机进行配置
将f0/1端口只允许vlan 10,f0/11端口只允许vlan 20,将f0/24端口设为truck模式
int f0/1
switchport mode access
switchport access vlan 10
exi
int f0/11
switchport mode access
switchport access vlan 20
exit
int f0/24
switchport mode trunk
switchport trunk allowed vlan all
在路由器上进行单臂路由配置
int f0/0
int f0/0.10 #进入子接口
encapsulation dot1Q 10 #进行封装802.1q协议,打上vlan 10的标签
ip add 192.168.10.254 255.255.255.0 #配置valn 10的网关
int f0/0.20
encapsulation dot1Q 20 #进行封装802.1q协议,打上vlan 20的标签
ip add 192.168.20.254 255.255.255.0 #配置vlan 20的网关
这时两台主机成功通信。
配置三层交换
首先配置二层交换机
将f0/1端口只允许vlan 10,f0/11端口只允许vlan 20,将f0/24端口启用trunk模式
int f0/1
switchport mode access
switch access vlan 10
int f0/11
switchport mode access
switch access vlan 20
int f0/24
switchport mode trunk
switch trunk allowed vlan all
接着配置三层交换机
ip routing #开启路由功能
int f0/1
switchport trunk encapsulation dot1q #封装dot1q协议,这里不指定vlan号
switchport trunk allowed vlan all #允许所有vlan通过
exit
int vlan 10
ip add 192.168.10.254 255.255.255.0 #设置vlan 10的网关
int vlan 20
ip add 192.168.20.254 255.255.255.0 #设置vlan 20 的网关
以上给基本命令配置完成。