适用于租户系统的 NAT
NAT 是一种修改或转换数据包标头中的网络地址信息的方法。可以转换数据包中的一个或两个源地址和目标地址。有关更多信息,请参阅以下主题:
了解租户系统的网络地址转换
从 Junos OS 18.3R1 版开始,租户系统支持网络地址转换,包括逻辑系统上支持的源 NAT、目标 NAT 和静态 NAT。
租户系统有一个管理员(租户管理员),他们可以为租户系统配置源 NAT、目标 NAT 和静态 NAT。租户管理员可以查看租户系统的源 NAT、目标 NAT 和静态 NAT 的详细信息。主管理员可以查看任何租户系统的源 NAT、目标 NAT 和静态 NAT 的统计信息或信息。
对于租户系统,主管理员可以为以下 NAT 资源配置最大和保留编号:
源 NAT 池和目标 NAT 池
源 NAT 池中的 IP 地址,带和不带端口地址转换
源、目标和静态 NAT 的规则
规则匹配的前缀列表
NAT 圆锥形绑定
支持端口过载的 IP 地址
分配的保留编号可确保指定资源量始终可供租户系统使用。租户系统的管理员可以将 show system security-profile
命令与 NAT 选项一起用于查看分配给租户系统的 NAT 资源。
另请参阅
示例:为租户系统配置网络地址转换
此示例说明如何为给定租户系统配置源 NAT、目标 NAT 和静态 NAT。
要求
此示例使用以下硬件和软件组件:
Junos OS 18.3R1 或更高版本的 SRX 系列防火墙。此配置示例针对 Junos OS 18.3R1 版进行了测试。
创建租户系统。请参阅: 示例:创建租户系统、租户系统管理员和互连 VPLS 交换机
配置网络接口。请参阅: 为租户系统配置路由实例。
概述
在此示例中,首先为专用地址空间配置信任安全区域,然后为公共地址空间配置不信任安全区域。
不可信区域中的设备访问信任区域的特定主机,其目标 IP 地址为 203.0.113.200/24。此示例配置表 1:租户系统 NAT 配置中描述的 NAT。
特征 |
名字 |
配置参数 |
---|---|---|
静态、源和目标 NAT 规则集 |
r1 |
|
源池 |
帕特 |
地址 192.0.2.1 至 192.0.2.24。 |
目标池 |
h1 |
地址 192.168.1.200。 |
代理 ARP |
Arp |
地址 192.0.2.1 至 192.0.2.24。 |
用于流量方向的 NAT 接口。 |
|
ge-0/0/0 和 ge-0/0/1。 |
配置
程序
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,将命令复制并粘贴到层级的 [edit]
CLI 中,然后从配置模式进入 commit
。
set tenants tn1 security nat source pool pat address 192.0.2.1 to 192.0.2.24 set tenants tn1 security nat source rule-set from_intf from interface ge-0/0/0.0 set tenants tn1 security nat source rule-set from_intf to interface ge-0/0/1.0 set tenants tn1 security nat source rule-set from_intf rule r1 match source-address 192.0.2.0/24 set tenants tn1 security nat source rule-set from_intf rule r1 match destination-address 203.0.113.200/24 set tenants tn1 security nat source rule-set from_intf rule r1 then source-nat pool pat set tenants tn1 security nat static rule-set from_zone from zone trust set tenants tn1 security nat static rule-set from_zone rule r1 match source-address 192.0.2.0/24 set tenants tn1 security nat static rule-set from_zone rule r1 match destination-address 203.0.113.203/24 set tenants tn1 security nat static rule-set from_zone rule r1 then static-nat prefix 192.168.1.203/24 set tenants tn1 security nat destination pool h1 address 192.168.1.200 set tenants tn1 security nat destination rule-set from_zone from zone trust set tenants tn1 security nat destination rule-set from_zone rule r1 match source-address 192.0.2.0/24 set tenants tn1 security nat destination rule-set from_zone rule r1 match destination-address 203.0.113.202/24 set tenants tn1 security nat destination rule-set from_zone rule r1 then destination-nat pool h1 set tenants tn1 security nat proxy-arp interface ge-0/0/1.0 address 192.0.2.1 to 192.0.2.24
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关如何操作的说明,请参阅 Junos OS CLI 用户指南 中的在配置模式下使用 CLI 编辑器 。
在租户系统中配置 NAT:
为租户系统创建安全 NAT 源池和规则集。
[edit tenant tn1 security nat source] user@host# set tenants tn1 security nat source pool pat address 192.0.2.1 to 192.0.2.24 user@host# set tenants tn1 security nat source rule-set from_intf from interface ge-0/0/0.0 user@host# set tenants tn1 security nat source rule-set from_intf to interface ge-0/0/1.0 user@host# set tenants tn1 security nat source rule-set from_intf rule r1 match source-address 192.0.2.0/24 user@host# set tenants tn1 security nat source rule-set from_intf rule r1 match destination-address 203.0.113.200/24 user@host# set tenants tn1 security nat source rule-set from_intf rule r1 then source-nat pool pat
为租户系统创建安全 NAT 静态规则集。
[edit tenants tn1 security nat static] user@host# set tenants tn1 security nat static rule-set from_zone from zone trust user@host# set tenants tn1 security nat static rule-set from_zone rule r1 match source-address 192.0.2.0/24 user@host# set tenants tn1 security nat static rule-set from_zone rule r1 match destination-address 203.0.113.203/24 user@host# set tenants tn1 security nat static rule-set from_zone rule r1 then static-nat prefix 192.168.1.203/24
为租户系统创建安全 NAT 目标池和规则集。
[edit tenants tn1 security nat destination] user@host# set tenants tn1 security nat destination pool h1 address 192.168.1.200 user@host# set tenants tn1 security nat destination rule-set from_zone from zone trust user@host# set tenants tn1 security nat destination rule-set from_zone rule r1 match source-address 192.0.2.0/24 user@host# set tenants tn1 security nat destination rule-set from_zone rule r1 match destination-address 203.0.113.202/24 user@host# set tenants tn1 security nat destination rule-set from_zone rule r1 then destination-nat pool h1
配置代理地址解析协议 (ARP)。
[edit tenant tn1 security nat] user@host# set tenants tn1 security nat proxy-arp interface ge-0/0/1.0 address 192.0.2.1 to 192.0.2.24
结果
在配置模式下,输入命令以确认 show tenants tn1 security nat
您的配置。如果输出未显示预期的配置,请重复此示例中的配置说明,以便进行更正。
source { pool pat { address { 192.0.2.1 to 192.0.2.24; } } rule-set from_intf { from interface ge-0/0/0.0; to interface ge-0/0/1.0; rule r1 { match { source-address 192.168.1.0/24; destination-address [203.0.113.200/24 ]; } then { source-nat { pool { pat; } } } } } } destination { pool h1 { address 192.168.1.200; } rule-set from_zone { from zone untrust; rule r1 { match { source-address 192.0.2.0/24; destination-address 203.0.113.202/24; } then { destination-nat { pool { h1; } } } } } } static { rule-set from_zone { from zone untrust; rule r1 { match { source-address 192.0.2.0/24; destination-address 203.0.113.203/24; } then { static-nat { prefix { 192.168.1.203/24; } } } } } } proxy-arp { interface ge-0/0/1.0 { address { 192.0.2.1 to 192.0.2.24; } } }
完成设备配置后,请从配置模式进入 commit
。
验证
要确认配置工作正常,请执行以下任务:
验证静态 NAT 配置
目的
要验证是否存在与静态 NAT 规则集匹配的流量。
行动
在操作模式下,输入 show security nat static rule all tenant tn1
命令。 Translation hits
查看字段,检查是否与规则匹配的流量。
user@host> show security nat static rule all tenant tn1
示例输出
命令名称
Total static-nat rules: 1 Total referenced IPv4/IPv6 ip-prefixes: 2/0 Static NAT rule: r1 Rule-set: from_zone Rule-Id : 1 Rule position : 1 From zone : untrust Source addresses : 192.0.2.0 - 192.0.2.255 Destination addresses : 203.0.113.203 Host addresses : 192.168.1.203 Netmask : 32 Host routing-instance : N/A Translation hits : 0 Successful sessions : 0 Failed sessions : 0 Number of sessions : 0
意义
命令输出显示静态 NAT 规则。 Translation hits
查看字段,检查是否与静态规则匹配的流量。
验证目标 NAT 配置
目的
要验证是否存在与目标 NAT 规则集匹配的流量。
行动
在操作模式下,输入 show security nat destination rule all tenant tn1
命令。 Translation hits
查看字段,检查是否与规则匹配的流量。
user@host> show security nat destination rule all tenant tn1
示例输出
命令名称
Total destination-nat rules: 1 Total referenced IPv4/IPv6 ip-prefixes: 2/0 Destination NAT rule: r1 Rule-set: from_zone Rule-Id : 1 Rule position : 1 From zone : untrust Match Source addresses : 192.0.2.0 - 192.0.2.255 Destination addresses : 203.0.113.202 - 203.0.113.202 Action : h1 Translation hits : 0 Successful sessions : 0 Failed sessions : 0 Number of sessions : 0
意义
命令输出显示目标 NAT 规则。 Translation hits
查看字段,检查是否与目标规则匹配的流量。
验证源 NAT 配置
目的
验证是否存在与源 NAT 规则集匹配的流量。
行动
在操作模式下,输入 show security nat source rule all tenant tn1
命令。 Translation hits
查看字段,检查是否与规则匹配的流量。
user@host> show security nat source rule all tenant tn1
示例输出
命令名称
Total rules: 1 Total referenced IPv4/IPv6 ip-prefixes: 2/0 source NAT rule: r1 Rule-set: from_intf Rule-Id : 1 Rule position : 1 From interface : ge-0/0/0.0 To interface : ge-0/0/1.0 Match Source addresses : 192.168.1.0 - 192.168.1.255 Destination addresses : 203.0.113.200 - 203.0.113.200 Action : pat Persistent NAT type : N/A Persistent NAT mapping type : address-port-mapping Inactivity timeout : 0 Max session number : 0 Translation hits : 0 Successful sessions : 0 Failed sessions : 0 Number of sessions : 0
意义
命令输出显示源 NAT 规则。 Translation hits
查看字段,检查是否与源规则匹配的流量。