Next: Traffic, Previous: ACL, Up: Configuration
<nat> sectionThe NAT section is used to define network address translation rules, these
rules allow one to translate the source or destination IP address within
packets. A common use for this is when a webserver is behind a firewall,
requests are made to a globally routable IP address and translated to the
internal IP address of the webserver and visa versa.
This section has the following syntax...
<firewall>
.
.
.
<nat>
<snat>
<rule name="traf_from_webserver"
to-src="<globally routable IP here>">
traffic_from_webserver
</rule>
</snat>
<dnat>
<rule name="traf_to_webserver" to-dst="192.168.1.100">
traffic_to_webserver
</rule>
</dnat>
<masq>
<rule name="traf_to_from_inside">
internal_dsl_ips
</rule>
</masq>
</nat>
.
.
.
</firewall>
There are 3 tags available, <snat>, <dnat> and <masq>,
these three tags are used for source network address translation, destination
address translation and masquerading respectively.
Valid options for these tags are as follows...
<snat>
<rule> ... </rule>
<rule> tag is used to specify what classes apply to what rule,
and are in order inserted into the actual iptables chains as iptables rules.
The <rule> tag takes the following parameters...
name="..." - Optional name of rule
to-src"..." - Translate all traffic matched in the class
specification to this source IP address.
Between the opening and closing tags, classes defined in the <global>
section are listed, these classify which traffic applies to which rule.
Multiple classes can be listed, one per line.
<dnat>
<rule> ... </rule>
<rule> tag is used to specify what classes apply to what rule,
and are in order inserted into the actual iptables chains as iptables rules.
<rule> tag takes the following parameters...
name="..." - Optional name of rule
to-dst"..." - Translate all traffic matched in the class
specification to this destination IP address.
<global>
section are listed, these classify which traffic applies to which rule.
<masq>
<rule> ... </rule>
<rule> tag is used to specify what classes apply to what rule,
and are in order inserted into the actual iptables chains as iptables rules.
The <rule> tag takes the following parameters...
name="..." - Optional name of rule
to-ports"..." - This specifies a range of source ports to use,
overriding the default SNAT source port-selection heuristics. For this
parameter to work you MUST have defined a protocol in all the classes
specified. For example proto="tcp".
Between the opening and closing tags, classes defined in the <global>
section are listed, these classify which traffic applies to which rule.
Multiple classes can be listed, one per line.
<firewall>
# Global configuration and access classes
<global>
<class name="traf_from_webserver">
<address src="192.168.0.100"/>
</class>
<class name="traf_to_webserver">
<address dst="<globally routable IP here>"/>
</class>
</global>
# Network address translation
<nat>
<snat>
<rule to-src="<globally routable IP here>">
traf_from_webserver
</rule>
</snat>
<dnat>
<rule to-dst="192.168.0.100">
traf_to_webserver
</rule>
</dnat>
</nat>
</firewall>
Here is an example if you pc is acting as a DSL router...
<firewall>
# Global configuration and access classes
<global>
<class name="traf_going_to_dsl">
<address src="192.168.0.0/24"/>
</class>
</global>
# Network address translation
<nat>
<masq>
<rule name="masq_traffic_going_out">
traf_going_to_dsl
</rule>
</masq>
</nat>
</firewall>