一: 连接
二: 设置主机0和主机1的IP地址
主机0: 192.168.10.2 255.255.255.0 192.168.10.1
主机1: 192.168.20.2 255.255.255.0 192.168.20.1
三:利用主机2进行配置,划分端口到VLAN10,并设置交换机和路由器的一号端口为 trunk模式
1.en
2.conf
3.vlan 10
4.name vlan10
5.exit
6.interface f0/2
7.switchport access vlan 10
8.exit
9.vlan 20
10.name vlan 20
11.interface f0/3
12.switchport access vlan 20
13.exit
14.进入全局模式
15.选中一号端口:interface f0/1
16.switchport mode trunk (这个命令就是设置trunk模式命令,是共享端口)
17.exit
四: 在主机3进行配置路由器
1.no
2.en
3.conf
4.interface f0/1
5.no shutdown
6.exit
7.设置虚拟子接口1.1
先选中子接口:interface f0/1.1 回车就进入了子接口模式Router(conf-subif)#
接着封装协议:输入encapsulation dot1Q 10 回车(是把虚拟子接口1.1封装到VLAN10)
8.设置IP地址: ip address 192.168.10.1 255.255.255.0
9.no shutdown
10.exit
11.设置虚拟子接口1.2
选中子接口:interface f0/1.2 回车
接着封装协议:输入encapsulation dot1Q 20 回车 (是把虚拟子接口1.2封装到VLAN20)
12.设置IP地址: ip address 192.168.20.1 255.255.255.0
13.no shutdown
14.exit
五: ping命令,看是否为通