diff options
author | Máté Eckl <ecklm94@gmail.com> | 2018-08-10 06:58:39 -0400 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-08-16 13:37:07 -0400 |
commit | 1bfc2bc7ad8ac045045e99e33aa1ba727d2d291d (patch) | |
tree | 20fcefb229ba39fb7a7b6770cd3056431f1fe8d9 | |
parent | a148ce15375fc664ad64762c751c0c2aecb2cafe (diff) |
netfilter: doc: Add nf_tables part in tproxy.txt
Recently, transparent proxy support has been added to nf_tables so that
this document should be updated with the new information.
- Nft commands are added as alternatives to iptables ones.
- The link for a patched iptables is removed as it is already part of
the mainline iptables implementation (and the link is dead).
- tcprdr is added as an example implementation of a transparent proxy
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Florian Westphal <fw@strlen.de>
Cc: KOVACS Krisztian <hidden@sch.bme.hu>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: linux-doc@vger.kernel.org
Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | Documentation/networking/tproxy.txt | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/Documentation/networking/tproxy.txt b/Documentation/networking/tproxy.txt index ec11429e1d42..b9a188823d9f 100644 --- a/Documentation/networking/tproxy.txt +++ b/Documentation/networking/tproxy.txt | |||
@@ -5,19 +5,28 @@ This feature adds Linux 2.2-like transparent proxy support to current kernels. | |||
5 | To use it, enable the socket match and the TPROXY target in your kernel config. | 5 | To use it, enable the socket match and the TPROXY target in your kernel config. |
6 | You will need policy routing too, so be sure to enable that as well. | 6 | You will need policy routing too, so be sure to enable that as well. |
7 | 7 | ||
8 | From Linux 4.18 transparent proxy support is also available in nf_tables. | ||
8 | 9 | ||
9 | 1. Making non-local sockets work | 10 | 1. Making non-local sockets work |
10 | ================================ | 11 | ================================ |
11 | 12 | ||
12 | The idea is that you identify packets with destination address matching a local | 13 | The idea is that you identify packets with destination address matching a local |
13 | socket on your box, set the packet mark to a certain value, and then match on that | 14 | socket on your box, set the packet mark to a certain value: |
14 | value using policy routing to have those packets delivered locally: | ||
15 | 15 | ||
16 | # iptables -t mangle -N DIVERT | 16 | # iptables -t mangle -N DIVERT |
17 | # iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT | 17 | # iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT |
18 | # iptables -t mangle -A DIVERT -j MARK --set-mark 1 | 18 | # iptables -t mangle -A DIVERT -j MARK --set-mark 1 |
19 | # iptables -t mangle -A DIVERT -j ACCEPT | 19 | # iptables -t mangle -A DIVERT -j ACCEPT |
20 | 20 | ||
21 | Alternatively you can do this in nft with the following commands: | ||
22 | |||
23 | # nft add table filter | ||
24 | # nft add chain filter divert "{ type filter hook prerouting priority -150; }" | ||
25 | # nft add rule filter divert meta l4proto tcp socket transparent 1 meta mark set 1 accept | ||
26 | |||
27 | And then match on that value using policy routing to have those packets | ||
28 | delivered locally: | ||
29 | |||
21 | # ip rule add fwmark 1 lookup 100 | 30 | # ip rule add fwmark 1 lookup 100 |
22 | # ip route add local 0.0.0.0/0 dev lo table 100 | 31 | # ip route add local 0.0.0.0/0 dev lo table 100 |
23 | 32 | ||
@@ -57,17 +66,28 @@ add rules like this to the iptables ruleset above: | |||
57 | # iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY \ | 66 | # iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY \ |
58 | --tproxy-mark 0x1/0x1 --on-port 50080 | 67 | --tproxy-mark 0x1/0x1 --on-port 50080 |
59 | 68 | ||
69 | Or the following rule to nft: | ||
70 | |||
71 | # nft add rule filter divert tcp dport 80 tproxy to :50080 meta mark set 1 accept | ||
72 | |||
60 | Note that for this to work you'll have to modify the proxy to enable (SOL_IP, | 73 | Note that for this to work you'll have to modify the proxy to enable (SOL_IP, |
61 | IP_TRANSPARENT) for the listening socket. | 74 | IP_TRANSPARENT) for the listening socket. |
62 | 75 | ||
76 | As an example implementation, tcprdr is available here: | ||
77 | https://git.breakpoint.cc/cgit/fw/tcprdr.git/ | ||
78 | This tool is written by Florian Westphal and it was used for testing during the | ||
79 | nf_tables implementation. | ||
63 | 80 | ||
64 | 3. Iptables extensions | 81 | 3. Iptables and nf_tables extensions |
65 | ====================== | 82 | ==================================== |
66 | 83 | ||
67 | To use tproxy you'll need to have the 'socket' and 'TPROXY' modules | 84 | To use tproxy you'll need to have the following modules compiled for iptables: |
68 | compiled for iptables. A patched version of iptables is available | 85 | - NETFILTER_XT_MATCH_SOCKET |
69 | here: http://git.balabit.hu/?p=bazsi/iptables-tproxy.git | 86 | - NETFILTER_XT_TARGET_TPROXY |
70 | 87 | ||
88 | Or the floowing modules for nf_tables: | ||
89 | - NFT_SOCKET | ||
90 | - NFT_TPROXY | ||
71 | 91 | ||
72 | 4. Application support | 92 | 4. Application support |
73 | ====================== | 93 | ====================== |