All of lore.kernel.org
 help / color / mirror / Atom feed
* [nft PATCH] nft.8: Enhance NAT documentation
@ 2017-05-02 17:51 Phil Sutter
  2017-05-04  7:04 ` Arturo Borrero Gonzalez
  2017-05-04  8:24 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: Phil Sutter @ 2017-05-02 17:51 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

This adds documentation about masquerade and redirect statements, points
out that for any NAT statement both prerouting and postrouting chains
are required and adds a bunch of examples to the section's end.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 doc/nft.xml | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/doc/nft.xml b/doc/nft.xml
index 4d0e89cd2054c..5680cdf1f5a22 100644
--- a/doc/nft.xml
+++ b/doc/nft.xml
@@ -4121,12 +4121,45 @@ ct eventmask set new or related or destroy
 						<arg choice="opt">:<replaceable>port</replaceable> - <replaceable>port</replaceable></arg></arg>
 						<arg choice="opt">persistent, random, fully-random</arg>
 				</cmdsynopsis>
+				<cmdsynopsis>
+						<command>masquerade</command>
+						<arg choice="none">to
+						<arg choice="opt">:<replaceable>port</replaceable></arg></arg>
+						<arg choice="opt">persistent, random, fully-random</arg>
+				</cmdsynopsis>
+				<cmdsynopsis>
+						<command>masquerade</command>
+						<arg choice="none">to
+						<arg choice="opt">:<replaceable>port</replaceable> - <replaceable>port</replaceable></arg></arg>
+						<arg choice="opt">persistent, random, fully-random</arg>
+				</cmdsynopsis>
+				<cmdsynopsis>
+						<command>redirect</command>
+						<arg choice="none">to
+						<arg choice="opt">:<replaceable>port</replaceable></arg></arg>
+						<arg choice="opt">persistent, random, fully-random</arg>
+				</cmdsynopsis>
+				<cmdsynopsis>
+						<command>redirect</command>
+						<arg choice="none">to
+						<arg choice="opt">:<replaceable>port</replaceable> - <replaceable>port</replaceable></arg></arg>
+						<arg choice="opt">persistent, random, fully-random</arg>
+				</cmdsynopsis>
 			</para>
 			<para>
 				The nat statements are only valid from nat chain types.
 			</para>
 			<para>
-				The <command>snat</command> statement is only valid in the postrouting and input hooks, it specifies that the source address of the packet should be modified. The <command>dnat</command> statement is only valid in the prerouting and output chains, it specifies that the destination address of the packet should be modified. You can use non-base chains which are called from base chains of nat chain type too. All future packets in this connection will also be mangled, and rules should cease being examined.
+				The <command>snat</command> and <command>masquerade</command> statements specify that the source address of the packet should be modified. While <command>snat</command> is only valid in the postrouting and input chains, <command>masquerade</command> makes sense only in postrouting. The <command>dnat</command> and <command>redirect</command> statements are only valid in the prerouting and output chains, they specify that the destination address of the packet should be modified. You can use non-base chains which are called from base chains of nat chain type too. All future packets in this connection will also be mangled, and rules should cease being examined.
+			</para>
+			<para>
+				The <command>masquerade</command> statement is a special form of <command>snat</command> which always uses the outgoing interface's IP address to translate to. It is particularly useful on gateways with dynamic (public) IP addresses.
+			</para>
+			<para>
+				The <command>redirect</command> statement is a special form of <command>dnat</command> which always translates the destination address to the local host's one. It comes in handy if one only wants to alter the destination port of incoming traffic on different interfaces.
+			</para>
+			<para>
+				Note that all nat statements require both prerouting and postrouting base chains to be present since otherwise packets on the return path won't be seen by netfilter and therefore no reverse translation will take place.
 			</para>
 			<para>
 				<table frame="all">
@@ -4183,7 +4216,30 @@ ct eventmask set new or related or destroy
 						</tbody>
 					</tgroup>
 				</table>
+			</para>
+			<para>
+				<example>
+					<title>Using NAT statements</title>
+					<programlisting>
+# create a suitable table/chain setup for all further examples
+add table nat
+add chain nat prerouting { type nat hook prerouting priority 0; }
+add chain nat postrouting { type nat hook postrouting priority 100; }
+
+# translate source addresses of all packets leaving via eth0 to address 1.2.3.4
+add rule nat postrouting oif eth0 snat to 1.2.3.4
 
+# redirect all traffic entering via eth0 to destination address 192.168.1.120
+add rule nat prerouting iif eth0 dnat to 192.168.1.120
+
+# translate source addresses of all packets leaving via eth0 to whatever
+# locally generated packets would use as source to reach the same destination
+add rule nat postrouting oif eth0 masquerade
+
+# redirect incoming TCP traffic for port 22 to port 2222
+add rule nat prerouting tcp dport 22 redirect to :2222
+					</programlisting>
+				</example>
 			</para>
 		</refsect2>
 		<refsect2>
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [nft PATCH] nft.8: Enhance NAT documentation
  2017-05-02 17:51 [nft PATCH] nft.8: Enhance NAT documentation Phil Sutter
@ 2017-05-04  7:04 ` Arturo Borrero Gonzalez
  2017-05-04  8:24 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Arturo Borrero Gonzalez @ 2017-05-04  7:04 UTC (permalink / raw)
  To: Phil Sutter; +Cc: Netfilter Development Mailing list

On 2 May 2017 at 19:51, Phil Sutter <phil@nwl.cc> wrote:
> This adds documentation about masquerade and redirect statements, points
> out that for any NAT statement both prerouting and postrouting chains
> are required and adds a bunch of examples to the section's end.
>
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
>  doc/nft.xml | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 57 insertions(+), 1 deletion(-)
>

Thanks Phil, more docs are always good.

Acked-by: Arturo Borrero Gonzalez <arturo@debian.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [nft PATCH] nft.8: Enhance NAT documentation
  2017-05-02 17:51 [nft PATCH] nft.8: Enhance NAT documentation Phil Sutter
  2017-05-04  7:04 ` Arturo Borrero Gonzalez
@ 2017-05-04  8:24 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-05-04  8:24 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel

On Tue, May 02, 2017 at 07:51:27PM +0200, Phil Sutter wrote:
> This adds documentation about masquerade and redirect statements, points
> out that for any NAT statement both prerouting and postrouting chains
> are required and adds a bunch of examples to the section's end.

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-04  8:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-02 17:51 [nft PATCH] nft.8: Enhance NAT documentation Phil Sutter
2017-05-04  7:04 ` Arturo Borrero Gonzalez
2017-05-04  8:24 ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.