内联 NAT
内联网络地址转换概述
内联 NAT 使用 MPC 线卡的功能,无需为 NAT 提供服务卡。因此,您可以实现线速、低延迟的地址转换(每个插槽高达 120 Gbps)。目前的实施方案提供:
-
1:1 静态地址映射。
-
双向映射 - 出站流量的源 NAT 和入站流量的目标 NAT。
-
对流量数量没有限制。
-
支持源、目标和两次 NAT,如 图 1 所示。内联 NAT 支持转换类型
basic-nat44。从 Junos OS 15.1R1 版开始,内联 NAT 还支持twice-basic-nat-44。 -
支持发夹。
要配置内联 NAT,请将服务接口定义为类型 si- (服务内联)接口。您还必须为内联接口预留足够的带宽。这样可以配置用于 NAT 的接口或下一跃点服务集。该 si- 接口用作“虚拟服务 PIC”。
-
仅支持静态 NAT。不支持端口转换、动态 NAT 和 ALG。因此,需要对 NAT 进行高级处理的 SIP 或 FTP 活动模式等应用程序无法运行。对于任何状态防火墙处理、ALG 支持和动态端口转换,仍然需要 MS-MPC、MS-MIC、MS-DPC 或 MS-PIC。
-
内联 NAT 不支持对数据包进行采样或记录。
内联 NAT 的优势
-
不再需要服务卡
-
支持比服务卡更多的 NAT 流
另见
示例:配置内联网络地址转换 - 基于接口的方法
此配置示例说明如何使用(服务内联)接口与接口样式服务集在 MX 系列设备 si- 上配置基于接口的内联网络地址转换 (NAT)。
本主题将介绍:
要求
此示例使用以下硬件和软件组件:
带有模块化端口集中器 (MPC) 线卡的 MX 系列路由器
Junos OS 11.4R1 或更高版本
概述和拓扑
从 Junos OS 11.4R1 版开始,MPC 线卡可以执行某些服务,而无需专用服务卡(如 MS-MPC)。内联服务通常比使用服务卡提供更好的性能,但其功能往往更基本。例如,内联 NAT 仅支持静态 NAT。
在此示例中,带有 MPC 线卡的 MX 系列设备为两个终端主机之间的流量提供内联源 NAT 服务。此方案的拓扑如图 2 所示
如图所示,主机 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 所示
内联网络地址转换配置
要使用接口样式服务集配置内联 NAT,请执行以下任务:
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到 [编辑] 层次结构级别的 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。
两次 NAT 配置
要使用接口样式服务集配置 Twice NAT,请执行以下任务:
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到 [编辑] 层次结构级别的 CLI 中。
## Configure a NAT rule and pool ## set services nat pool dst-pool-p1 address 100.1.1.2/32 set services nat pool dst-pool-p2 address 100.1.1.4/32 set services nat pool src-pool-p2 address 20.0.0.0/8 set services nat allow-overlapping-nat-pools set services nat rule TWICE_rule_1 match-direction output set services nat rule TWICE_rule_1 term TWICE_rule_1_term_1 from source-address 10.0.0.0/8 set services nat rule TWICE_rule_1 term TWICE_rule_1_term_1 from destination-address 120.1.1.2/32 set services nat rule TWICE_rule_1 term TWICE_rule_1_term_1 then translated source-pool src-pool-p1 set services nat rule TWICE_rule_1 term TWICE_rule_1_term_1 then translated destination-pool dst-pool-p1 set services nat rule TWICE_rule_1 term TWICE_rule_1_term_1 then translated translation-type twice-basic-nat-44 set services nat rule TWICE_rule_1 term TWICE_rule_1_term_2 from source-address 10.0.0.0/8 set services nat rule TWICE_rule_1 term TWICE_rule_1_term_2 from destination-address 120.1.1.4/32 set services nat rule TWICE_rule_1 term TWICE_rule_1_term_2 then translated source-pool src-pool-p2 set services nat rule TWICE_rule_1 term TWICE_rule_1_term_2 then translated destination-pool dst-pool-p2 set services nat rule TWICE_rule_1 term TWICE_rule_1_term_2 then translated translation-type twice-basic-nat-44 set services nat rule-set TWICE_NAT_RS1 rule TWICE_rule_1 set services service-set TWICE_SS_1 nat-rule-sets TWICE_NAT_RS1 set services service-set TWICE_SS_1 interface-service service-interface si-2/0/0 ## Configure interfaces ## set interfaces si-2/0/0 unit 0 family inet filter input log_filer set interfaces xe-2/0/0 unit 0 family inet address 10.1.1.251/16 set interfaces xe-2/0/1 unit 0 family inet service input service-set TWICE_SS_1 service-filter TWICE_SF_in set interfaces xe-2/0/1 unit 0 family inet service output service-set TWICE_SS_1 service-filter TWICE_SF_out set interfaces xe-2/0/1 unit 0 family inet address 100.1.1.251/16 ## Configure firewall filters ## set firewall family inet service-filter TWICE_SF_in term SF_R1_term_1 from source-address 100.1.1.2/32 set firewall family inet service-filter TWICE_SF_in term SF_R1_term_1 then service set firewall family inet service-filter TWICE_SF_in term SF_R1_term_2 from source-address 100.1.1.4/32 set firewall family inet service-filter TWICE_SF_in term SF_R1_term_2 then service set firewall family inet service-filter TWICE_SF_in term default then count non-matching-packets-in set firewall family inet service-filter TWICE_SF_out term SF_R1_out_term_1 from destination-address 120.1.1.2/32 set firewall family inet service-filter TWICE_SF_out term SF_R1_out_term_1 then service set firewall family inet service-filter TWICE_SF_out term SF_R1_out_term_2 from destination-address 120.1.1.4/32 set firewall family inet service-filter TWICE_SF_out term SF_R1_out_term_2 then service set firewall family inet service-filter TWICE_SF_out term default then count non-matching-packets-out set firewall family inet service-filter TWICE_SF_out term default then skip
配置(接口样式)服务集
配置使用两次 NAT 服务 (
nat-rules) 的服务集,a使用interface-service参数指定这是一个接口样式服务集。[edit services] user@MX# set service-set TWICE_SS_1 nat-rule-sets TWICE_NAT_RS1 user@MX# set service-set TWICE_SS_1 interface-service service-interface si-2/0/0
配置物理接口
分步过程
配置物理接口。
[edit interfaces] user@MX# set si-2/0/0 unit 0 family inet filter input log_filer user@MX# set xe-2/0/0 unit 0 family inet address 10.1.1.251/16 user@MX# set xe-2/0/1 unit 0 family inet service input service-set TWICE_SS_1 service-filter TWICE_SF_in user@MX# set xe-2/0/1 unit 0 family inet service output service-set TWICE_SS_1 service-filter TWICE_SF_out user@MX# set xe-2/0/1 unit 0 family inet address 100.1.1.251/16
在接口上,指定通过上述定义的服务集发送流量。
[edit interfaces] user@MX# set xe-2/0/1 unit 0 family inet service input service-set TWICE_SS_1 service-filter TWICE_SF_in user@MX# set xe-2/0/1 unit 0 family inet service output service-set TWICE_SS_1 service-filter TWICE_SF_out
配置防火墙过滤器选项以将流量定向到
si接口。[edit firewall] user@MX# set family inet service-filter TWICE_SF_in term SF_R1_term_1 from source-address 100.1.1.2/32 user@MX# set family inet service-filter TWICE_SF_in term SF_R1_term_1 then service user@MX# set family inet service-filter TWICE_SF_in term SF_R1_term_2 from source-address 100.1.1.4/32 user@MX# set family inet service-filter TWICE_SF_in term SF_R1_term_2 then service user@MX# set family inet service-filter TWICE_SF_in term default then count non-matching-packets-in user@MX# set family inet service-filter TWICE_SF_out term SF_R1_out_term_1 from destination-address 120.1.1.2/32 user@MX# set family inet service-filter TWICE_SF_out term SF_R1_out_term_1 then service user@MX# set family inet service-filter TWICE_SF_out term SF_R1_out_term_2 from destination-address 120.1.1.4/32 user@MX# set family inet service-filter TWICE_SF_out term SF_R1_out_term_2 then service user@MX# set family inet service-filter TWICE_SF_out term default then count non-matching-packets-out user@MX# set family inet service-filter TWICE_SF_out term default then skip
目标 NAT 配置
要使用接口样式服务集配置目标 NAT,请执行以下任务:
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到 [编辑] 层次结构级别的 CLI 中。
## Enable inline services, create an si- interface ## set chassis fpc 2 pic 0 inline-services set chassis fpc 2 pic 1 inline-services set services service-set DANT44_SS_1 nat-rule-sets DNAT44_RS_1 set services service-set DANT44_SS_1 interface-service service-interface si-2/0/0.0 ## Configure a NAT rule ## set services nat rule DNAT44_rule_1 match-direction output set services nat rule DNAT44_rule_1 term DNAT44_R1_term_1 from destination-address 21.1.1.2/32 set services nat rule DNAT44_rule_1 term DNAT44_R1_term_1 then translated destination-prefix 192.168.1.2/32 set services nat rule DNAT44_rule_1 term DNAT44_R1_term_1 then translated translation-type dnat-44 set services nat rule-set DNAT44_RS_1 rule DNAT44_rule_1 ## Configure interfaces (and the interface-style) and service filters ## set interfaces si-2/0/0 unit 0 family inet set interfaces xe-2/0/0 unit 0 family inet address 100.2.1.2/24 set interfaces xe-2/0/1 unit 0 family inet service input service-set DANT44_SS_1 service-filter SF_in set interfaces xe-2/0/1 unit 0 family inet service output service-set DANT44_SS_1 service-filter SF_out set interfaces xe-2/0/1 unit 0 family inet address 192.168.1.251/24 ## Configure the firewall filter options and static route options## set firewall family inet service-filter SF_in term SF_in_term1 from source-address 192.168.1.2/32 set firewall family inet service-filter SF_in term SF_in_term1 then service set firewall family inet service-filter SF_out term SF_out_term1 from destination-address 21.1.1.2/32 set firewall family inet service-filter SF_out term SF_out_term1 then service set routing-options static route 21.1.0.0/16 next-hop 100.2.1.2
启用内联服务
为相关 FPC 插槽和 PIC 插槽启用内联服务。
此处的 FPC 和 PIC 设置将创建并映射到一个
si-接口。[edit chassis fpc 2 pic 0] user@MX# set inline-services
[edit chassis fpc 2 pic 1] user@MX# set inline-services
配置(接口样式)服务集
配置使用目标 NAT 服务 (
nat-rules) 的服务集,a使用interface-service参数指定这是一个接口样式服务集。[edit services service-set] user@MX# set DANT44_SS_1 nat-rule-sets DNAT44_RS_1 user@MX# set DANT44_SS_1 DANT44_SS_1 interface-service service-interface si-2/0/0.0
配置物理接口
配置物理接口。
[edit interfaces] user@MX# set si-2/0/0 unit 0 family inet user@MX# set xe-2/0/0 unit 0 family inet address 100.2.1.2/24
在接口上,指定流量将通过之前定义的服务集发送。
[edit interfaces] user@MX# set xe-2/0/1 unit 0 family inet service input service-set DANT44_SS_1 service-filter SF_in user@MX# set xe-2/0/1 unit 0 family inet service output service-set DANT44_SS_1 service-filter SF_out user@MX# set interfaces xe-2/0/1 unit 0 family inet address 192.168.1.251/24
配置防火墙过滤器选项以将流量定向到
si接口。[edit firewall] user@MX# set firewall family inet service-filter SF_in term SF_in_term1 from source-address 192.168.1.2/32 user@MX# set firewall family inet service-filter SF_in term SF_in_term1 then service user@MX# set firewall family inet service-filter SF_out term SF_out_term1 from destination-address 21.1.1.2/32 user@MX# set firewall family inet service-filter SF_out term SF_out_term1 then service
配置静态路由选项。
[edit routing-optipons] user@MX# set static route 21.1.0.0/16 next-hop 100.2.1.2
示例:配置内联网络地址转换 - 基于路由的方法
此配置示例说明如何使用(服务内联)接口和下一跃点样式服务集在 MX 系列设备 si- 上配置基于路由的内联网络地址转换 (NAT)。
本主题将介绍:
要求
此示例使用以下硬件和软件组件:
带有模块化端口集中器 (MPC) 线卡的 MX 系列路由器
Junos OS 11.4R1 或更高版本
概述和拓扑
从 Junos OS 11.4R1 版开始,MPC 线卡可以执行某些服务,而无需专用服务卡(如 MS-MPC)。内联服务通常比使用服务卡提供更好的性能,但其功能往往更基本。例如,内联 NAT 仅支持静态 NAT。
在此示例中,带有 MPC 线卡的 MX 系列设备为两个终端主机之间的流量提供内联源 NAT 服务。此方案的拓扑如图 6 所示
如图所示,主机 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 通常用于涉及路由实例的场景。
这些元素组合在一起,如 图 7 所示。
配置
要使用下一跃点样式的服务集配置内联 NAT,请执行以下任务:
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到 [编辑] 层次结构级别的 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 服务发送的流量
分步过程
配置一个路由实例,其中包含“innside”物理接口和
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-接口分配为 'inside' 和 'outside'。流量将流入和流出
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