Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

header-navigation
keyboard_arrow_up
close
keyboard_arrow_left
list Table of Contents
file_download PDF
{ "lLangCode": "en", "lName": "English", "lCountryCode": "us", "transcode": "en_US" }
English
keyboard_arrow_right

Dynamic Address-Only Source Translation

date_range 13-Jan-21

Configuring Dynamic Address-Only Source Translation in IPv4 Networks

In IPv4 networks, dynamic address translation (dynamic NAT) is a mechanism to dynamically translate the destination traffic without port mapping. To use dynamic NAT, you must specify a source pool name, which includes an address configuration.

To configure dynamic NAT in IPv4 networks:

  1. In configuration mode, go to the [edit services] hierarchy level.
    content_copy zoom_out_map
    [edit]
    user@host# edit services
    
  2. Configure the service set and NAT rule.
    content_copy zoom_out_map
    [edit services]
    user@host# set service-set service-set-name nat-rules rule-name
    

    In the following example, the name of the service set is s1, and the name of the NAT rule is rule-dynamic-nat44.

    content_copy zoom_out_map
    [edit services]
    user@host# set service-set s1 nat-rules rule-dynamic-nat44
    
  3. Go to the [interface-service] hierarchy level for the service set.
    content_copy zoom_out_map
    [edit services]
    user@host# edit service-set s1 interface-service
    
  4. Configure the service interface. 
    content_copy zoom_out_map
     [edit services service-set s1 interface-service]
    user@host# set service-interface service-interface-name
    

    In the following example, the name of the service interface is ms-0/1/0.

    Note:

    If the service interface is not present in the router, or the specified interface is not functional, the following command can result in an error.

    content_copy zoom_out_map
     [edit services service-set s1 interface-service]
    user@host# set service-interface ms-0/1/0
    
  5. Go to the [edit services nat] hierarchy level. Issue the following command from the top of the services hierarchy, or use the top keyword.
    content_copy zoom_out_map
     [edit services service-set s1 interface-service]
    user@host# top editservices nat
    
  6. Configure the NAT pool with an address.
    content_copy zoom_out_map
    [edit services nat]
    user@host# set pool pool-name address address
    

    In the following example, the name of the pool is source-dynamic-pool, and the address is 10.10.10.0.

    content_copy zoom_out_map
    [edit services nat]
    user@host# set pool source-dynamic-pool address 10.10.10.0
    
  7. Configure the rule, match direction, term, and source address. 
    content_copy zoom_out_map
    [edit services nat]
    user@host# set rule rule-name match-direction match-direction term term-name from source-address address
    

    In the following example, the name of the rule is rule-dynamic-nat44, the match direction is input, the name of the term is t1, and the source address is 3.1.1.0.

    content_copy zoom_out_map
    [edit services nat]
    user@host# set rule rule-dynamic-nat44 match-direction  input term t1 from source-address  3.1.1.0
    
  8. Go to the [edit rule rule-dynamic-nat-44 term t1] hierarchy level.
    content_copy zoom_out_map
    [edit services nat]
    user@host# edit rule rule-dynamic-nat44 term t1
    
  9. Configure the source pool and the translation type.
    content_copy zoom_out_map
    [edit services nat rule rule-dynamic-nat44 term t1]
    user@host# set then translated source-pool src-pool-name translation-type translation-type
    

    In the following example, the name of the source pool is source-dynamic-pool and the translation type is dynamic-nat44.

    content_copy zoom_out_map
    [edit services nat rule rule-dynamic-nat44 term t1]
    user@host# set then translated source-pool  source-dynamic-pool translation-type dynamic-nat44 
    
  10. Go to the [edit services adaptive-services-pics] hierarchy level. In the following command, the top keyword ensures that the command is run from the top of the hierarchy.
    content_copy zoom_out_map
    [edit services nat rule rule-dynamic-nat44 term t1]
    user@host# top editservices adaptive-services-pics
    
  11. Configure the trace options.
    content_copy zoom_out_map
    [edit services adaptive-services-pics]
    user@host# set traceoptions flag tracing parameter
    

    In the following example, the tracing parameter is configured as all.

    content_copy zoom_out_map
    [edit services adaptive-services-pics]
    user@host# set traceoptions flag all
    
  12. Verify the configuration by using the show command at the [edit services] hierarchy level.
    content_copy zoom_out_map
    [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;
        }
      }
    

The following example configures the translation type as dynamic-nat44.

content_copy zoom_out_map
[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;
    }
  }

The following configuration specifies that NAT is not performed on incoming traffic from the source address 192.168.20.24/32 by providing a NAT rule term t0 that configures no-translation. Dynamic NAT is performed on all other incoming traffic, as configured by term t1 of the NAT rule. The no-translation option is supported on MX Series routers with MS-DPCs and on M Series routers with MS-100, MS-400, and MS-500 MultiServices PICS. The no-translation option is supported on MX Series routers with MS-MPCs and MS-MICs starting in Junos OS release 15.1R1.

content_copy zoom_out_map
[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;
            }
        }
    }
}

The following configuration performs NAT using the source prefix 20.20.10.0/24 without defining a pool.

content_copy zoom_out_map
[edit services nat]
rule src-nat {
    match-direction input;
    term t1 {
        then {
            translation-type dynamic-nat44;
            source-prefix 20.20.10.0/24;
        }
    }
}

The following configuration performs NAT using the destination prefix 20.20.10.0/32 without defining a pool.

content_copy zoom_out_map
[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;
            }
        }
    }
}

Example: Dynamic Source NAT as a Next-Hop Service

The following example shows dynamic-source NAT applied as a next-hop service:

content_copy zoom_out_map
[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;
    }
}

Example: Assigning Addresses from a Dynamic Pool for Static Use

The following configuration statically assigns a subset of addresses that are configured as part of a dynamic pool (dynamic-pool) to two separate static pools (static-pool and static-pool2).

content_copy zoom_out_map
[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;
        }
    }
}
footer-navigation