[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
# 配置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
# 配置公网接口的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
# 配置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
3、检查配置结果
配置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的配置文件
#
sysname Switch
#
vlan batch 2 to 3
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 3
#
interface GigabitEthernet0/0/2
port link-type access
port default vlan 2
#
【华为二层交换机与路由器对接上网配置示例】interface GigabitEthernet0/0/3
port link-type access
port default vlan 3
#
return
Router的配置文件(路由器通过子接口进行三层转发的配置文件)
#
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接口进行三层转发的配置文件)
#
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
推荐阅读
- 华为|支持海洋潜水的华为手表来了!华为WATCH GT 3 Pro这次有什么惊喜?
- 华为交换机telnet和SSH配置实验案例
- 华为p40和苹果11哪个好?
- 华为|华为Watch GT3 Pro系列官宣:海洋30米自由潜运动无压力
- 如何在华为应用市场上传APP???
- jkmal00b华为什么型号多少钱?jkmal00a华为是什么型号
- 拍照|工信部发布手机图像视频防抖性能标准:华为、OPPO等联合制订
- p30pro的屏幕刷新率是多少?华为p30pro屏幕刷新率是多少赫兹
- 2020年,华为研发总费用为1418.93亿元?华为每年研发费用占比
- 华为三层交换机与路由器对接上网配置示例