内联 NAT
内联网络地址转换概述
内联 NAT 使用 MPC 线卡的功能,无需为 NAT 提供服务卡。因此,您可以实现线速、低延迟的地址转换(每个插槽高达 120 Gbps)。当前的实现提供:
1:1 静态地址映射。
双向映射 - 出站流量的源 NAT 和入站流量的目标 NAT。
对流的数量没有限制。
支持源、目标和两次 NAT,如图 1 所示。内联 NAT 支持转换类型
basic-nat44
。从 Junos OS 15.1R1 版开始,内联 NAT 还支持twice-basic-nat-44
.支持发夹。
![Supported Inline NAT Types](/documentation/us/en/software/junos/interfaces-adaptive-services/images/g041381.png)
要配置内联 NAT,请将服务接口定义为类型 si-
(服务内联)接口。您还必须为内联接口保留足够的带宽。这使您能够配置用于 NAT 的接口或下一跃点服务集。该 si-
接口用作“虚拟服务 PIC”。
仅支持静态 NAT。不支持端口转换、动态 NAT 和 ALG。因此,需要对 NAT 进行高级处理的 SIP 或 FTP 活动模式等应用程序无法运行。任何状态防火墙处理、ALG 支持和动态端口转换仍然需要 MS-MPC、MS-MIC、MS-DPC 或 MS-PIC。
内联 NAT 不支持数据包采样或日志记录。
内联 NAT 的优势
无需服务卡
支持比服务卡更多的 NAT 流量
参见
示例:配置内联网络地址转换 - 基于接口的方法
此配置示例说明了如何使用具有接口样式服务集的(服务内联)接口在 si-
MX 系列设备上配置基于接口的内联网络地址转换 (NAT)。
本主题涵盖:
要求
此示例使用以下硬件和软件组件:
带有模块化端口集中器 (MPC) 线卡的 MX 系列路由器
Junos OS 11.4R1 或更高版本
概述和拓扑
从 Junos OS 11.4R1 版开始,MPC 线卡无需专用服务卡(如 MS-MPC)即可执行某些服务。内联服务通常比使用服务卡提供更好的性能,但它们的功能往往更基本。例如,内联 NAT 仅支持静态 NAT。
在此示例中,具有 MPC 线卡的 MX 系列设备为在两个终端主机之间流动的流量提供内联源 NAT 服务。此方案的拓扑如图 2 所示
![Inline Source NAT Using an MX Series Device with an MPC](/documentation/us/en/software/junos/interfaces-adaptive-services/images/g200025.png)
如图所示,主机 H1 将流量发送到服务器 S1。MX 系列设备执行源 NAT 以将 H1 的源 IP 地址从 10.1.1.2 转换为 192.0.2.2。然后,服务器 S1 使用目标 IP 地址 192.0.2.2 向主机 H1 发送返回流量,MX 系列设备将 H1 的 IP 地址恢复为 10.1.1.2。
此方案中使用以下配置元素:
内联服务接口 — 驻留在 MPC 的数据包转发引擎上的虚拟接口。要访问服务,流量流入和流出这些
si-
(内联服务)接口。服务集 — 定义要执行的服务,并确定哪些内联接口将流量馈入和送出服务集。有两种方法可以实现服务集:
接口样式 — 一种基于接口的方法,到达接口的数据包通过内联服务转发。
下一跃点样式 — 一种基于路由的方法,其中静态路由用于通过内联服务转发发往特定目标的数据包。
此示例使用接口样式的服务集。
NAT 规则 — 使用 if-then 结构(类似于防火墙过滤器)定义匹配条件,然后将地址转换应用于匹配流量。
NAT 池 — NAT 规则用于转换的用户定义的一组 IP 地址。
这些元素组合在一起,如图 3 所示
![Interface-Based Inline Source NAT](/documentation/us/en/software/junos/interfaces-adaptive-services/images/g200030.png)
配置
要使用接口样式服务集配置内联 NAT,请执行以下操作:
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改任何必要的详细信息以匹配您的网络配置,然后将命令复制并粘贴到 [edit] 层次结构级别的 CLI 中。
## Enable inline services, create an si- interface, reserve bandwidth ## set chassis fpc 0 pic 0 inline-services bandwidth 1g set interfaces si-0/0/0 unit 0 family inet ## Configure a NAT rule and pool ## set services nat rule SRC-NAT1 match-direction input set services nat rule SRC-NAT1 term r1 from source-address 10.1.1.0/24 set services nat rule SRC-NAT1 term r1 then translated translation-type basic-nat44 set services nat rule SRC-NAT1 term r1 then translated source-pool p1 set services nat pool p1 address 192.0.2.0/24 ## Configure the (interface-style) service set ## set services service-set INT-STYLE-SS-NAT1 nat-rules SRC-NAT1 set services service-set INT-STYLE-SS-NAT1 interface-service service-interface si-0/0/0.0 ## Configure interfaces ## set interfaces xe-0/0/0 unit 0 family inet address 10.1.1.1/24 set interfaces xe-0/0/0 description INSIDE set interfaces xe-1/0/0 unit 0 family inet address 192.168.1.1/24 set interfaces xe-1/0/0 description OUTSIDE set interfaces xe-0/0/0 unit 0 family inet service input service-set INT-STYLE-SS-NAT1 set interfaces xe-0/0/0 unit 0 family inet service output service-set INT-STYLE-SS-NAT1
启用内联服务并创建内联接口
分步过程
为相关的 FPC 插槽和 PIC 插槽启用内联服务,并定义专用于内联服务的带宽量。
此处的 FPC 和 PIC 设置将创建并映射到
si-
接口。[edit chassis fpc 0 pic 0] user@MX# set inline-services bandwidth 1g
在接口上
si-
,指定需要 NAT 服务的一个或多个协议家族。注意:此处的 FPC 和 PIC 设置必须与上面定义的设置匹配。
[edit interfaces si-0/0/0] user@MX# set unit 0 family inet
配置 NAT 规则和池
分步过程
配置一个 NAT 规则,该规则匹配从 H1 的子网 (10.1.1.0/24) 到达 MX 设备的流量,使用基本 IPv4 NAT 进行转换,并使用池
p1
中的 IP 地址。[edit services nat] user@MX# set rule SRC-NAT1 match-direction input user@MX# set rule SRC-NAT1 term r1 from source-address 10.1.1.0/24 user@MX# set rule SRC-NAT1 term r1 then translated translation-type basic-nat44 user@MX# set rule SRC-NAT1 term r1 then translated source-pool p1
配置 NAT 池。
[edit services nat] user@MX# set pool p1 address 192.0.2.0/24
配置(接口样式)服务集
分步过程
配置使用内联 NAT 服务 (
nat-rules
) 和上面定义的内联接口的服务集。使用该interface-service
参数指定这是一个接口样式的服务集。流量将流入和流出
si-
接口以访问内联 NAT 服务。[edit services] user@MX# set service-set INT-STYLE-SS-NAT1 nat-rules SRC-NAT1 user@MX# set service-set INT-STYLE-SS-NAT1 interface-service service-interface si-0/0/0.0
配置物理接口
分步过程
配置物理接口。
[edit interfaces] user@MX# set xe-0/0/0 unit 0 family inet address 10.1.1.1/24 user@MX# set xe-0/0/0 description INSIDE user@MX# set xe-1/0/0 unit 0 family inet address 192.168.1.1/24 user@MX# set xe-1/0/0 description OUTSIDE
在“内部”接口上,指定流量将通过上面定义的服务集发送。
[edit interfaces xe-0/0/0 unit 0] user@MX# set family inet service input service-set INT-STYLE-SS-NAT1 user@MX# set family inet service output service-set INT-STYLE-SS-NAT1
结果
chassis { fpc 0 { pic 0 { inline-services { bandwidth 1g; } } } } services { service-set INT-STYLE-SS-NAT1 { nat-rules SRC-NAT1; interface-service { service-interface si-0/0/0.0; } } nat { pool p1 { address 192.0.2.0/24; } rule SRC-NAT1 { match-direction input; term r1 { from { source-address { 10.1.1.0/24; } } then { translated { source-pool p1; translation-type { basic-nat44; } } } } } } } interfaces { si-0/0/0 { unit 0 { family inet; } } xe-0/0/0 { description INSIDE; unit 0 { family inet { service { input { service-set INT-STYLE-SS-NAT1; } output { service-set INT-STYLE-SS-NAT1; } } address 10.1.1.1/24; } } } xe-1/0/0 { description OUTSIDE; unit 0 { family inet { address 192.168.1.1/24; } } } }
验证
确认配置工作正常。
验证从主机 H1 到服务器 S1 的可访问性
目的
验证 H1 和 S1 之间的可访问性。
行动
在主机 H1 上,验证主机是否可以 ping 服务器 S1。
user@H1> ping 192.168.1.2 count 5 PING 192.168.1.2 (192.168.1.2): 56 data bytes 64 bytes from 192.168.1.2: icmp_seq=0 ttl=63 time=0.991 ms 64 bytes from 192.168.1.2: icmp_seq=1 ttl=63 time=14.186 ms 64 bytes from 192.168.1.2: icmp_seq=2 ttl=63 time=3.016 ms 64 bytes from 192.168.1.2: icmp_seq=3 ttl=63 time=3.742 ms 64 bytes from 192.168.1.2: icmp_seq=4 ttl=63 time=4.748 ms --- 192.168.1.2 ping statistics --- 5 packets transmitted, 5 packets received, 0% packet loss round-trip min/avg/max/stddev = 0.991/5.337/14.186/4.593 ms
意义
H1 可以成功到达 S1。
验证地址转换
目的
验证地址转换是否正常工作。
行动
在 MX 设备上,验证是否已正确应用内联 NAT 配置详细信息。
user@MX> show services inline nat pool Interface: si-0/0/0, Service set: INT-STYLE-SS-NAT1 NAT pool: p1, Translation type: BASIC NAT44 Address range: 192.0.2.0-192.0.2.255 NATed packets: 5, deNATed packets: 5, Errors: 0
在服务器 S1 上,验证服务器是否正在从 H1 的 NAT 转换源 IP 地址 (192.0.2.2) 接收 ping。
发出以下命令,并从 H1 再次发送 ping。
注意:对于此设置,另一个 MX 设备用于表示服务器 S1,以启用入站流量监控。
user@S1> monitor traffic interface xe-1/1/1 no-resolve verbose output suppressed, use <detail> or <extensive> for full protocol decode Address resolution is OFF. Listening on xe-1/1/1, capture size 96 bytes 23:28:28.577377 In IP 192.0.2.2 > 192.168.1.2: ICMP echo request, id 3293, seq 0, length 64 23:28:28.577405 Out IP 192.168.1.2 > 192.0.2.2: ICMP echo reply, id 3293, seq 0, length 64 23:28:29.579253 In IP 192.0.2.2 > 192.168.1.2: ICMP echo request, id 3293, seq 1, length 64 23:28:29.579278 Out IP 192.168.1.2 > 192.0.2.2: ICMP echo reply, id 3293, seq 1, length 64 23:28:30.579275 In IP 192.0.2.2 > 192.168.1.2: ICMP echo request, id 3293, seq 2, length 64 23:28:30.579302 Out IP 192.168.1.2 > 192.0.2.2: ICMP echo reply, id 3293, seq 2, length 64 23:28:31.580279 In IP 192.0.2.2 > 192.168.1.2: ICMP echo request, id 3293, seq 3, length 64 23:28:31.580305 Out IP 192.168.1.2 > 192.0.2.2: ICMP echo reply, id 3293, seq 3, length 64 23:28:32.581266 In IP 192.0.2.2 > 192.168.1.2: ICMP echo request, id 3293, seq 4, length 64 23:28:32.581293 Out IP 192.168.1.2 > 192.0.2.2: ICMP echo reply, id 3293, seq 4, length 64 ^C 10 packets received by filter 0 packets dropped by kernel
意义
上述步骤 1 确认内联 NAT 服务参数和接口样式服务集已正确实现。上述步骤 2 确认服务器 S1 从其 NAT 转换的源 IP 地址正确接收 H1 的 ping。
示例:配置内联网络地址转换 - 基于路由的方法
此配置示例说明如何使用具有下一跃点样式服务集的(服务内联)接口在 si-
MX 系列设备上配置基于路由的内联网络地址转换 (NAT)。
本主题涵盖:
要求
此示例使用以下硬件和软件组件:
带有模块化端口集中器 (MPC) 线卡的 MX 系列路由器
Junos OS 11.4R1 或更高版本
概述和拓扑
从 Junos OS 11.4R1 版开始,MPC 线卡无需专用服务卡(如 MS-MPC)即可执行某些服务。内联服务通常比使用服务卡提供更好的性能,但它们的功能往往更基本。例如,内联 NAT 仅支持静态 NAT。
在此示例中,具有 MPC 线卡的 MX 系列设备为在两个终端主机之间流动的流量提供内联源 NAT 服务。此方案的拓扑如图 4 所示
![Inline Source NAT Using an MX Series Device with an MPC](/documentation/us/en/software/junos/interfaces-adaptive-services/images/g200025.png)
如图所示,主机 H1 将流量发送到服务器 S1。MX 系列设备执行源 NAT 以将 H1 的源 IP 地址从 10.1.1.2 转换为 192.0.2.2。然后,服务器 S1 使用目标 IP 地址 192.0.2.2 向主机 H1 发送返回流量,MX 系列设备将 H1 的 IP 地址恢复为 10.1.1.2。
此方案中使用以下配置元素:
内联服务接口 — 驻留在 MPC 的数据包转发引擎上的虚拟接口。要访问服务,流量流入和流出这些
si-
(内联服务)接口。服务集 — 定义要执行的服务,并确定哪些内联接口将流量馈入和送出服务集。有两种方法可以实现服务集:
接口样式 — 一种基于接口的方法,到达接口的数据包通过内联服务转发。
下一跃点样式 — 一种基于路由的方法,其中静态路由用于通过内联服务转发发往特定目标的数据包。
此示例使用下一跃点样式的服务集。
NAT 规则 — 使用 if-then 结构(类似于防火墙过滤器)定义匹配条件,然后将地址转换应用于匹配流量。
NAT 池 — NAT 规则用于转换的用户定义的一组 IP 地址。
路由实例 — 独立于主(默认)路由实例运行的路由表、接口和路由协议参数的集合。
基于路由的内联 NAT 通常用于涉及路由实例的方案。
这些元素组合在一起,如图 5 所示。
![Route-Based Inline Source NAT](/documentation/us/en/software/junos/interfaces-adaptive-services/images/g200032.png)
配置
要使用下一跃点样式服务集配置内联 NAT,请执行以下操作:
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改任何必要的详细信息以匹配您的网络配置,然后将命令复制并粘贴到 [edit] 层次结构级别的 CLI 中。
## Configure interfaces ## set interfaces xe-0/0/0 unit 0 family inet address 10.1.1.1/24 set interfaces xe-0/0/0 description INSIDE set interfaces xe-1/0/0 unit 0 family inet address 192.168.1.1/24 set interfaces xe-1/0/0 description OUTSIDE ## Enable inline services, create an si- interface, reserve bandwidth ## set chassis fpc 0 pic 0 inline-services bandwidth 1g set interfaces si-0/0/0 unit 1 family inet set interfaces si-0/0/0 unit 1 service-domain inside set interfaces si-0/0/0 unit 2 family inet set interfaces si-0/0/0 unit 2 service-domain outside ## Configure routing instance, feed traffic into the inline NAT service ## set routing-instances RI-A instance-type virtual-router set routing-instances RI-A interface xe-0/0/0.0 set routing-instances RI-A interface si-0/0/0.1 set routing-instances RI-A routing-options static route 192.168.1.2/32 next-hop si-0/0/0.1 ## Configure a NAT rule and pool ## set services nat rule SRC-NAT1 match-direction input set services nat rule SRC-NAT1 term r1 from source-address 10.1.1.0/24 set services nat rule SRC-NAT1 term r1 then translated translation-type basic-nat44 set services nat rule SRC-NAT1 term r1 then translated source-pool p1 set services nat pool p1 address 192.0.2.0/24 ## Configure the (next-hop-style) service set ## set services service-set NH-STYLE-SS-NAT1 nat-rules SRC-NAT1 set services service-set NH-STYLE-SS-NAT1 next-hop-service inside-service-interface si-0/0/0.1 set services service-set NH-STYLE-SS-NAT1 next-hop-service outside-service-interface si-0/0/0.2
配置物理接口
分步过程
配置物理接口。
[edit interfaces] user@MX# set xe-0/0/0 unit 0 family inet address 10.1.1.1/24 user@MX# set xe-0/0/0 description INSIDE user@MX# set xe-1/0/0 unit 0 family inet address 192.168.1.1/24 user@MX# set xe-1/0/0 description OUTSIDE
启用内联服务并创建内联接口
分步过程
为相关的 FPC 插槽和 PIC 插槽启用内联服务,并定义专用于内联服务的带宽量。
此处的 FPC 和 PIC 设置将创建并映射到
si-
接口。[edit chassis fpc 0 pic 0] user@MX# set inline-services bandwidth 1g
在接口上
si-
,创建两个逻辑单元。对于每个单元,指定需要 NAT 服务的一个或多个协议家族,以及服务域的“内部”或“外部”接口。注意:此处的 FPC 和 PIC 设置必须与上面定义的设置匹配。
[edit interfaces si-0/0/0] user@MX# set unit 1 family inet user@MX# set unit 1 service-domain inside user@MX# set unit 2 family inet user@MX# set unit 2 service-domain outside
配置路由实例并确定要通过内联 NAT 服务发送的流量
分步过程
配置包含“ínside”物理和
si-
接口的路由实例,以及标识要通过接口转发si-
到内联 NAT 服务的流量的静态路由。为简单起见,此处使用的静态路由仅标识服务器 S1。
[edit routing-instances] user@MX# set RI-A instance-type virtual-router user@MX# set RI-A interface xe-0/0/0.0 user@MX# set RI-A interface si-0/0/0.1 user@MX# set RI-A routing-options static route 192.168.1.2/32 next-hop si-0/0/0.1
配置 NAT 规则和池
分步过程
配置一个 NAT 规则,该规则匹配从 H1 的子网 (10.1.1.0/24) 到达 MX 设备的流量,使用基本 IPv4 NAT 进行转换,并使用池
p1
中的 IP 地址。[edit services nat] user@MX# set rule SRC-NAT1 match-direction input user@MX# set rule SRC-NAT1 term r1 from source-address 10.1.1.0/24 user@MX# set rule SRC-NAT1 term r1 then translated translation-type basic-nat44 user@MX# set rule SRC-NAT1 term r1 then translated source-pool p1
配置 NAT 池。
[edit services nat] user@MX# set pool p1 address 192.0.2.0/24
配置(下一跃点样式)服务集
分步过程
配置使用内联 NAT 服务 (
nat-rules
) 和上面定义的内联接口的服务集。使用该next-hop-service
参数指定这是下一跃点样式的服务集,并根据接口的上述设置将接口分配si-
为“内部”和“外部”。流量将流入和流出
si-
接口以访问内联 NAT 服务。[edit services] user@MX# set service-set NH-STYLE-SS-NAT1 nat-rules SRC-NAT1 user@MX# set service-set NH-STYLE-SS-NAT1 next-hop-service inside-service-interface si-0/0/0.1 user@MX# set service-set NH-STYLE-SS-NAT1 next-hop-service outside-service-interface si-0/0/0.2
结果
chassis { fpc 0 { pic 0 { inline-services { bandwidth 1g; } } } } services { service-set NH-STYLE-SS-NAT1 { nat-rules SRC-NAT1; next-hop-service { inside-service-interface si-0/0/0.1; outside-service-interface si-0/0/0.2; } } nat { pool p1 { address 192.0.2.0/24; } rule SRC-NAT1 { match-direction input; term r1 { from { source-address { 10.1.1.0/24; } } then { translated { source-pool p1; translation-type { basic-nat44; } } } } } } } interfaces { si-0/0/0 { unit 1 { family inet; service-domain inside; } unit 2 { family inet; service-domain outside; } } xe-0/0/0 { description INSIDE; unit 0 { family inet { address 10.1.1.1/24; } } } xe-1/0/0 { description OUTSIDE; unit 0 { family inet { address 192.168.1.1/24; } } } } routing-instances { RI-A { instance-type virtual-router; interface xe-0/0/0.0; interface si-0/0/0.1; routing-options { static { route 192.168.1.2/32 next-hop si-0/0/0.1; } } } }
验证
确认配置工作正常。
验证从主机 H1 到服务器 S1 的可访问性
目的
验证 H1 和 S1 之间的可访问性。
行动
在主机 H1 上,验证主机是否可以 ping 服务器 S1。
user@H1> ping 192.168.1.2 count 5 PING 192.168.1.2 (192.168.1.2): 56 data bytes 64 bytes from 192.168.1.2: icmp_seq=0 ttl=63 time=0.926 ms 64 bytes from 192.168.1.2: icmp_seq=1 ttl=63 time=0.859 ms 64 bytes from 192.168.1.2: icmp_seq=2 ttl=63 time=0.853 ms 64 bytes from 192.168.1.2: icmp_seq=3 ttl=63 time=0.825 ms 64 bytes from 192.168.1.2: icmp_seq=4 ttl=63 time=0.930 ms --- 192.168.1.2 ping statistics --- 5 packets transmitted, 5 packets received, 0% packet loss round-trip min/avg/max/stddev = 0.825/0.879/0.930/0.042 ms
意义
H1 可以成功到达 S1。
验证地址转换
目的
验证地址转换是否正常工作。
行动
在 MX 设备上,验证是否已正确应用内联 NAT 配置详细信息。
user@MX> show services inline nat pool Interface: si-0/0/0, Service set: NH-STYLE-SS-NAT1 NAT pool: p1, Translation type: BASIC NAT44 Address range: 192.0.2.0-192.0.2.255 NATed packets: 5, deNATed packets: 5, Errors: 0, Skipped packets: 0
在服务器 S1 上,验证服务器是否正在从 H1 的 NAT 转换源 IP 地址 (192.0.2.2) 接收 ping。
发出以下命令,并从 H1 再次发送 ping。
注意:对于此设置,另一个 MX 设备用于表示服务器 S1,以启用入站流量监控。
user@S1> monitor traffic interface xe-1/1/1 no-resolve verbose output suppressed, use <detail> or <extensive> for full protocol decode Address resolution is OFF. Listening on xe-1/1/1, capture size 96 bytes 20:19:36.182690 In IP 192.0.2.2 > 192.168.1.2: ICMP echo request, id 4436, seq 0, length 64 20:19:36.182719 Out IP 192.168.1.2 > 192.0.2.2: ICMP echo reply, id 4436, seq 0, length 64 20:19:37.182918 In IP 192.0.2.2 > 192.168.1.2: ICMP echo request, id 4436, seq 1, length 64 20:19:37.182945 Out IP 192.168.1.2 > 192.0.2.2: ICMP echo reply, id 4436, seq 1, length 64 20:19:38.183914 In IP 192.0.2.2 > 192.168.1.2: ICMP echo request, id 4436, seq 2, length 64 20:19:38.183940 Out IP 192.168.1.2 > 192.0.2.2: ICMP echo reply, id 4436, seq 2, length 64 20:19:39.184872 In IP 192.0.2.2 > 192.168.1.2: ICMP echo request, id 4436, seq 3, length 64 20:19:39.184896 Out IP 192.168.1.2 > 192.0.2.2: ICMP echo reply, id 4436, seq 3, length 64 20:19:40.185882 In IP 192.0.2.2 > 192.168.1.2: ICMP echo request, id 4436, seq 4, length 64 20:19:40.185907 Out IP 192.168.1.2 > 192.0.2.2: ICMP echo reply, id 4436, seq 4, length 64 ^C 10 packets received by filter 0 packets dropped by kernel
意义
上述步骤 1 确认内联 NAT 服务参数和下一跃点样式服务集已正确实现。上述步骤 2 确认服务器 S1 从其 NAT 转换的源 IP 地址正确接收 H1 的 ping。
更改历史记录表
功能支持由您使用的平台和版本决定。使用功能资源管理器确定您的平台是否支持某个 功能 。
twice-basic-nat-44