Dnat

These scenarios show how to configure DNAT (Destination Network Address Translation) on OSDx.

../../../../../_images/dnat.svg

Test DNAT

Description

In this scenario, DUT0 modifies the source address of outgoing packets generated at the LAN side. The address is translated to a custom one: 10.0.0.1.

Scenario

Step 1: Set the following configuration in DUT0:

set interfaces ethernet eth0 address 192.168.100.1/24
set interfaces ethernet eth1 address 10.0.0.2/24
set interfaces ethernet eth1 traffic nat destination rule 1 selector SEL
set traffic selector SEL rule 1 protocol tcp,udp
set interfaces ethernet eth1 traffic nat destination rule 1 address 192.168.100.2

Step 2: Set the following configuration in DUT1:

set interfaces ethernet eth0 address 10.0.0.22/24

Step 3: Set the following configuration in DUT2:

set interfaces ethernet eth0 address 192.168.100.2/24
set protocols static route 0.0.0.0/0 next-hop 192.168.100.1

Step 4: Ping IP address 192.168.100.2 from DUT0:

admin@DUT0$ ping 192.168.100.2 count 1 size 56 timeout 1
Show output
PING 192.168.100.2 (192.168.100.2) 56(84) bytes of data.
64 bytes from 192.168.100.2: icmp_seq=1 ttl=64 time=0.615 ms

--- 192.168.100.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.615/0.615/0.615/0.000 ms

Step 5: Ping IP address 10.0.0.22 from DUT0:

admin@DUT0$ ping 10.0.0.22 count 1 size 56 timeout 1
Show output
PING 10.0.0.22 (10.0.0.22) 56(84) bytes of data.
64 bytes from 10.0.0.22: icmp_seq=1 ttl=64 time=0.684 ms

--- 10.0.0.22 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.684/0.684/0.684/0.000 ms

Step 6: Initiate a tcp connection from DUT1 to DUT2 and try to send some messages between both endpoints

admin@DUT2$ monitor test connection server 8080 tcp
admin@DUT1$ monitor test connection client 10.0.0.2 8080 tcp

Step 7: Initiate a udp connection from DUT1 to DUT2 and try to send some messages between both endpoints

admin@DUT2$ monitor test connection server 5050 udp
admin@DUT1$ monitor test connection client 10.0.0.2 5050 udp

Step 8: Run command system conntrack show nat at DUT0 and check if output contains the following tokens:

src=10.0.0.22 dst=10.0.0.2
src=192.168.100.2 dst=10.0.0.2
Show output
tcp      6 17 TIME_WAIT src=10.0.0.22 dst=10.0.0.2 sport=48152 dport=8080 packets=6 bytes=338 src=192.168.100.2 dst=10.0.0.22 sport=8080 dport=48152 packets=5 bytes=286 [ASSURED] mark=0 use=1
udp      17 29 src=10.0.0.22 dst=10.0.0.2 sport=39194 dport=5050 packets=1 bytes=46 src=192.168.100.2 dst=10.0.0.22 sport=5050 dport=39194 packets=1 bytes=46 mark=0 use=1
icmp     1 24 src=192.168.100.1 dst=192.168.100.2 type=8 code=0 id=423 packets=1 bytes=84 src=192.168.100.2 dst=192.168.100.1 type=0 code=0 id=423 packets=1 bytes=84 mark=0 use=1
icmp     1 25 src=10.0.0.2 dst=10.0.0.22 type=8 code=0 id=424 packets=1 bytes=84 src=10.0.0.22 dst=10.0.0.2 type=0 code=0 id=424 packets=1 bytes=84 mark=0 use=1
conntrack v1.4.5 (conntrack-tools): 4 flow entries have been shown.

Test DNAT Redirect

Description

This scenario is similar to the previous one, but when masquerade is specified, the route uses the IP address of the outgoing interface. Therefore, masquerading should be configured if the outgoing interface uses a dynamic IP address.

Scenario

Step 1: Set the following configuration in DUT0:

set interfaces ethernet eth0 address 192.168.100.1/24
set interfaces ethernet eth1 address 10.0.0.2/24
set interfaces ethernet eth1 traffic nat destination rule 1 selector SEL
set traffic selector SEL rule 1 protocol tcp,udp
set interfaces ethernet eth1 traffic nat destination rule 1 address redirect

Step 2: Set the following configuration in DUT1:

set interfaces ethernet eth0 address 10.0.0.22/24
set protocols static route 0.0.0.0/0 next-hop 10.0.0.2

Step 3: Ping IP address 10.0.0.22 from DUT0:

admin@DUT0$ ping 10.0.0.22 count 1 size 56 timeout 1
Show output
PING 10.0.0.22 (10.0.0.22) 56(84) bytes of data.
64 bytes from 10.0.0.22: icmp_seq=1 ttl=64 time=0.733 ms

--- 10.0.0.22 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.733/0.733/0.733/0.000 ms

Step 4: Initiate a tcp connection from DUT1 to DUT0 and try to send some messages between both endpoints

admin@DUT0$ monitor test connection server 8080 tcp
admin@DUT1$ monitor test connection client 192.168.100.3 8080 tcp

Step 5: Initiate a udp connection from DUT1 to DUT0 and try to send some messages between both endpoints

admin@DUT0$ monitor test connection server 5050 udp
admin@DUT1$ monitor test connection client 192.168.100.3 5050 udp

Step 6: Run command system conntrack show nat at DUT0 and check if output contains the following tokens:

src=10.0.0.22 dst=192.168.100.3
src=10.0.0.2 dst=10.0.0.22
Show output
udp      17 29 src=10.0.0.22 dst=192.168.100.3 sport=56723 dport=5050 packets=1 bytes=46 src=10.0.0.2 dst=10.0.0.22 sport=5050 dport=56723 packets=1 bytes=46 mark=0 use=1
tcp      6 17 TIME_WAIT src=10.0.0.22 dst=192.168.100.3 sport=58882 dport=8080 packets=6 bytes=338 src=10.0.0.2 dst=10.0.0.22 sport=8080 dport=58882 packets=5 bytes=286 [ASSURED] mark=0 use=1
icmp     1 24 src=10.0.0.2 dst=10.0.0.22 type=8 code=0 id=425 packets=1 bytes=84 src=10.0.0.22 dst=10.0.0.2 type=0 code=0 id=425 packets=1 bytes=84 mark=0 use=1
conntrack v1.4.5 (conntrack-tools): 3 flow entries have been shown.