| 1 |
# dnat |
| 2 |
|
| 3 |
Destination NAT is used to mangle traffic by using standard [rules](../rule/index.md). |
| 4 |
|
| 5 |
Example: |
| 6 |
|
| 7 |
``` |
| 8 |
dnat { |
| 9 |
# http traffic to 10.0.0.1 is DNAT'ed to 10.0.0.2 port 8080 |
| 10 |
daddr 10.0.0.1 http dnat 10.0.0.2:8080 |
| 11 |
|
| 12 |
# http traffic to fd00:f00::1 is DNAT'ed to fd00:f00::2 port 8080 |
| 13 |
daddr fd00:f00::1 http dnat [fd00:f00::2]:8080 |
| 14 |
|
| 15 |
# http traffic to 10.0.0.6 is DNAT'ed to 10.0.0.7, port doesn't change |
| 16 |
daddr 10.0.0.6 http dnat 10.0.0.7 |
| 17 |
|
| 18 |
# All smtp traffic from eth2 is DNAT'ed to 10.0.0.8 or fd00:f00::8, |
| 19 |
# port doesn't change |
| 20 |
iifname eth2 smtp dnat 10.0.0.8 fd00:f00::8 |
| 21 |
|
| 22 |
# All traffic from eth1 inteface is DNAT'ed to 10.0.0.3 |
| 23 |
iifname eth1 dnat 10.0.0.3 |
| 24 |
|
| 25 |
# http traffic to 10.0.0.4 coming from interface eth2 is DNAT'ed to 10.0.0.5 |
| 26 |
iifname eth2 daddr 10.0.0.4 http dnat 10.0.0.5 |
| 27 |
|
| 28 |
# http traffic to localhost coming from interface eth3 is DNAT'ed to 10.0.0.6 |
| 29 |
iifname eth3 oifname lo http dnat 10.0.0.6 |
| 30 |
} |
| 31 |
``` |
| 32 |
|
| 33 |
Remember to accept DNAT'ed traffic in zone-zone section. This can be done |
| 34 |
with specific rule or with `ct_status` matcher. Example: |
| 35 |
|
| 36 |
``` |
| 37 |
public-internal { |
| 38 |
# Specific rule to accept https |
| 39 |
https daddr 10.0.0.9 |
| 40 |
|
| 41 |
# Generic rule to accept all DNAT'ed traffic |
| 42 |
ct_status dnat |
| 43 |
} |
| 44 |
``` |