实验14-1:静态NAT 配置

Ø    实验目的
通过本实验可以掌握
(1)静态NAT 的特征
(2)静态NAT 基本配置和调试

Ø    拓扑结构

实验步骤
n    步骤1:配置路由器R1 提供NAT 服务
R1(config)#ip nat inside source static 192.168.1.1 202.96.1.3
R1(config)#ip nat inside source static 192.168.1.2 202.96.1.4
//配置静态NAT 映射
R1(config)#interface f0/0
R1(config)#ip add 192.168.1.254 255.255.255.0
R1(config-if)#no sh
R1(config-if)#ip nat inside
//配置NAT 内部接口
R1(config)#interface s1/0
R1(config-if)#ip add 202.96.1.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#ip nat outside
//配置NAT 外部接口
R1(config)#router rip
R1(config-router)#version 2
R1(config-router)#no auto-summary
R1(config-router)#network 202.96.1.0

n    步骤2:配置路由器R2
Router(config)#host R2
R2(config)#int s1/0
R2(config-if)#ip add 202.96.1.2 255.255.255.0
R2(config-if)#int lo0
R2(config-if)#ip add 2.2.2.2 255.255.255.0
R2(config)#router rip
R2(config-router)#version 2
R2(config-router)#no auto-summary
R2(config-router)#network 202.96.1.0
R2(config-router)#network 2.0.0.0

Ø    实验调试
n    debug ip nat
该命令可以查看地址翻译的过程。
在PC1 和PC2 上Ping 2.2.2.2(路由器R2 的环回接口),此时应该是通的,路由器R1的输出信息如下:
PC1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 12/52/104 ms

PC2#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 36/69/112 ms

R1#debug ip nat
*Mar  1 00:14:24.799: NAT*: s=192.168.1.1->202.96.1.3, d=2.2.2.2 [0]
*Mar  1 00:14:24.835: NAT*: s=2.2.2.2, d=202.96.1.3->192.168.1.1 [0]
*Mar  1 00:14:24.887: NAT*: s=192.168.1.1->202.96.1.3, d=2.2.2.2 [1]
*Mar  1 00:14:24.947: NAT*: s=2.2.2.2, d=202.96.1.3->192.168.1.1 [1]
………………….
*Mar  1 00:15:19.239: NAT*: s=192.168.1.2->202.96.1.4, d=2.2.2.2 [0]
*Mar  1 00:15:19.267: NAT*: s=2.2.2.2, d=202.96.1.4->192.168.1.2 [0]
*Mar  1 00:15:19.299: NAT*: s=192.168.1.2->202.96.1.4, d=2.2.2.2 [1]
*Mar  1 00:15:19.311: NAT*: s=2.2.2.2, d=202.96.1.4->192.168.1.2 [1]

以上输出表明了NAT 的转换过程。首先把私有地址“192.168.1.1”和“192.168.1.2”
分别转换成公网地址“202.96.1.3”和“202.96.1.4”访问地址“2.2.2.2”,然后回来的时候把公网地址“202.96.1.3”和 “202.96.1.4”分别转换成私有地址“192.168.1.1”和“192.168.1.2”。

n    show ip nat translations
该命令用来查看NAT 表,静态映射时,NAT 表一直存在
R1#show ip nat translations
Pro Inside global      Inside local       Outside local      Outside global
--- 202.96.1.3         192.168.1.1        ---                ---
--- 202.96.1.4         192.168.1.2        ---                ---
以上输出表明了内部全局地址和内部局部地址的对应关系。

【术语】
① 内部局部(inside local)地址:在内部网络使用的地址,往往是RFC1918 地址;
② 内部全局(inside global)地址:用来代替一个或多个本地IP 地址的、对外的、
向NIC 注册过的地址;
③ 外部局部(outside local)地址:一个外部主机相对于内部网络所用的IP 地址。
不一定是合法的地址;
④ 外部全局(outside global)地址:外部网络主机的合法IP 地址。

实验14-2:动态NAT

Ø    实验目的
通过本实验可以掌握:
(1)动态NAT 的特征
(2)动态NAT 配置和调试

Ø    拓扑结构

实验步骤
n    步骤1 : 实验前先删除实验13-1的静态NAT的配置
R1(config)#no ip nat inside source static 192.168.1.1 202.96.1.3
R1(config)#no ip nat inside source static 192.168.1.2 202.96.1.4

n    步骤2:配置路由器R1 提供NAT 服务
R1(config)#ip nat pool NAT 202.96.1.3 202.96.1.100 netmask 255.255.255.0           //配置动态NAT 转换的地址池
R1(config)#ip nat inside source list 1 pool NAT
//配置动态NAT 映射
R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255
//允许动态NAT 转换的内部地址范围
R1(config)#interface f0/0
R1(config-if)#ip nat inside
R1(config-if)#interface s1/0
R1(config-if)#ip nat outside

Ø    实验调试
在PC1 上ping 2.2.2.2(路由器R2 的环回接口),在PC2 上分别telnet 2.2.2.2(路由器R2 的环回接口),调试结果如下:
n    debug ip nat
       R1#debug ip nat
       *Mar  1 00:31:18.327: NAT*: s=192.168.1.1->202.96.1.4, d=2.2.2.2 [10]
*Mar  1 00:31:18.383: NAT*: s=2.2.2.2, d=202.96.1.4->192.168.1.1 [10]
        ……………………….
*Mar  1 00:31:28.215: NAT*: s=192.168.1.2->202.96.1.3, d=2.2.2.2 [49342]
*Mar  1 00:31:28.307: NAT*: s=2.2.2.2, d=202.96.1.3->192.168.1.2 [17311]

【提示】
如果动态NAT 地址池中没有足够的地址作动态映射,则会出现类似下面的信息,提示NAT 转换失败,并丢弃数据包。
*Feb 22 09:02:59.075: NAT: translation failed (A), dropping packet s=192.168.1.2 d=2.2.2.2

n    show ip nat translations

R1#show ip nat tran
Pro Inside global      Inside local       Outside local      Outside global
icmp 202.96.1.5:3      192.168.1.1:3      2.2.2.2:3          2.2.2.2:3
--- 202.96.1.5         192.168.1.1        ---                ---
tcp 202.96.1.3:62479   192.168.1.2:62479  2.2.2.2:23         2.2.2.2:23
--- 202.96.1.3         192.168.1.2        ---                ---

以上信息表明当PC1 和PC2 第一次访问“2.2.2.2”地址的时候,NAT 路由器R1 为主机PC1 和PC2 动态分配两个全局地址“202.96.1.5”和“202.96.1.3,在NAT 表表中生成两条动态映射的记录,同时会在NAT 表中生成和应用向对应的协议和端口号的记录(过期时间为60 秒)。在动态映射没有过期(过期时间为86400 秒)之前,再有应用从相同主机发起时,NAT 路由器直接查NAT表,然后为应用分配相应的端口号。

n     show ip nat statistics
该命令用来查看NAT 转换的统计信
R1#show ip nat statistics
Total active translations: 2 (0 static, 2 dynamic; 0 extended)
//有2个转换是动态转化,
Outside interfaces:
  Serial1/0                     //NAT 外部接口
Inside interfaces:
  FastEthernet0/0
Hits: 107  Misses: 10            //NAT 内部接口
CEF Translated packets: 117, CEF Punted packets: 0
Expired translations: 8           //NAT 表中过期的转换
Dynamic mappings:             //动态映射
-- Inside Source
[Id: 1] access-list 1 pool nat refcount 2
 pool nat: netmask 255.255.255.0         //地址池名字和掩码
      start 202.96.1.3 end 202.96.1.100       //地址池范围
      type generic, total addresses 98, allocated 2 (2%), misses 0
//共98 个地址,分出去2 个
Queued Packets: 0

实验14-3: PAT 配置

实验目的
通过本实验可以掌握:
(1)PAT 的特征
(2)overload 的使用
(3)PAT 配置和调试

Ø     拓扑结构

实验步骤
n    步骤1 : 实验前先删除实验13-2的动态NAT的配置
 R1(config)#no ip nat inside source list 1 pool NAT

n    步骤2 : 配置路由器R1 提供NAT 服务
R1(config)#ip nat pool NAT 202.96.1.3 202.96.1.100 netmask 255.255.255.0
R1(config)#ip nat inside source list 1 pool NAT overload //配置PAT
R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255
R1(config)#interface f0/0
R1(config-if)#ip nat inside
R1(config-if)#interface s1/0
R1(config-if)#ip nat outside

