网络地址转换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的一个机制。
相关推荐
2301_780789667 小时前
DDoS 攻击溯源:DNS 水印标记 + 区块链存证的双保险
运维·服务器·网络·云原生·ddos
less_121387 小时前
HarmonyOS WPS Open SDK:打开时配置水印与修订模式
华为·harmonyos·wps
2601_9494999412 小时前
芯瑞科技 DT-1414 光模块工程实测:完美兼容博通(安华高) HFBR-1414PTZ,VCSEL 替代方案
大数据·网络·人工智能·科技·光模块
云边云科技_云网融合13 小时前
连锁门店 POS、监控、IoT 设备网络不稳定怎么解决?
网络·物联网
小雨青年14 小时前
【HarmonyOS 7 沉浸光感深度实战】 03 五档 ImmersiveStyle 到底怎么选
华为·harmonyos
XR12345678814 小时前
学校宿舍区网络方案对比:多终端高并发下的认证、管理与体验
网络
March.s14 小时前
IP 存储核心 iSCSI:原理拆解 + 无报错实战指南
网络·网络协议·tcp/ip
星恒讯工业路由器14 小时前
远程访问技术解析:从内网穿透到安全隧道的三种主流方案
网络·信息与通信·内网穿透·远程访问·vpn隧道
超智算科技15 小时前
超智算领衔协办“NVIDIA创业企业展示·西安站”,全栈AI服务赋能行业生态协同发展
大数据·网络·人工智能·物联网·百度
云端漫步198715 小时前
HarmonyOS NEXT AI 智能生活助手:性能优化
华为·性能优化·生活·harmonyos