网络端口地址转换 NAPT 配置

本文涉及的产品
公网NAT网关,每月750个小时 15CU
简介: 网络端口地址转换 NAPT 配置

你是某公司的网络管理员,公司办公网需要接入互联网,公司只向 ISP 申请了一条专线,该专线分配了一个公司 IP 地址,配置实现全公司的主机都能访问外网。

技术原理
NAT 将网络划分为内部网络和外部网络两部分,局域网主机利用 NAT 访问网络时,是将局域网内部的本地地址转换为全局地址(互联网合法的 IP 地址)后转发数据包;
NAT 分为两种类型:NAT(网络地址转换)和 NAPT(网络端口地址转换 IP 地址对应一个全局地址)。
NAPT:使用不同的端口来映射多个内网 IP 地址到一个指定的外网 IP 地址,多对一。
NAPT 采用端口多路复用方式。内部网络的所有主机均可共享一个合法外部 IP 地址实现对 Internet 的访问,从而可以最大限度地节约 IP 地址资源。同时,又可隐藏网络内部的所有主机,有效避免来自 Internet 的攻击。因此,目前网络中应用最多的就是端口多路复用方式。

ISP(Internet Service Provider),互联网服务提供商,即向广大用户综合提供互联网接入业务、信息业务和增值业务的电信运营商。ISP是经国家主管部门批准的正式运营企业,享受国家法律保护。

实验步骤
新建 Packet Tracer 拓扑图

网络端口地址转换 NAPT 配置网络端口地址转换 NAPT 配置

(1)R1 为公司出口路由器,其与 ISP 路由器之间通过 V.35 电缆串口连接,DCE 端连接在 R1 上,配置其时钟频率 64000;
(2)配置 PC 机、服务器及路由器接口 IP 地址;
(3)在各路由器上配置静态路由协议,让 PC 间能相互 Ping 通;
(4)在 R1 上配置 NAPT。
(5)在 R1 上定义内外网络接口。
(6)验证主机之间的互通性。

实验设备
PC 2 台;Server-PT 1 台;Switch_2950-24 1 台 Router-PT 2 台;直通线;交叉线;DCE串口线

PC1

192.168.1.2
255.255.255.0
192.168.1.1

PC2

192.168.1.3
255.255.255.0
192.168.1.1

Server

200.1.2.2
255.255.255.0
200.1.2.1

R1

en
conf t
host R1
int fa 0/0
ip address 192.168.1.1 255.255.255.0
no shutdown
int s 2/0
ip address 200.1.1.1 255.255.255.0
no shutdown
clock rate 64000

R2

en
conf t
host R2
int s 2/0
ip address 200.1.1.2 255.255.255.0
no shutdown
int fa 0/0
ip address 200.1.2.1 255.255.255.0
no shutdown

R1

exit
ip route 200.1.2.0 255.255.255.0 200.1.1.2

R2

exit
ip route 192.168.1.0 255.255.255.0 200.1.1.1
end
show ip route

PC1

CMD
ping 200.1.2.2 (success)

Web 浏览器
http://200.1.2.2 (success)

R1

int fa 0/0
ip nat inside
int s 2/0
ip nat outside
exit
access-list 1 permit 192.168.1.0 0.0.0.255
ip nat pool jaking 200.1.1.3 200.1.1.3 netmask 255.255.255.0 #设置名称为jaking的地址池,起始和终止IP都是200.1.1.3
ip nat inside source list 1 pool jaking overload (无 overload 表示多对多,有 overload 表示多对一)
end
show ip nat translations(无结果)

PC1

Web 浏览器
http://200.1.2.2 (success)

R1

show ip nat translations(有 1 个结果)

PC2

Web 浏览器
http://200.1.2.2 (success)

R1

show ip nat translations(有 2 个结果)
实战演练
R1

Continue with configuration dialog? [yes/no]: n

Press RETURN to get started!

Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host R1
R1(config)#int fa 0/0
R1(config-if)#ip add 192.168.1.1 255.255.255.0
R1(config-if)#no shut

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

