网络工程实验四:NAT的配置
#实验仅供参考,勿直接粘贴复制,用以学习交流#
#对于软件的使用,请移步到实验一观看#
1、实验目的:
(1)掌握网络地址转换的工作原理。
(2)掌握配置静态NAT和NAPT的方法。、
2、实验图像绘制与相应基础配置
绘制本次实验图像如下所示:
并且给对应的四台PC机配置相应的地址包括IP地址,子网掩码与网关地址,如下图所示:
PC1:
PC2:
PC3:
PC4:
配置路由器AR1,AR2的各接口的地址
AR1:
<huawei>sys
[huawei]sysname AR1
[AR1]interface GigabitEtthernet 0/0/0
[AR1- GigabitEtthernet 0/0/0 ]ip address 192.168.0.1 24
[AR1- GigabitEtthernet 0/0/0 ]quit
[AR1]interface GigabitEtthernet 0/0/1
[AR1-GigabitEthernet0/0/1]ip address 12.2.2.1 24
[AR1- GigabitEtthernet 0/0/1 ]quit
[AR1]display ip interface brief //用于显示结果自己检查端口IP是否正确
AR2:
<huawei>sys
[huawei]sysname AR2
[AR2]interface GigabitEtthernet 0/0/0
[AR2-GigabitEthernet0/0/0]ip address 12.2.2.254 24
[AR2- GigabitEtthernet 0/0/0 ]quit
[AR2]interface GigabitEtthernet 0/0/1
[AR2-GigabitEthernet0/0/1]ip address 20.1.2.1 24
[AR2- GigabitEtthernet 0/0/1 ]quit
[AR2]display ip interface brief //用于显示结果自己检查端口IP是否正确
3、配置静态路由,使得PC1和PC2能够通信
配置后的AR1,AR2静态路由器表和代码如下:
AR1:
<AR1>sys
[AR1]ip route-static 20.1.2.0 24 12.2.2.254
[AR1]display ip routing-table protocol static //显示静态路由器表,用于自查
AR2:
<AR2>sys
[AR2]ip route-static 192.168.0.0 24 12.2.2.1
[AR2]display ip routing-table protocol static //显示静态路由器表,用于自查
4、静态NAT配置和NAPT配置
PC1 ping PC4
将对应的私网地址192.168.0.2转变为12.2.2.2的公网地址与PC4地址20.1.2.3地址进行通信
[AR1]interface GigabitEthernet 0/0/1
[AR1-GigabitEthernet0/0/1]nat static global 12.2.2.2 inside 192.168.0.2
[AR1-GigabitEthernet0/0/1]nat static global 12.2.2.3 inside 192.168.0.3
[AR1-GigabitEthernet0/0/1]quit
演示成功结果如下图所示:
之后取消NAT静态,采用NAPT配置验证实验,
范例PC3 PING PC4
将对应的私网地址192.168.0.4转变为12.2.2.2的公网地址与PC4地址20.1.2.3地址进行通信
取消NAT静态的配置
[AR1]interface GigabitEthernet 0/0/1
[AR1-GigabitEthernet0/0/1]undo nat static global 12.2.2.2 inside 192.168.0.2
[AR1-GigabitEthernet0/0/1]undo nat static global 12.2.2.3 inside 192.168.0.3
[AR1-GigabitEthernet0/0/1]quit
NAPT实现代码:
[AR1]nat address-group 1 12.2.2.2 12.2.2.3
[AR1]acl 2000
[AR1-acl-basic-2000]rule 5 permit source 192.168.0.0 0.0.0.255
[AR1-acl-basic-2000]rule deny
[AR1-acl-basic-2000]quit
[AR1-GigabitEthernet0/0/1]nat outbound 2000 address-group 1
[AR1-GigabitEthernet0/0/1]quit
演示成功结果如下图所示:
#相比于前几个,实验四较为简单,但是后面逻辑较为困难#