Ø     实验调试
在PC1 上ping 2.2.2.2(路由器R2 的环回接口),在PC2 上分别telnet 2.2.2.2(路由器R2 的环回接口),调试结果如下:
n    debug ip nat
   R1#debug ip nat
*Mar  1 00:54:32.479: NAT*: s=192.168.1.1->202.96.1.3, d=2.2.2.2 [20]
*Mar  1 00:54:32.551: NAT*: s=2.2.2.2, d=202.96.1.3->192.168.1.1 [20]
……………………
*Mar  1 00:54:42.451: NAT*: s=192.168.1.2->202.96.1.3, d=2.2.2.2 [19447]
*Mar  1 00:54:42.579: NAT*: s=2.2.2.2, d=202.96.1.3->192.168.1.2 [12582]

n    show ip nat translations
     R1#show ip nat tran
Pro Inside global      Inside local       Outside local      Outside global
icmp 202.96.1.3:5      192.168.1.1:5      2.2.2.2:5          2.2.2.2:5
tcp 202.96.1.3:27119   192.168.1.2:27119  2.2.2.2:23         2.2.2.2:23
以上输出表明进行PAT 转换使用的是同一个IP 地址的不同端口号。

n    show ip nat statistics
    R1#show ip nat statistics
Total active translations: 0 (0 static, 0 dynamic; 0 extended)
Outside interfaces:
  Serial1/0
Inside interfaces:
  FastEthernet0/0
Hits: 155  Misses: 14
CEF Translated packets: 169, CEF Punted packets: 0
Expired translations: 12
Dynamic mappings:
-- Inside Source
[Id: 2] access-list 1 pool nat refcount 0
    pool nat: netmask 255.255.255.0
        start 202.96.1.3 end 202.96.1.100
        type generic, total addresses 98, allocated 0 (0%), misses 0
Queued Packets: 0

【提示】
动态NAT 的过期时间是86400 秒,PAT 的过期时间是60 秒,通过命令“show ip nat translations verbose”可以查看。也可以通过下面的命令来修改超时时间:
R1(config)#ip nat translation timeout timeout
//参数timeout 的范围是0-2147483。
如果主机的数量不是很多, 可以直接使用outside 接口地址配置PAT,不必定义地址池,命令如下:
R1(config)#ip nat inside source list 1 interface s1/0 overload

最新文章

  1. Linux环境数据备份Python脚本
  2. js 数组赋值问题 :值传递还是引用?
  3. Careercup - Google面试题 - 4557716425015296
  4. bzoj 3242: [Noi2013]快餐店 章鱼图
  5. hdu 1788 Chinese remainder theorem again(最小公倍数)
  6. Ajax实现三级联动(0520)
  7. docker 现实---中小企业docker环境结构(五)
  8. PAT (Advanced Level) 1101. Quick Sort (25)
  9. 3D GIS 应用开发 —— 基于 Mapbox GL 的实践总结
  10. Python发邮件的小脚本
  11. 使用脚本与orm模型交互对数据库操作
  12. 数学集合:N Z Q R C
  13. TCP客户端【TcpClient】
  14. maven 项目 编码
  15. Java 8 新日期时间 API
  16. 通过http请求传递xml流和接收xml流的代码示例
  17. ZetCode PyQt4 tutorial work with menus, toolbars, a statusbar, and a main application window
  18. [转]Porting to Oracle with Entity Framework NLog
  19. UIImageView只显示一半
  20. 时区缩写 UTC, CST, GMT, CEST 以及转换

热门文章

  1. 计算机专业如何高质量的走完大学四年?毕业成为Offer收割机
  2. JAVA优化篇 如何找到运行缓慢的线程
  3. 1068 万绿丛中一点红 (20分)C语言
  4. 1051 复数乘法 (15 分)C语言
  5. shiro采坑指南—基础概念与实战
  6. 变量内容的删除、取代与替换(optional)
  7. Map2Shp7专业版新增功能
  8. rest实践1
  9. Elasticsearch系列---实战零停机重建索引
  10. MySql数据主从同步配置