pc4 pc5 位于vlan 10 从路由器dhcp获取的IP段 192.168.10.0/24
pc6 pc7位于vlan 20 从路由器dhcp获取的IP段 192.168.20.0/24
vlan 10内所有的机器的网关为192.168.10.254
vlan 20内所有的机器的网关为192.168.20.254
不同vlan 可以进行通讯1.配置交换机吧
接口划分至相应的vlanSwitch#show vlan briefVLAN Name Status Ports---- -------------------------------- --------- -------------------------------1 default active Fa0/6, Fa0/7, Fa0/8, Fa0/9Fa0/10, Fa0/11, Fa0/12, Fa0/13Fa0/14, Fa0/15, Fa0/16, Fa0/17Fa0/18, Fa0/19, Fa0/20, Fa0/21Fa0/22, Fa0/23, Fa0/2410 v10 active Fa0/2, Fa0/320 v20 active Fa0/4, Fa0/51002 fddi-default active1003 token-ring-default active1004 fddinet-default active1005 trnet-default activeSwitch#
2.配置vlan 的
SW1(config)#interface vlan 10 SW1(config-if)#ip helper-address 192.168.10.254 #单臂路由的子接口 vlan10的SW1(config)#interface vlan 20 SW1(config-if)#ip helper-address 192.168.20.254 #单臂路由的子接口 vlan20的
3.配置交换机的上行接口为trunk
Switch(config)#interface fastEthernet 0/1Switch(config-if)#swSwitch(config-if)#switchport mode trunk
4.配置路由器单臂路由(路由器和交换机链接的端口是fa0/0 口)
Router(config)#interface fastEthernet 0/0.10Router(config-subif)#encapsulation dot1Q 10Router(config-subif)#ip addRouter(config-subif)#ip address 192.168.10.254 255.255.255.0Router(config)#interface fastEthernet 0/0.20Router(config-subif)#encapsulation dot1Q 20Router(config-subif)#ip addRouter(config-subif)#ip address 192.168.20.254 255.255.255.0
5.配置dhcp
Router(config)#ip dhcp pool vlan10 #vlan10只是名字Router(dhcp-config)#network 192.168.10.0 255.255.255.0Router(dhcp-config)#dns-server 223.5.5.5Router(dhcp-config)#default-router 192.168.10.254Router(dhcp-config)#exitRouter(config)#ip dhcp excluded-address 192.168.10.254Router(config)#ip dhcp pool vlan20 #vlan20只是名字Router(dhcp-config)#network 192.168.20.0 255.255.255.0Router(dhcp-config)#dns-server 223.5.5.5Router(dhcp-config)#default-router 192.168.20.254Router(dhcp-config)#exitRouter(config)#ip dhcp excluded-address 192.168.20.254
最终测试:不同vlan获取了不同的Ip 不同vlan可以通讯 OK