租户系统的 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 交换机。
配置网络接口。请参阅: 为租户系统配置路由实例。
概述
在此示例中,首先为专用地址空间配置信任安全区域,然后为公共地址空间配置不信任安全区域。
untrust 区域中的设备可以访问目标 IP 地址为 203.0.113.200/24 的信任区域中的特定主机。此示例配置 表 1 中所述的 NAT:租户系统 NAT 配置。
功能 |
姓名 |
配置参数 |
|---|---|---|
静态、源和目标 NAT 规则集 |
R1 |
|
源池 |
PAT |
地址 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 字段以检查是否与源规则匹配的流量。