路由器R1配置:
R1#configure terminal
R1(config)#interface fastethernet 0/0
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#interface fastethernet 0/0.1
R1(config-subif)#encapsulation dot1Q 10
R1(config-subif)#ip add 10.1.1.1 255.255.255.0
R1(config-subif)#no shutdown
R1(config-subif)#exit
R1(config)#interface fastethernet 0/0.2
R1(config-subif)#encapsulation dot1Q 20
R1(config-subif)#ip add 20.2.2.2 255.255.255.0
R1(config-subif)#no shutdown
R1(config-subif)#exit
R1(config)#ip dhcp pool vlan10
R1(dhcp-config)#network 10.1.1.0 255.255.255.0
R1(dhcp-config)#default-router 10.1.1.1
R1(dhcp-config)#dns-server 8.8.8.8
R1(dhcp-config)#exit
R1(config)#ip dhcp pool vlan20
R1(dhcp-config)#network 20.2.2.0 255.255.255.0
R1(dhcp-config)#default-router 20.2.2.2
R1(dhcp-config)#dns-server 8.8.8.8
R1(dhcp-config)#exit
交换机SW1配置:
SW1#vlan database
SW1(vlan)#vlan 10 name vlan10
SW1(vlan)#vlan 20 name vlan20
SW1(vlan)#exit
SW1#configure terminal
SW1(config)#interface fastethernet 0/2
SW1(config-if)#switchport access vlan 10
SW1(config-if)#exit
SW1(config)#interface fastethernet 0/3
SW1(config-if)#switchport access vlan 20
SW1(config-if)#exit
SW1(config)#interface fastethernet 0/1
SW1(config-if)#switchport mode trunk