网络地址转换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的一个机制。
相关推荐
脑子缺根弦1 小时前
融合优势:SIP 广播对讲联动华为会议 全场景沟通响应提速
华为·音视频·广播对讲系统
_丿丨丨_5 小时前
XSS(跨站脚本攻击)
前端·网络·xss
一只栖枝6 小时前
HCIA-Security 认证精讲!网络安全理论与实战全掌握
网络·web安全·网络安全·智能路由器·hcia·it·hcia-security
FileLink跨网文件交换6 小时前
文件摆渡系统十大软件|文件摆渡系统如何构建网络安全呢?
网络
晨欣9 小时前
大型语言模型(LLM)在网络安全中最具商业价值的应用场景(Grok3 回答 DeepSearch模式)
网络·web安全·语言模型
有书Show10 小时前
个人IP的塑造方向有哪些?
网络·网络协议·tcp/ip
HHRL-yx10 小时前
C++网络编程 5.TCP套接字(socket)通信进阶-基于多线程的TCP多客户端通信
网络·c++·tcp/ip
迈威通信10 小时前
接口黑洞?破!安全堡垒?筑!冰火炼狱?战!MES7114W终极掌控
网络·安全
迷曳10 小时前
27、鸿蒙Harmony Next开发:ArkTS并发(Promise和async/await和多线程并发TaskPool和Worker的使用)
前端·华为·多线程·harmonyos
baynk11 小时前
wireshark的常用用法
网络·测试工具·wireshark·ctf