一、实验拓扑图

实验目的 基于gns3软件上操作 1.配置静态NAT 2.配置动态NAT 3.配置动态PAT

1.配置静态NAT R1配置 在R1上配置直连网段(0/0和0/1接口) R1>en R1#conf t R1(config)#int f0/0 R1(config-if)#ip address 192.168.10.1 255.255.255.0 R1(config-if)#no shutdown R1(config)#int f0/1 R1(config-if)#ip address 12.0.0.1 255.255.255.0 R1(config-if)#no shutdown

将内网的192.168.10.10转换为12.0.0.10用来与公网通信(一对一的形式,不可以重复) R1(config)#ip nat inside source static 192.168.10.10 12.0.0.2

在内部接口和外部接口上启用NAT R1(config)#int f0/0 R1(config-if)#ip nat inside R1(config-if)#exit R1(config)#int f0/1 R1(config-if)#ip nat outside

R2配置 R2>en R2#conf t R2(config)#int f0/0 R2(config-if)#ip address 12.0.0.21 255.255.255.0 R2(config-if)#no shutdown

pc上的配置(如图所示) vpsc[1]ip 192.168.10.10 192.168.10.1 VPCS[1]> 2 VPCS[2]> ip 192.168.10.20 192.168.10.1

验证pc1如图所示:

通过debug 实时监控如图所示: R1#debug ip nat

当PC1执行PING命令之后,我在R1上运行dubug ip nat后,可以看到更加详细的转换。源地址192.168.10.10到达路由器之后转换成12.0.0.2与公网12.0.0.21进行通信。

2.配置动态NAT R1配置 配置之前,需要将任务1中配置的静态NAT删除掉 R1(config)#no ip nat inside source static 192.168.1.10 12.0.0.2 R1(config)#int f0/0 R1(config-if)#no ip nat inside R1(config-if)#exit R1(config)#int f0/1 R1(config-if)#no ip nat outside

定义内部网络中允许访问外部网络的访问控制列表 R1(config)#access-list 10 permit 192.168.10.0 0.0.0.255

定义合法IP地址池 R1(config)#ip nat pool test1 12.0.0.1 12.0.0.31 netmask 255.255.255.0

实现网络地址转换 R1(config)#ip nat inside source list 10 pool test1

在内部和外部接口启用NAT R1(config)#int f0/0 R1(config-if)#ip nat inside R1(config-if)#exit R1(config)#int s1/0 R1(config-if)#ip nat outside

R2配置 R2>en R2#conf t R2(config)#int f0/0 R2(config-if)#ip address 12.0.0.21 255.255.255.0 R2(config-if)#no shutdown

pc上的配置(如图所示) vpsc[1]ip 192.168.10.10 192.168.10.1 VPCS[1]> 2 VPCS[2]> ip 192.168.10.20 192.168.10.1

验证pc1如图所示:

通过debug 实时监控如图所示: R1#debug ip nat

3.配置动态PAT R1配置 R1#conf t R1(config)#no ip nat inside source list 10 pool test1        R1(config)#no access-list 10          R1(config)#no ip nat pool test1                    R1(config)#int f0/0 R1(config-if)#no ip nat inside R1(config)#int f1/0 R1(config-if)#no ip nat outside R1(config-if)#end

定义内部网络中允许访问外部网络的访问控制列表 R1(config)#access-list 10 permit 192.168.10.0 0.0.0.255

基于外网口的地址转换 ip nat inside sourse list 10 int fa 0/1 overload

由于使用外部接口地址,所以不用再定义IP地址池了

R2配置 R2>en R2#conf t R2(config)#int f0/0 R2(config-if)#ip address 12.0.0.21 255.255.255.0 R2(config-if)#no shutdown

pc上的配置(如图所示) vpsc[1]ip 192.168.10.10 192.168.10.1 VPCS[1]> 2 VPCS[2]> ip 192.168.10.20 192.168.10.1

pc上的配置(如图所示) vpsc[1]ip 192.168.10.10 192.168.10.1 VPCS[1]> 2 VPCS[2]> ip 192.168.10.20 192.168.10.1

验证pc1如图所示:

通过debug 实时监控如图所示: R1#debug ip nat

OK,实验到此圆满完成!我们今天的实验主要演示了基于接口动态获取外部全局IP实现NAT转换和基于地址池获取外部全局IP实现NAT转换。这里的主要区别于不同模式的几条命令。