网络地址转换NAT-动态NAT的使用范围和配置-思科EI,华为数通

网络地址转换NAT-动态NAT的使用范围和配置

什么是动态NAT?

使用公有地址池,并以先到先得的原则分配这些地址。当具有私有 IP 地址的主机请求访问 Internet 时,动态 NAT 从地址池中选择一个未被其它主机占用的 IP 地址一对一的转化。当数据会话结束后,路由器会释放掉公有IP地址回到地址池,以提供其他内部私有IP地址的转换。当同一时刻地址池中地址被NAT转换完毕,则其他私有地址不能够被NAT转换。

使用范围:

一般是我们公司内网中有设备需要去访问我们公网,我们就必须要做一个NAT地址转换,把我们私网的IP地址转换成我们公网的IP地址,这时,就需要使用动态NAT了,使用地址池中的公网地址进行IP地址转换,去访问我们的公网,下文是一个例子。

(描述实验的要求)

  1. 使用网络拓扑图给的地址网段配置各路由器PC机的IP地址和接口地址
  2. 使用ospf路由协议使得全网互通(除公网ISP)
  3. 使用PAT端口复用使得内网可以同时访问公网服务器

拓扑:

分析难点以及完成的思路

优先配置各PC机和路由器的地址,其次在路由器配置路由协议使得内网全网互通,最后在边界路由器做动态NAT,并且在边界路由器配置默认路由并下发给内网各路由器,全部指向边界路由器,注意动态NAT和PAT端口复用的区别,端口复用配置命令的关键词overload,还有进出口的选择,我们做动态NAT不需要加overload。

配置命令

  1. 配置ISP、PC机和路由器的IP地址接口地址和网关地址。
  2. 如果使用路由器代替PC或者server,需要加上"no ip routing"在全局配置模式下。

PC1:

PC1(config)#no ip routing

PC1(config-if)#interface Ethernet0/0

PC1(config-if)#ip address 192.168.1.1 255.255.255.0

PC1(config)#ip default-gateway 192.168.1.254

PC2:

PC2(config)#no ip routing

PC2(config-if)#interface Ethernet0/0

PC2(config-if)#ip address 192.168.1.2 255.255.255.0

PC2(config)#ip default-gateway 192.168.1.254

PC3:

PC3(config)#no ip routing

PC3(config-if)#interface Ethernet0/0

PC3(config-if)#ip address 192.168.3.1 255.255.255.0

PC3(config)#ip default-gateway 192.168.3.254

Sever:

server(config)#no ip routing

server(config-if)#interface Ethernet0/0

server(config-if)#ip address 192.168.2.1 255.255.255.0

server(config)#ip default-gateway 192.168.2.254

ISP:

ISP(config)#interface Serial2/0

ISP(config-if)#ip address 200.1.1.100 255.255.255.0

R1:(配置接口IP地址,使用OSPF路由协议,通告直连网段)

R1(config-if)#interface Ethernet0/0

R1(config-if)#ip address 192.168.1.254 255.255.255.0

R1(config-if)#interface Ethernet0/1

R1(config-if)#ip address 10.1.1.1 255.255.255.0

R1(config)#router ospf 1

R1(config-router)#router-id 1.1.1.1

R1(config-router)#network 10.1.1.0 0.0.0.255 area 0

R1(config-router)#network 192.168.1.0 0.0.0.255 area 0

R2:(配置接口IP地址,使用OSPF路由协议,通告直连网段)

R2(config-if)#interface Ethernet0/1

R2(config-if)#ip address 192.168.2.254 255.255.255.0

R2(config-if)#interface Ethernet0/0

R2(config-if)#ip address 10.1.1.2 255.255.255.0

R2(config-if)#interface Ethernet0/2

R2(config-if)#ip address 10.1.2.1 255.255.255.0

R2(config)#router ospf 1

R2(config-router)#router-id 2.2.2.2

R2(config-router)#network 10.1.1.0 0.0.0.255 area 0

R2(config-router)#network 10.1.2.0 0.0.0.255 area 0

R2(config-router)#network 192.168.2.0 0.0.0.255 area 0

R3:(配置接口IP地址,使用OSPF路由协议,通告直连网段)

R3(config-if)#interface Ethernet0/1

R3(config-if)#ip address 192.168.3.254 255.255.255.0

R3(config-if)#interface Ethernet0/0

R3(config-if)#ip address 10.1.3.1 255.255.255.0

R3(config)#router ospf 1

R3(config-router)#router-id 3.3.3.3