R1(config-if)#int s 2/0
R1(config-if)#ip add 200.1.1.1 255.255.255.0
R1(config-if)#no shut

%LINK-5-CHANGED: Interface Serial2/0, changed state to down
R1(config-if)#clock rate 64000
R1(config-if)#

R2

Continue with configuration dialog? [yes/no]: n

Press RETURN to get started!

Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host R2
R2(config)#int s 2/0
R2(config-if)#ip add 200.1.1.2 255.255.255.0
R2(config-if)#no shut

%LINK-5-CHANGED: Interface Serial2/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up

R2(config-if)#int fa 0/0
R2(config-if)#ip add 200.1.2.1 255.255.255.0
R2(config-if)#no shut

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

R2(config-if)#

R1

R1(config-if)#exit
R1(config)#ip route 200.1.2.0 255.255.255.0 200.1.1.2

R2

R2(config-if)#exit
R2(config)#ip route 192.168.1.0 255.255.255.0 200.1.1.1
R2(config)#end
R2#
%SYS-5-CONFIG_I: Configured from console by console

R2#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

   D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
   N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
   E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
   i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
   * - candidate default, U - per-user static route, o - ODR
   P - periodic downloaded static route

Gateway of last resort is not set

S 192.168.1.0/24 [1/0] via 200.1.1.1
C 200.1.1.0/24 is directly connected, Serial2/0
C 200.1.2.0/24 is directly connected, FastEthernet0/0

PC1

CMD
ping 200.1.2.2 (success)

PC>ipconfig

IP Address......................: 192.168.1.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.1.1

PC>ping 200.1.2.2

Pinging 200.1.2.2 with 32 bytes of data:

Request timed out.
Reply from 200.1.2.2: bytes=32 time=24ms TTL=126
Reply from 200.1.2.2: bytes=32 time=25ms TTL=126
Reply from 200.1.2.2: bytes=32 time=20ms TTL=126

Ping statistics for 200.1.2.2:

Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),

Approximate round trip times in milli-seconds:

Minimum = 20ms, Maximum = 25ms, Average = 23ms

PC>ping 200.1.2.2

Pinging 200.1.2.2 with 32 bytes of data:

Reply from 200.1.2.2: bytes=32 time=25ms TTL=126
Reply from 200.1.2.2: bytes=32 time=20ms TTL=126
Reply from 200.1.2.2: bytes=32 time=23ms TTL=126
Reply from 200.1.2.2: bytes=32 time=25ms TTL=126

Ping statistics for 200.1.2.2:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 20ms, Maximum = 25ms, Average = 23ms

Web 浏览器
http://200.1.2.2 (success)
网络端口地址转换 NAPT 配置网络端口地址转换 NAPT 配置

PC2

CMD
ping 200.1.2.2 (success)

PC>ipconfig

IP Address......................: 192.168.1.3
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.1.1

PC>ping 200.1.2.2

Pinging 200.1.2.2 with 32 bytes of data:

Reply from 200.1.2.2: bytes=32 time=31ms TTL=126
Reply from 200.1.2.2: bytes=32 time=17ms TTL=126
Reply from 200.1.2.2: bytes=32 time=19ms TTL=126
Reply from 200.1.2.2: bytes=32 time=23ms TTL=126

Ping statistics for 200.1.2.2:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 17ms, Maximum = 31ms, Average = 22ms

Web 浏览器
http://200.1.2.2 (success)
网络端口地址转换 NAPT 配置网络端口地址转换 NAPT 配置

R1

R1(config)#int fa 0/0
R1(config-if)#ip nat inside
R1(config-if)#int s 2/0
R1(config-if)#ip nat outside
R1(config-if)#exit
R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255
R1(config)#ip nat pool jaking 200.1.1.3 200.1.1.3 netmask 255.255.255.0
R1(config)#ip nat inside source list 1 pool jaking overload
R1(config)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console

R1#show ip nat translations
R1#

