方法一:单臂路由,配置终结子接口

交换机

路由器配置

#
sysname Router
#
vlan batch 2 to 3
#
dhcp enable
#
acl number 2001  
 rule 5 permit source 192.168.0.0 0.0.255.255 
#
interface GigabitEthernet0/0/1
#
interface GigabitEthernet0/0/1.1
 dot1q termination vid 2
 ip address 192.168.1.1 255.255.255.0 
 arp broadcast enable
 dhcp select interface
 dhcp server dns-list 223.5.5.5 
#
interface GigabitEthernet0/0/1.2
 dot1q termination vid 3
 ip address 192.168.2.1 255.255.255.0 
 arp broadcast enable
 dhcp select interface
 dhcp server dns-list 223.5.5.5 
#
interface GigabitEthernet0/0/2
 ip address 203.0.113.2 255.255.255.0 
 nat outbound 2001
#
ip route-static 0.0.0.0 0.0.0.0 203.0.113.1
#
return

方法二:portswitch切换为交换模式,和交换机一样划分vlan,配trunk

交换机配置

路由器配置

#
sysname Router
#
vlan batch 2 to 3
#
dhcp enable
#
acl number 2001
 rule 5 permit source 192.168.0.0 0.0.255.255
#
interface Vlanif2
 ip address 192.168.1.1 255.255.255.0
 dhcp select interface
 dhcp server dns-list 223.5.5.5
#
interface Vlanif3
 ip address 192.168.2.1 255.255.255.0
 dhcp select interface
 dhcp server dns-list 223.5.5.5
#
interface GigabitEthernet0/0/1
 portswitch
 port link-type trunk
 port trunk allow-pass vlan 2 to 3
#
interface GigabitEthernet0/0/2
 ip address 203.0.113.2 255.255.255.0
 nat outbound 2001
#
ip route-static 0.0.0.0 0.0.0.0 203.0.113.1
#
return

Q.E.D.