R3(config-router)#network 10.1.3.0 0.0.0.255 area 0

R3(config-router)#network 192.168.3.0 0.0.0.255 area 0

R4:(配置接口IP地址,使用OSPF路由协议,通告直连网段)

R4(config-if)#interface Ethernet0/0

R4(config-if)#ip address 10.1.2.2 255.255.255.0

R4(config-if)#interface Ethernet0/1

R4(config-if)#ip address 10.1.3.2 255.255.255.0

R4(config-if)#interface Serial2/0

R4(config-if)#ip address 200.1.1.2 255.255.255.0

R4(config)#router ospf 1

R4(config-router)#router-id 4.4.4.4

R4(config-router)#network 10.1.2.0 0.0.0.255 area 0

R4(config-router)#network 10.1.3.0 0.0.0.255 area 0

R4(config-router)#default-information originate ----------公网IP地址无法在内网中出现,故下发一条默认路由,为内网设

备提供到达公网IP地址的路径

  1. 使用拓扑给的唯一地址在边界路由器(R4)配置动态NAT,划出一段地址池,根据拓扑中给出的信息是从200.1.1.1到200.1.1.100是可以使用的地址,作为我们的地址池进行绑定,并给出可以上网的网段信息,可以使用访问控制列表进行过滤。

R4(config)#ip nat pool zsl 200.1.1.10 200.1.1.12 netmask 255.255.255.0

R4(config)#ip nat inside source list 1 pool zsl

R4(config)#ip route 0.0.0.0 0.0.0.0 200.1.1.100

R4(config)#access-list 1 permit 192.168.0.0 0.0.255.255

我们在地址池中选取了三个有效地址,但我们内网中有四台设备需要上网,这时我们可以看一下动态NAT的缺点,采取先到先得的方式进行地址分配,所以我们这个实验可以看到至少有一台设备是无法ping通的。如果需要ping通,那么必须要等待有一台设备将他的公网地址释放,才可以让另一台设备使用,所以动态NAT是非常浪费我们公网地址的,接下来我们来测试一下这个实验。

PC1#ping 200.1.1.100

Type escape sequence to abort.

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

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 4/210/1016 ms

PC2#ping 200.1.1.100

Type escape sequence to abort.

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

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 10/211/1016 ms

Server#ping 200.1.1.100

Type escape sequence to abort.

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

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 9/210/1014 ms

PC3#ping 200.1.1.100

Type escape sequence to abort.

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

UUUUU

Success rate is 0 percent (0/5)

总结:

  1. 不要把inside和outside应用的接口弄错。
  2. 动态NAT映射表条目存在一定生存时间,时间超过时转换条目将会被自动删除。一对一的动态NAT超时时间为10分钟(600秒);只有等待将使用后的地址释放之后,才可以给别的设备进行使用,这是动态NAT的一个机制。
相关推荐
宝哥网络砖家8 小时前
软路由品牌推荐先看设备站在哪一层
网络·软路由·routeros
时间的拾荒人9 小时前
Linux 系统命令与网络、磁盘、日志监控(下篇):性能原理与优化
linux·运维·网络
代码改善世界11 小时前
鸿蒙电脑能被远程控制吗?ToDesk鸿蒙双向远控能力解析
华为·电脑·harmonyos
nice_lcj52012 小时前
【从零理解计算机网络 · 13】DNS 解析全流程:域名怎么变成 IP,慢在哪
网络·计算机网络·面试·dns·域名解析·cname·ttl
张张123y19 小时前
个人助手型 Agent 的六个工程细节:Hermes 与 OpenClaw 的审批、委派、上下文与调度
网络·人工智能·开源·后端开发·ai agent
nice_lcj52020 小时前
【从零理解计算机网络 · 15】完整串联:一次请求的全旅程,以及那道经典面试题
网络·计算机网络·http·面试·tcp·总结·网络排查
光电笑映1 天前
TCP 为什么可靠?从三次握手、滑动窗口到拥塞控制全面拆解(下)
linux·网络·网络协议·tcp
huang_xiaoen2 天前
鸿蒙手机远程控制电脑哪个好用?2026鸿蒙远控软件横测推荐
华为·harmonyos·远程工作·远程工具·远程办公
如夏倾城2 天前
入侵检测系统(IDS)原理、部署模式与 IPS/防火墙对比
大数据·网络·人工智能·网络安全·云原生·架构·kubernetes
LabVIEW开发2 天前
LabVIEW 用 25 ns 精度捕捉赛车发动机共振
网络·labview·labview知识·labview功能·labview程序