PC1

Web 浏览器
http://200.1.2.2 (success)

R1
show ip nat translations(有 1 个结果)

R1#show ip nat translations
Pro Inside global Inside local Outside local Outside global
tcp 200.1.1.3:1026 192.168.1.2:1026 200.1.2.2:80 200.1.2.2:80

PC2

Web 浏览器
http://200.1.2.2 (success)

R1
show ip nat translations(有 2 个结果)

R1#show ip nat translations
Pro Inside global Inside local Outside local Outside global
tcp 200.1.1.3:1026 192.168.1.2:1026 200.1.2.2:80 200.1.2.2:80
tcp 200.1.1.3:1024 192.168.1.3:1026 200.1.2.2:80 200.1.2.2:80
总结
至此,用思科模拟器进行网络端口地址转换 NAPT 配置完毕。

相关文章
|
17天前
|
网络协议
iptables配置tcp端口转发
iptables配置tcp端口转发
25 1
|
28天前
|
监控 Linux Shell
【Shell 命令集合 网络通讯 】Linux 配置和管理网络流量的形状 shapecfg命令 使用指南
【Shell 命令集合 网络通讯 】Linux 配置和管理网络流量的形状 shapecfg命令 使用指南
38 0
|
28天前
|
网络协议 Shell Linux
【Shell 命令集合 网络通讯 】Linux 设置和配置PPP pppsetup命令 使用教程
【Shell 命令集合 网络通讯 】Linux 设置和配置PPP pppsetup命令 使用教程
36 0
|
28天前
|
缓存 网络协议 Linux
【Shell 命令集合 网络通讯 】Linux 配置DNS dnsconf 命令 使用教程
【Shell 命令集合 网络通讯 】Linux 配置DNS dnsconf 命令 使用教程
38 0
|
30天前
|
网络协议 网络虚拟化 数据中心
华为配置VXLAN构建虚拟网络实现相同网段互通示例(静态方式)
配置VXLAN构建虚拟网络实现相同网段互通示例(静态方式
|
28天前
|
域名解析 网络协议 Linux
【Shell 命令集合 网络通讯 】Linux 设置和管理网络接口配置信息 netconfig命令 使用指南
【Shell 命令集合 网络通讯 】Linux 设置和管理网络接口配置信息 netconfig命令 使用指南
49 1
|
10天前
|
网络协议 Linux
在Linux中,管理和配置网络接口
在Linux中管理网络接口涉及多个命令,如`ifconfig`(在新版本中被`ip`取代)、`ip`(用于网络设备配置)、`nmcli`(NetworkManager的CLI工具)、`nmtui`(文本界面配置)、`route/ip route`(处理路由表)、`netstat/ss`(显示网络状态)和`hostnamectl/systemctl`(主机名和服务管理)。这些命令帮助用户启动接口、设置IP地址、查看连接和路由信息。不同发行版可能有差异,建议参考相应文档。
19 4
|
10天前
|
网络协议
centos8 网卡 Nmcli(是network的简写 Nmcli)配置网络
centos8 网卡 Nmcli(是network的简写 Nmcli)配置网络
11 0
|
28天前
|
存储 安全 网络安全
网络技术基础(20)——AAA原理与配置
【3月更文挑战第6天】华为设备的AAA框架实现网络安全管理,包括认证、授权、计费三要素,常使用RADIUS协议。用户、NAS(Network Access Server)和AAA服务器构成基本架构。认证方式有不认证、本地认证和远端认证,授权方式包括不授权、本地授权和远端授权,计费则为不计费和远端计费。RADIUS作为分布式协议,处理认证、计费和授权。常见应用场景如SSH登录,配置涉及创建认证方案、用户及服务类型。实验配置示例展示了SSH登录的AAA验证过程。
|
29天前
|
前端开发 应用服务中间件 nginx
nginx中配置不输入端口(指定地址)访问项目的方法
nginx中配置不输入端口(指定地址)访问项目的方法
23 0