NVIDIA DOCA™ HBN supports IPv4 source network address translation (SNAT) and destination network address translation (DNAT) on NVIDIA® BlueField® uplink interfaces and subinterfaces. NAT rules translate IP addresses and, when port address translation (PAT) is configured, transport-layer ports.
HBN supports NAT for ICMP, TCP, and UDP traffic.
-
Static NAT provides a persistent one-to-one mapping. It is stateless, does not use connection tracking, and is enabled by default.
-
Dynamic NAT maps addresses or ports from a configured pool. It is stateful, uses connection tracking, and must be enabled before you configure dynamic rules.
Before You Begin
-
Determine whether the deployment requires static or dynamic NAT.
-
Plan the private and public address ranges, translated ports, protocols, and rule direction.
-
Apply SNAT rules in the outbound direction and DNAT rules in the inbound direction on each applicable public-facing uplink or subinterface.
-
Replace the ACL names, interfaces, addresses, prefixes, and ports in the examples with deployment-specific values.
Source NAT
Static SNAT
NVUE ICMP Example
The following rule translates the source address of ICMP packets from 30.30.30.2 to 100.100.100.1:
nv set acl acl_1 rule 1 action source-nat translate-ip 100.100.100.1
nv set acl acl_1 rule 1 match ip protocol icmp
nv set acl acl_1 rule 1 match ip source-ip 30.30.30.2
nv set acl acl_1 type ipv4
Bind the ACL to the BlueField uplinks in the outbound direction:
nv set interface p0_if acl acl_1 outbound
nv set interface p1_if acl acl_1 outbound
NVUE UDP With PAT Example
The following rule translates UDP source address 21.1.0.18 and source port 10011 to source address 199.5.1.1 and source port 11011:
nv set acl stnatpat rule 1 action source-nat translate-ip 199.5.1.1
nv set acl stnatpat rule 1 action source-nat translate-port 11011
nv set acl stnatpat rule 1 match ip protocol udp
nv set acl stnatpat rule 1 match ip source-ip 21.1.0.18
nv set acl stnatpat rule 1 match ip source-port 10011
nv set acl stnatpat type ipv4
Bind the ACL to the uplink subinterfaces in the outbound direction:
nv set interface p0_if.10,p1_if.10 acl stnatpat outbound
Flat-File Examples
[iptables]
## ACL acl_1 in dir outbound on interface p0_if ##
-t nat -A POSTROUTING -m physdev --physdev-out p0_if -s 30.30.30.2 -p icmp -j SNAT --to-source 100.100.100.1 -m mark --mark 0xdead
## ACL acl_1 in dir outbound on interface p1_if ##
-t nat -A POSTROUTING -m physdev --physdev-out p1_if -s 30.30.30.2 -p icmp -j SNAT --to-source 100.100.100.1 -m mark --mark 0xdead
## ACL stnatpat in dir outbound on interface p0_if.10 ##
-t nat -A POSTROUTING -o p0_if.10 -s 21.1.0.18 -p udp --sport 10011 -j SNAT --to-source 199.5.1.1:11011 -m mark --mark 0xdead
## ACL stnatpat in dir outbound on interface p1_if.10 ##
-t nat -A POSTROUTING -o p1_if.10 -s 21.1.0.18 -p udp --sport 10011 -j SNAT --to-source 199.5.1.1:11011 -m mark --mark 0xdead
Dynamic SNAT
Enable dynamic NAT mode:
nv set system nat mode dynamic
NVUE TCP Address-Pool Example
The following rule translates TCP traffic from source prefix 21.1.0.0/16 to addresses in the range 199.10.0.1 through 199.10.255.254:
nv set acl dnat1 rule 1 action source-nat translate-ip 199.10.0.1 to 199.10.255.254
nv set acl dnat1 rule 1 match ip protocol tcp
nv set acl dnat1 rule 1 match ip source-ip 21.1.0.0/16
nv set acl dnat1 type ipv4
Bind the ACL to the uplink subinterfaces in the outbound direction:
nv set interface p0_if.10,p1_if.10 acl dnat1 outbound
NVUE TCP Address-Pool and PAT Example
The following rule translates TCP traffic from source prefix 30.30.30.0/29 and source port 5000 to the address range 100.100.100.8 through 100.100.100.15 and source port 10000:
nv set acl acl_2 rule 1 action source-nat translate-ip 100.100.100.8 to 100.100.100.15
nv set acl acl_2 rule 1 action source-nat translate-port 10000
nv set acl acl_2 rule 1 match ip protocol tcp
nv set acl acl_2 rule 1 match ip source-ip 30.30.30.0/29
nv set acl acl_2 rule 1 match ip source-port 5000
nv set acl acl_2 type ipv4
Bind the ACL to the uplinks in the outbound direction:
nv set interface p0_if,p1_if acl acl_2 outbound
Flat-File Examples
## ACL dnat1 in dir outbound on interface p0_if.10 ##
-t nat -A POSTROUTING -o p0_if.10 -s 21.1.0.0/16 -p tcp -j SNAT --to-source 199.10.0.1-199.10.255.254 -m mark --mark 0xdead
## ACL dnat1 in dir outbound on interface p1_if.10 ##
-t nat -A POSTROUTING -o p1_if.10 -s 21.1.0.0/16 -p tcp -j SNAT --to-source 199.10.0.1-199.10.255.254 -m mark --mark 0xdead
## ACL acl_2 in dir outbound on interface p0_if ##
-t nat -A POSTROUTING -m physdev --physdev-out p0_if -s 30.30.30.0/29 -p tcp --sport 5000 -j SNAT --to-source 100.100.100.8-100.100.100.15:10000 -m mark --mark 0xdead
## ACL acl_2 in dir outbound on interface p1_if ##
-t nat -A POSTROUTING -m physdev --physdev-out p1_if -s 30.30.30.0/29 -p tcp --sport 5000 -j SNAT --to-source 100.100.100.8-100.100.100.15:10000 -m mark --mark 0xdead
The following NVUE example maps the source prefix to a single public address and allocates translated ports from 10001 through 24000:
nv set acl dnatpat1 rule 1 action source-nat translate-ip 199.9.1.1
nv set acl dnatpat1 rule 1 match ip protocol tcp
nv set acl dnatpat1 rule 1 match ip source-ip 21.1.0.0/16
nv set acl dnatpat1 rule 1 action source-nat translate-port 10001-24000
nv set acl dnatpat1 type ipv4
nv set interface p0_if.10,p1_if.10 acl dnatpat1 outbound
Destination NAT
Static DNAT
NVUE ICMP Example
The following rule translates the destination address of incoming ICMP packets from 100.100.100.1 to 30.30.30.2:
nv set acl acl_1 rule 1 action dest-nat translate-ip 30.30.30.2
nv set acl acl_1 rule 1 match ip protocol icmp
nv set acl acl_1 rule 1 match ip dest-ip 100.100.100.1
nv set acl acl_1 type ipv4
Bind the ACL to the BlueField uplinks in the inbound direction:
nv set interface p0_if acl acl_1 inbound
nv set interface p1_if acl acl_1 inbound
Flat-File Example
## ACL acl_1 in dir inbound on interface p0_if ##
-t nat -A PREROUTING -m physdev --physdev-in p0_if -d 100.100.100.1 -p icmp -j DNAT --to-destination 30.30.30.2 -m mark --mark 0xdead
## ACL acl_1 in dir inbound on interface p1_if ##
-t nat -A PREROUTING -m physdev --physdev-in p1_if -d 100.100.100.1 -p icmp -j DNAT --to-destination 30.30.30.2 -m mark --mark 0xdead
Dynamic DNAT
Dynamic DNAT uses the same dynamic NAT mode enabled for dynamic SNAT:
nv set system nat mode dynamic
You can configure multiple dynamic DNAT rules and bind multiple DNAT ACLs to the same uplink interfaces.
ICMP Example
nv set acl dyndnaticmp rule 1 action dest-nat translate-ip 21.1.0.19 to 21.1.0.20
nv set acl dyndnaticmp rule 1 match ip dest-ip 199.101.6.0/30
nv set acl dyndnaticmp rule 1 match ip protocol icmp
nv set acl dyndnaticmp rule 2 action dest-nat translate-ip 120.19.0.19 to 120.19.0.20
nv set acl dyndnaticmp rule 2 match ip dest-ip 199.101.6.4/30
nv set acl dyndnaticmp rule 2 match ip protocol icmp
nv set acl dyndnaticmp rule 3 action dest-nat translate-ip 21.1.0.15 to 21.1.0.16
nv set acl dyndnaticmp rule 3 match ip dest-ip 199.101.6.8/30
nv set acl dyndnaticmp rule 3 match ip protocol icmp
nv set acl dyndnaticmp type ipv4
TCP Example
nv set acl dyndnattcp rule 1 action dest-nat translate-ip 21.1.0.19 to 21.1.0.20
nv set acl dyndnattcp rule 1 match ip dest-ip 199.101.7.0/30
nv set acl dyndnattcp rule 1 match ip protocol tcp
nv set acl dyndnattcp rule 2 action dest-nat translate-ip 120.19.0.19 to 120.19.0.20
nv set acl dyndnattcp rule 2 match ip dest-ip 199.101.7.4/30
nv set acl dyndnattcp rule 2 match ip protocol tcp
nv set acl dyndnattcp rule 3 action dest-nat translate-ip 21.1.0.15 to 21.1.0.16
nv set acl dyndnattcp rule 3 match ip dest-ip 199.101.7.8/30
nv set acl dyndnattcp rule 3 match ip protocol tcp
nv set acl dyndnattcp type ipv4
UDP Example
nv set acl dyndnatudp rule 1 action dest-nat translate-ip 21.1.0.19 to 21.1.0.20
nv set acl dyndnatudp rule 1 match ip dest-ip 199.101.8.0/30
nv set acl dyndnatudp rule 1 match ip protocol udp
nv set acl dyndnatudp rule 2 action dest-nat translate-ip 120.19.0.19 to 120.19.0.20
nv set acl dyndnatudp rule 2 match ip dest-ip 199.101.8.4/30
nv set acl dyndnatudp rule 2 match ip protocol udp
nv set acl dyndnatudp rule 3 action dest-nat translate-ip 21.1.0.15 to 21.1.0.16
nv set acl dyndnatudp rule 3 match ip dest-ip 199.101.8.8/30
nv set acl dyndnatudp rule 3 match ip protocol udp
nv set acl dyndnatudp type ipv4
Bind the Dynamic DNAT ACLs
nv set interface p0_if.10,p1_if.10 acl dyndnaticmp inbound
nv set interface p0_if.10,p1_if.10 acl dyndnattcp inbound
nv set interface p0_if.10,p1_if.10 acl dyndnatudp inbound
After applying the configuration, verify that traffic matching each rule is translated on the intended interface and that unrelated traffic is not translated.
Last updated: