2024年3月25日发(作者:)

NAT的分类

在cisco里,NAT按大类分有三种方式,分别是:

静态NAT(包括静态端口NAT)

动态NAT

端口复用NAT(即PAT)

其中静态NAT(包括静态端口NAT)是一对一的IP地址映射,是永久不变的。一旦配置完成,

映射永久存在于转换表中,永久不超时。而动态NAT与端口复用PAT是由匹配配置的第一个

数据包来触发的,动态建立的。在这两种的NAT中,由于终端一般是用户,他们不提供服务。

所以,在用户空闲的情况下(没有访问外网的需求),如果长期占用公网IP地址,势必造成

IP地址的浪费。此外,NAT条目的存在也会占用网络设备的资源,NAT超时时间解决了这些

问题。

以下实验如无说明,均使用以下拓扑。

静态NAT的NAT表

在R2做NAT配置

int f0/0

ip nat outside

int f0/1

ip nat inside

ip nat inside source static 23.1.1.3 12.1.1.3

ip nat inside source statci tcp 23.1.1.4 21 12.1.1.2 21

r2#sho ip nat translations

Pro Inside global Inside local Outside local Outside global

--- 12.1.1.3 23.1.1.3 --- ---

tcp 12.1.1.2:21 23.1.1.4:21 --- ---

可见,当配置完静态的NAT,立即存在于NAT表里,永远不会超时。

调整动态NAT的超时时间

在动态的nat里,可以调整nat的超时时间,ip nat translation timeout 60 把超时的

时间改为60秒。默认24小时。

R2配置如下:

ip nat pool cisco 23.1.1.4 23.1.1.6 netmask 255.255.255.0

access-list 1 permit 12.1.1.0 0.0.0.255

int s1/0

ip nat inside

int s1/1

ip nat outside

ip nat translation timeout 60 #NAT表里的动态条目的超市时间为60秒

r2#sho ip nat translations

此时的NAT表为空,我们用数据流来触发NAT:

R1#ping 23.1.1.3

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 12.1.1.1, timeout is 2 seconds:

.!!!!

Success rate is 80 percent (4/5), round-trip min/avg/max = 64/195/452 ms

r2#sho ip nat translations

Pro Inside global Inside local Outside local Outside global

--- 23.1.1.4 12.1.1.1 --- ---

debug ip nat 查看nat的超时时间:

r2#

*Sep 8 12:05:23.467: NAT: s=12.1.1.1->23.1.1.5, d=23.1.1.3 [35]

*Sep 8 12:05:23.659: NAT*: s=23.1.1.3, d=23.1.1.5->12.1.1.1 [35]

*Sep 8 12:05:23.843: NAT*: s=12.1.1.1->23.1.1.5, d=23.1.1.3 [36]

*Sep 8 12:05:24.035: NAT*: s=23.1.1.3, d=23.1.1.5->12.1.1.1 [36]

*Sep 8 12:06:24.651: NAT: expiring 23.1.1.5 (12.1.1.1)

在1分钟之后超时

查看R2的NAT表:

r2#sho ip nat translation

r2#

此时NAT表的记录为空,NAT条目超时。

调整端口复用NAT表的超时时间

在overload的nat里,因为有了端口上的转换,所以可以有更多的控制,如tcp,udp等等。

命令如下:ip nat translation udp-timeout 60 默认5分钟 Non-DNS UDP

ip nat translation dns-timeout 60 DNS的NAT默认1分

ip nat translation tcp-timeout 60 TCP的NAT 默认24小时,当同

一会话有RST或者FIN的时候,

默认再保留1分钟。

ip nat translation finrst-timeout 默认1分钟

ip nat translation icmp-timeout 60s icmp的nat的超时时间,icmp

的包在overload的nat也有端

口映射。默认24小时。

ip nat translation syn-timeout 60s 默认1分钟。