实验环境:Cisco Packet Tracer Student 6.2.0.0052
全局模式下show run显示如下配置:
--------------------------------------------------全局模式---------------------------------------------------------
路由器:cisco 2620XM 配置
interface FastEthernet0/0
no ip address
duplex auto
speed auto
!
interface FastEthernet0/0.2
encapsulation dot1Q 2
ip address 192.168.1.1 255.255.255.0
!
interface FastEthernet0/0.3
encapsulation dot1Q 3
ip address 192.168.2.1 255.255.255.0
!
交换机:cisco 2960-24T配置
hostname Switch
!
!
ip dhcp excluded-address 192.168.1.1 192.168.1.2
ip dhcp excluded-address 192.168.2.1 192.168.2.2
!
ip dhcp pool vlan2
network 192.168.1.0 255.255.255.0
default-router 192.168.1.1
ip dhcp pool vlan3
network 192.168.2.0 255.255.255.0
default-router 192.168.2.1
!
!
spanning-tree mode pvst
!
interface FastEthernet0/1
switchport mode trunk
!
interface FastEthernet0/2
switchport access vlan 2
switchport mode access
!
interface FastEthernet0/3
switchport access vlan 3
switchport mode access
--------------------------------------------------详细步骤---------------------------------------------------------
第一步:在路由器R1上的配置:
R1(config)#int f0/0
R1(config-if)#no shut
R1(config)#int f0/0.2
R1(config-subif)#encapsulation dot1q 2 (子接口封成dot1Q模式切关联VLAN 2)
R1(config-subif)#ip add 192.168.1.1 255.255.255.0
R1(config)#int f0/0.3
R1(config-subif)#encapsulation dot1q 3 (子接口封成dot1Q模式切关联VLAN 3)
R1(config-subif)#ip add 192.168.2.1 255.255.255.0
第二步:交换机SW1的配置:
(1)将SW1的f0/1的模式设置为trunk并封dot1q
SW1(config)#int f0/1
SW1(config-if)#switchport trunk encapulation dot1q (默认开启的)
SW1(config-if)#switchport mode trunk
(2)在SW1上创建vlan2
SW1(config)#vlan 2
SW1(config-vlan)#exit
SW1(config)#vlan 3
SW1(config-vlan)#exit
(3)将vlan 2和vlan 3 配置VLAN IP地址
SW1(config)#int vlan 2
SW1(config-if)#ip add 192.168.1.2 255.255.255.0
SW1(config-if)#exit
Sw1(config)#int vlan 3
Sw1(config-if)#ip add 192.168.2.2 255.255.255.0
Sw1(config-if)#exit
(4)将SW1的f0/2和f0/3模式设置为access,并分别划入valn2和vlan3
SW1(config)#int f0/2
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 2
SW1(config)#int f0/3
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 3
第三步:SW1开启vlan2,vlan3的DHCP并保留网关和vlan的ip地址:
Switch(config)#ip dhcp pool vlan2 (开启地址池并命名vlan2)
Switch(dhcp-config)#network 192.168.1.0 255.255.255.0 (指定vlan2地址池)
Switch(dhcp-config)#default-router 192.168.1.1 (指定vlan2默认路由)
Switch(dhcp-config)#exit
Switch(config)#ip dhcp pool vlan3 (开启地址池并命名vlan3)
Switch(dhcp-config)#network 192.168.2.0 255.255.255.0 (开启vlan3地址池)
Switch(dhcp-config)#default-router 192.168.2.1 (指定vlan3默认路由)
Switch(dhcp-config)#exit
Switch(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.2
Switch(config)#ip dhcp excluded-address 192.168.2.1 192.168.2.2
Switch(config)#exit
第四步:PC机的配置:
PC1: IP:192.168.1.2 netmask:255.255.255.0 gateway:192.168.1.1
PC2:IP:192.168.12.2 netmask:255.255.255.0 gateway:192.168.2.1
或自动获取IP