动态仅地址源转换
在 IPv4 网络中配置动态仅地址源转换
在 IPv4 网络中,动态地址转换(动态 NAT)是一种无需端口映射即可动态转换目标流量的机制。要使用动态 NAT,您必须指定源池名称,其中包括地址配置。
要在 IPv4 网络中配置动态 NAT,请执行以下作:
以下示例将转换类型配置为 dynamic-nat44。
[edit services]
user@host# show
service-set s1 {
nat-rules rule-dynamic-nat44;
interface-service {
service-interface ms-0/1/0;
}
}
nat {
pool source-dynamic-pool {
address 10.1.1.0/24;
}
rule rule-dynamic-nat44 {
match-direction input;
term t1 {
from {
source-address {
3.1.1.0/24;
}
}
then {
translated {
destination-pool source-dynamic-pool;
translation-type {
dynamic-nat44;
}
}
}
}
}
}
adaptive-services-pics {
traceoptions {
flag all;
}
}
以下配置通过提供配置 NAT 规则术语,指定不对源地址 192.168.20.24/32 的传入流量执行 NAT作。no-translationt0按照 NAT 规则条款t1的规定,对所有其他传入流量执行动态 NAT。带有 MS-DPC 的 MX 系列 路由器以及带有 MS-100、MS-400 和 MS-500 多服务 PIC 的 M Series 路由器支持该no-translation选项。从 Junos OS 15.1R1 版开始,配备 MS-MPC 和 MS-MIC 的 MX 系列路由器支持该no-translation选项。
[edit services nat]
pool my-pool {
address-range low 10.10.10.1 high 10.10.10.16;
port automatic;
}
rule src-nat {
match-direction input;
term t0 {
from {
source-address 192.168.20.24/32;
}
then {
no-translation;
}
}
term t1 {
then {
translated {
translation-type dynamic-nat44;
source-pool my-pool;
}
}
}
}
以下配置使用源前缀 20.20.10.0/24 执行 NAT,而不定义池。
[edit services nat]
rule src-nat {
match-direction input;
term t1 {
then {
translation-type dynamic-nat44;
source-prefix 20.20.10.0/24;
}
}
}
以下配置使用目标前缀 20.20.10.0/32 执行 NAT,而不定义池。
[edit services nat]
rule src-nat {
match-direction input;
term t1 {
from {
destination-address 10.10.10.10/32;
then {
translation-type dnat44;
destination-prefix 20.20.10.0/24;
}
}
}
}
示例:动态源 NAT 作为下一跳点服务
以下示例显示了作为下一跃点服务应用的动态源 NAT:
[edit interfaces]
ge-0/2/0 {
unit 0 {
family mpls;
}
}
sp-1/3/0 {
unit 0 {
family inet;
}
unit 20 {
family inet;
}
unit 32 {
family inet;
}
}
[edit routing-instances]
protected-domain {
interface ge-0/2/0.0;
interface sp-1/3/0.20;
instance-type vrf;
route-distinguisher 10.58.255.17:37;
vrf-import protected-domain-policy;
vrf-export protected-domain-policy;
routing-options {
static {
route 0.0.0.0/0 next-hop sp-1/3/0.20;
}
}
}
[edit policy-options]
policy-statement protected-domain-policy {
term t1 {
then reject;
}
}
[edit services]
stateful-firewall {
rule allow-all {
match-direction input;
term t1 {
then {
accept;
}
}
}
}
nat {
pool my-pool {
address 10.58.16.100;
port automatic;
}
rule hide-all {
match-direction input;
term t1 {
then {
translated {
source-pool my-pool;
translation-type napt-44;
}
}
}
}
}
service-set null-sfw-with-nat {
stateful-firewall-rules allow-all;
nat-rules hide-all;
next-hop-service {
inside-service-interface sp-1/3/0.20;
outside-service-interface sp-1/3/0.32;
}
}
示例:从动态池分配地址以供静态使用
以下配置将配置为动态池 (dynamic-pool) 一部分的地址子集静态分配给两个单独的静态池(static-pool 和 static-pool2)。
[edit services nat]
pool dynamic-pool {
address 20.20.10.0/24;
}
pool static-pool {
address-range low 20.20.10.10 high 10.20.10.12;
}
pool static-pool2 {
address 20.20.10.15/32;
}
rule src-nat {
match-direction input;
term t1 {
from {
source-address 30.30.30.0/24;
}
then {
translation-type dynamic-nat44;
source-pool dynamic-pool;
}
}
term t2 {
from {
source-address 10.10.10.2;
}
then {
translation-type basic-nat44;
source-pool static-pool;
}
}
term t3 {
from {
source-address 10.10.10.10;
}
then {
translation-type basic-nat44;
source-pool static-pool2;
}
}
}