二层交换机指的是仅能够进行二层转发,不能进行三层转发的交换机。也就是说仅支持二层特性,不支持路由等三层特性的交换机。
二层交换机一般部署在接入层,不能作为用户的网关。配置注意事项,本举例中的交换机配置适用于S12700, S12700E交换机的所有版本所有产品。本举例中的路由器配置以AR3600 V200R007C00SPCc00为例,其他路由器的配置方法请参见对应的文档指南。
一、组网需求
如图所示,某公司拥有多个部门且位于不同网段,各部门均有访问Internet的需求。现要求用户通过二层交换机和路由器访问外部网络,且要求路由器作为用户的网关。下图二层交换机与路由器对接上网组网图
二、配置思路
采用如下思路进行配置:
配置二层交换机基于接口划分VLAN,实现二层转发。配置路由器作为用户的网关,通过子接口或VLANIF接口实现跨网段的三层转发。配置路由器作为DHCP服务器,为用户PC分配IP地址。配置路由器NAT功能,使内网用户可以访问外部网络。
三、操作步骤
3.1 配置交换机
代码语言:javascript复制# 配置下行连接用户的接口。
<HUAWEI> system-view
[HUAWEI] sysname Switch
[Switch] vlan batch 2 3
[Switch] interface gigabitethernet 1/0/2
[Switch-GigabitEthernet1/0/2] port link-type access //配置接口接入类型为access
[Switch-GigabitEthernet1/0/2] port default vlan 2 //配置接口加入VLAN 2
[Switch-GigabitEthernet1/0/2] quit
[Switch] interface gigabitethernet 1/0/3
[Switch-GigabitEthernet1/0/3] port link-type access
[Switch-GigabitEthernet1/0/3] port default vlan 3
[Switch-GigabitEthernet1/0/3] quit
代码语言:javascript复制# 配置上行连接路由器的接口
[Switch] interface gigabitethernet 1/0/1
[Switch-GigabitEthernet1/0/1] port link-type trunk
[Switch-GigabitEthernet1/0/1] port trunk allow-pass vlan 2 3 //配置接口以trunk方式透传VLAN 2和VLAN 3
[Switch-GigabitEthernet1/0/1] quit
3.2 路由器配置
路由器的配置有两种方式,配置子接口进行通信或者配置VLANIF接口进行通信,两种方式选择其一即可。
配置路由器通过子接口终结VLAN,实现跨网段的三层转发。
代码语言:javascript复制# 配置终结子接口。
<Huawei> system-view
[Huawei] sysname Router
[Router] vlan batch 2 3
[Router] interface gigabitethernet 0/0/1.1
[Router-GigabitEthernet0/0/1.1] dot1q termination vid 2
[Router-GigabitEthernet0/0/1.1] ip address 192.168.1.1 24
[Router-GigabitEthernet0/0/1.1] arp broadcast enable //缺省状态下,AR路由器终结子接口的ARP广播功能在V200R003C01之前版本处于未使能状态,在V200R003C01及之后版本处于使能状态
[Router-GigabitEthernet0/0/1.1] quit
[Router] interface gigabitethernet 0/0/1.2
[Router-GigabitEthernet0/0/1.2] dot1q termination vid 3
[Router-GigabitEthernet0/0/1.2] ip address 192.168.2.1 24
[Router-GigabitEthernet0/0/1.2] arp broadcast enable
[Router-GigabitEthernet0/0/1.2] quit
代码语言:javascript复制# 配置DHCP功能,为内网用户分配IP地址和指定DNS服务器地址。
[Router] dhcp enable
[Router] interface gigabitethernet 0/0/1.1
[Router-GigabitEthernet0/0/1.1] dhcp select interface //DHCP使用接口地址池的方式为内网用户分配IP地址
[Router-GigabitEthernet0/0/1.1] dhcp server dns-list 114.114.114.114 223.5.5.5 //配置的DNS-List 114.114.114.114是公用的DNS服务器地址,是不区分运营商的。在实际应用中,请根据运营商分配的DNS进行配置
[Router-GigabitEthernet0/0/1.1] quit
[Router] interface gigabitethernet 0/0/1.2
[Router-GigabitEthernet0/0/1.2] dhcp select interface
[Router-GigabitEthernet0/0/1.2] dhcp server dns-list 114.114.114.114 223.5.5.5
[Router-GigabitEthernet0/0/1.2] quit
代码语言:javascript复制# 配置公网接口的IP地址和静态路由。
[Router] interface gigabitethernet 0/0/2
[Router-GigabitEthernet0/0/2] ip address 200.0.0.2 255.255.255.0 //配置连接公网的接口GE0/0/2的IP地址200.0.0.2
[Router-GigabitEthernet0/0/2] quit
[Router] ip route-static 0.0.0.0 0.0.0.0 200.0.0.1 //配置静态缺省路由的下一跳指向公网提供的IP地址200.0.0.1
代码语言:javascript复制# 配置NAT功能,使内网用户可以访问外网。
[Router] acl number 2001
[Router-acl-basic-2001] rule 5 permit source 192.168.0.0 0.0.255.255 //NAT转换只对源IP地址是192.168.0.0/16网段的生效,并在接口GE0/0/2的出方向进行转换
[Router-acl-basic-2001] quit
[Router] interface gigabitethernet 0/0/2
[Router-GigabitEthernet0/0/2] nat outbound 2001
[Router-GigabitEthernet0/0/2] quit
代码语言:javascript复制配置路由器通过配置VLANIF接口,实现跨网段的三层转发。 # 配置VLANIF接口。
<Huawei> system-view
[Huawei] sysname Router
[Router] vlan batch 2 3
[Router] interface gigabitethernet 0/0/1
[Router-GigabitEthernet0/0/1] portswitch //将以太网接口从三层模式切换到二层模式。如果接口已经是二层模式,跳过该步骤
[Router-GigabitEthernet0/0/1] port link-type trunk
[Router-GigabitEthernet0/0/1] port trunk allow-pass vlan 2 3
[Router-GigabitEthernet0/0/1] quit [Router] interface vlanif 2
[Router-vlanif2] ip address 192.168.1.1 24 //配置VLANIF2的IP地址作为PC1的网关
[Router-vlanif2] quit
[Router] interface vlanif 3
[Router-vlanif3] ip address 192.168.2.1 24 //配置VLANIF3的IP地址作为PC2的网关
[Router-vlanif3] quit
代码语言:javascript复制# 配置DHCP功能,为内网用户分配IP地址并指定DNS服务器地址。
[Router] dhcp enable
[Router] interface vlanif 2
[Router-Vlanif2] dhcp select interface
[Router-Vlanif2] dhcp server dns-list 114.114.114.114 223.5.5.5 //配置的DNS-List 114.114.114.114是公用的DNS服务器地址,是不区分运营商的。在实际应用中,请根据运营商分配的DNS进行配置
[Router-Vlanif2] quit
[Router] interface vlanif 3
[Router-Vlanif3] dhcp select interface
[Router-Vlanif3] dhcp server dns-list 114.114.114.114 223.5.5.5
[Router-Vlanif3] quit
代码语言:javascript复制# 配置公网接口的IP地址和静态路由。
[Router] interface gigabitethernet 0/0/2
[Router-GigabitEthernet0/0/2] ip address 200.0.0.2 255.255.255.0
[Router-GigabitEthernet0/0/2]quit
[Router] ip route-static 0.0.0.0 0.0.0.0 200.0.0.1 //配置静态缺省路由的下一跳指向公网提供的IP地址200.0.0.1
代码语言:javascript复制# 配置NAT功能,使内网用户可以访问外网。
[Router] acl number 2001
[Router-acl-basic-2001] rule 5 permit source 192.168.0.0 0.0.255.255 //NAT转换只对源IP地址是192.168.0.0/16网段的生效,并在接口GE0/0/2的出方向进行转换
[Router-acl-basic-2001] quit
[Router] interface gigabitethernet 0/0/2
[Router-GigabitEthernet0/0/2] nat outbound 2001
[Router-GigabitEthernet0/0/2] quit
检查配置结果
配置PC1的IP地址为192.168.1.2/24,网关为192.168.1.1;PC2的IP地址为192.168.2.2/24,网关为192.168.2.1。配置外网PC的IP地址为200.0.0.1/24,网关为200.0.0.2。
配置完成后,PC1和PC2都可以Ping通外网的IP 200.0.0.1/24,PC1和PC2都可以访问Internet。
四、配置文件
Switch的配置文件
代码语言:javascript复制#
sysname Switch
#
vlan batch 2 to 3
#
interface GigabitEthernet1/0/1 port link-type trunk port trunk allow-pass vlan 2 to 3
#
interface GigabitEthernet1/0/2 port link-type access port default vlan 2
#
interface GigabitEthernet1/0/3 port link-type access port default vlan 3
#
return
Router的配置文件(路由器通过子接口进行三层转发的配置文件)
代码语言:javascript复制#
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 114.114.114.114 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 114.114.114.114 223.5.5.5
#
interface GigabitEthernet0/0/2 ip address 200.0.0.2 255.255.255.0 nat outbound 2001
#
ip route-static 0.0.0.0 0.0.0.0 200.0.0.1
#
return
Router的配置文件(路由器通过VLANIF接口进行三层转发的配置文件)
代码语言:javascript复制#
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 114.114.114.114 223.5.5.5
#
interface Vlanif3 ip address 192.168.2.1 255.255.255.0 dhcp select interface dhcp server dns-list 114.114.114.114 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 200.0.0.2 255.255.255.0 nat outbound 2001
#
ip route-static 0.0.0.0 0.0.0.0 200.0.0.1
#
return