Source NAT is basically configured as follows:
Create an address pool.
To specify the address range in an address pool, you can configure one or more address segments or specify a large address range and then exclude the addresses and ports that cannot be used.
Operation |
Command |
|---|---|
Create a NAT address pool. |
nat address-group group-name [ group-number ] |
Set an IP address range. |
section [ id ] start-ipv4 [ end-ipv4 ] |
Exclude certain addresses or ports. |
exclude-ip { ip-address1 [ to ip-address2 ] | ip-address1 mask { mask-value | mask-length } } exclude-port port1 [ to port2 ] |
Set an address pool mode. The address pool mode varies with the Source NAT type.
mode { pat | no-pat { global | local } | full-cone { global | local } [ no-reverse ] }
Source NAT Type |
Command |
Description |
|---|---|---|
NAT No-PAT |
mode no-pat { global | local } |
- |
NAPT |
mode pat |
- |
3-Tuple NAT |
mode full-cone { global | local } [ no-reverse ] Optional: smart-fullcone exclude-dest-port port1 port2 |
For 3-Tuple NAT, one port range can be reserved for NAPT. |
Smart NAT |
mode no-pat { global | local } smart-nopat ip-address |
For Smart NAT, after configuring the address pool mode, you need to specify a reserved address for NAPT. |
Operation |
Command |
|---|---|
Set the maximum number of private addresses corresponding to a public address. |
srcip-car-num srcip-number [ no-port-translation ] |
Configure the range of port numbers for port translation. |
nat port range begin-port end-port |
Configure the working status for an address pool. |
status { maintenance | inactive } |
Configure the black-hole route to prevent routing loop.
The NAT function is implemented using NAT rules in the NAT policy. Create a NAT rule to specify the data flow to be translated and the translation action.
If multiple NAT rules are configured, the device matches them from top to bottom in the NAT rule list. If the traffic matches a NAT rule, the following rules will no longer be matched. Therefore, pay attention to the configuration sequence.
Create a NAT rule and set matching conditions.
All matching conditions are optional for traffic matching. The default matching condition is any. If an optional matching condition is configured, traffic that meets the condition is matched. If it is not configured, traffic is not matched with this matching condition.
Operation |
Command |
Description |
|---|---|---|
Enter the NAT policy view and create a NAT rule. |
rule name rule-name |
- |
| Set the matching condition (address) of the NAT rule. |
|
For example, NAT needs to be performed for users in the network segment 10.1.1.0/24, excluding the users from 10.1.1.2 to 10.1.1.5. [sysname] nat-policy [sysname-policy-nat] rule name policy1 [sysname-policy-nat-rule-policy1] source-address 10.1.1.0 24 [sysname-policy-nat-rule-policy1] source-address-exclude range 10.1.1.2 10.1.1.5 |
| Set the matching condition (security zone) of the NAT rule. |
|
- |
| Set the matching condition (service) of the NAT rule. |
|
The device supports two modes in which a service is specified:
For example, to specify source ports (TCP ports 123 to 128) as the matching condition: The first configuration method: [sysname] ip service-set set1 type object [sysname-object-service-set-set1] service protocol tcp source-port 123 to 128 [sysname-object-service-set-set1] quit [sysname] nat-policy [sysname-policy-nat] rule name policy1 [sysname-policy-nat-rule-policy1] service set1 The second configuration method: [sysname] nat-policy [sysname-policy-nat] rule name policy1 [sysname-policy-nat-rule-policy1] service protocol tcp source-port 123 to 128 |
Set an action for the NAT rule.
action { source-nat { address-group address-group-name | easy-ip } | no-nat }
nat indicates that NAT is performed for the matched traffic, while no-nat indicates that NAT is not performed for the matched traffic.
no-nat mainly applies to certain special clients. For example, to perform NAT on all hosts except 192.168.1.2 on the 192.168.1.0/24 network segment, you can first configure a policy that does not translate 192.168.1.2 and then configure a policy to translate the 192.168.1.0/24 network segment.