€•ð?Œsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ%/translations/zh_CN/networking/tproxy”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ%/translations/zh_TW/networking/tproxy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ%/translations/it_IT/networking/tproxy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ%/translations/ja_JP/networking/tproxy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ%/translations/ko_KR/networking/tproxy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ%/translations/pt_BR/networking/tproxy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ%/translations/sp_SP/networking/tproxy”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒcomment”“”)”}”(hŒ SPDX-License-Identifier: GPL-2.0”h]”hŒ SPDX-License-Identifier: GPL-2.0”…””}”hh·sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1hµhhh²hh³Œ?/var/lib/git/docbuild/linux/Documentation/networking/tproxy.rst”h´KubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒTransparent proxy support”h]”hŒTransparent proxy support”…””}”(hhÏh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhhÊh²hh³hÇh´KubhŒ paragraph”“”)”}”(hŒãThis feature adds Linux 2.2-like transparent proxy support to current kernels. To use it, enable the socket match and the TPROXY target in your kernel config. You will need policy routing too, so be sure to enable that as well.”h]”hŒãThis feature adds Linux 2.2-like transparent proxy support to current kernels. To use it, enable the socket match and the TPROXY target in your kernel config. You will need policy routing too, so be sure to enable that as well.”…””}”(hhßh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KhhÊh²hubhÞ)”}”(hŒIFrom Linux 4.18 transparent proxy support is also available in nf_tables.”h]”hŒIFrom Linux 4.18 transparent proxy support is also available in nf_tables.”…””}”(hhíh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K hhÊh²hubhÉ)”}”(hhh]”(hÎ)”}”(hŒ 1. Making non-local sockets work”h]”hŒ 1. Making non-local sockets work”…””}”(hhþh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhhûh²hh³hÇh´KubhÞ)”}”(hŒŒThe idea is that you identify packets with destination address matching a local socket on your box, set the packet mark to a certain value::”h]”hŒ‹The idea is that you identify packets with destination address matching a local socket on your box, set the packet mark to a certain value:”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Khhûh²hubhŒ literal_block”“”)”}”(hŒÇ# iptables -t mangle -N DIVERT # iptables -t mangle -A PREROUTING -p tcp -m socket --transparent -j DIVERT # iptables -t mangle -A DIVERT -j MARK --set-mark 1 # iptables -t mangle -A DIVERT -j ACCEPT”h]”hŒÇ# iptables -t mangle -N DIVERT # iptables -t mangle -A PREROUTING -p tcp -m socket --transparent -j DIVERT # iptables -t mangle -A DIVERT -j MARK --set-mark 1 # iptables -t mangle -A DIVERT -j ACCEPT”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jh³hÇh´Khhûh²hubhÞ)”}”(hŒBAlternatively you can do this in nft with the following commands::”h]”hŒAAlternatively you can do this in nft with the following commands:”…””}”(hj*h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Khhûh²hubj)”}”(hŒ¿# nft add table filter # nft add chain filter divert "{ type filter hook prerouting priority -150; }" # nft add rule filter divert meta l4proto tcp socket transparent 1 meta mark set 1 accept”h]”hŒ¿# nft add table filter # nft add chain filter divert "{ type filter hook prerouting priority -150; }" # nft add rule filter divert meta l4proto tcp socket transparent 1 meta mark set 1 accept”…””}”hj8sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jh³hÇh´Khhûh²hubhÞ)”}”(hŒ[And then match on that value using policy routing to have those packets delivered locally::”h]”hŒZAnd then match on that value using policy routing to have those packets delivered locally:”…””}”(hjFh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Khhûh²hubj)”}”(hŒQ# ip rule add fwmark 1 lookup 100 # ip route add local 0.0.0.0/0 dev lo table 100”h]”hŒQ# ip rule add fwmark 1 lookup 100 # ip route add local 0.0.0.0/0 dev lo table 100”…””}”hjTsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jh³hÇh´K!hhûh²hubhÞ)”}”(hXBecause of certain restrictions in the IPv4 routing output code you'll have to modify your application to allow it to send datagrams _from_ non-local IP addresses. All you have to do is enable the (SOL_IP, IP_TRANSPARENT) socket option before calling bind::”h]”hXBecause of certain restrictions in the IPv4 routing output code you’ll have to modify your application to allow it to send datagrams _from_ non-local IP addresses. All you have to do is enable the (SOL_IP, IP_TRANSPARENT) socket option before calling bind:”…””}”(hjbh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K$hhûh²hubj)”}”(hXfd = socket(AF_INET, SOCK_STREAM, 0); /* - 8< -*/ int value = 1; setsockopt(fd, SOL_IP, IP_TRANSPARENT, &value, sizeof(value)); /* - 8< -*/ name.sin_family = AF_INET; name.sin_port = htons(0xCAFE); name.sin_addr.s_addr = htonl(0xDEADBEEF); bind(fd, &name, sizeof(name));”h]”hXfd = socket(AF_INET, SOCK_STREAM, 0); /* - 8< -*/ int value = 1; setsockopt(fd, SOL_IP, IP_TRANSPARENT, &value, sizeof(value)); /* - 8< -*/ name.sin_family = AF_INET; name.sin_port = htons(0xCAFE); name.sin_addr.s_addr = htonl(0xDEADBEEF); bind(fd, &name, sizeof(name));”…””}”hjpsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jh³hÇh´K)hhûh²hubhÞ)”}”(hŒ{A trivial patch for netcat is available here: http://people.netfilter.org/hidden/tproxy/netcat-ip_transparent-support.patch”h]”(hŒ.A trivial patch for netcat is available here: ”…””}”(hj~h²hh³Nh´NubhŒ reference”“”)”}”(hŒMhttp://people.netfilter.org/hidden/tproxy/netcat-ip_transparent-support.patch”h]”hŒMhttp://people.netfilter.org/hidden/tproxy/netcat-ip_transparent-support.patch”…””}”(hjˆh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”jŠuh1j†hj~ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K3hhûh²hubeh}”(h]”Œmaking-non-local-sockets-work”ah ]”h"]”Œ 1. making non-local sockets work”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´KubhÉ)”}”(hhh]”(hÎ)”}”(hŒ2. Redirecting traffic”h]”hŒ2. Redirecting traffic”…””}”(hj¨h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhj¥h²hh³hÇh´K8ubhÞ)”}”(hXüTransparent proxying often involves "intercepting" traffic on a router. This is usually done with the iptables REDIRECT target; however, there are serious limitations of that method. One of the major issues is that it actually modifies the packets to change the destination address -- which might not be acceptable in certain situations. (Think of proxying UDP for example: you won't be able to find out the original destination address. Even in case of TCP getting the original destination address is racy.)”h]”hXTransparent proxying often involves “intercepting†traffic on a router. This is usually done with the iptables REDIRECT target; however, there are serious limitations of that method. One of the major issues is that it actually modifies the packets to change the destination address -- which might not be acceptable in certain situations. (Think of proxying UDP for example: you won’t be able to find out the original destination address. Even in case of TCP getting the original destination address is racy.)”…””}”(hj¶h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K:hj¥h²hubhÞ)”}”(hŒ…The 'TPROXY' target provides similar functionality without relying on NAT. Simply add rules like this to the iptables ruleset above::”h]”hŒˆThe ‘TPROXY’ target provides similar functionality without relying on NAT. Simply add rules like this to the iptables ruleset above:”…””}”(hjÄh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KBhj¥h²hubj)”}”(hŒh# iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY \ --tproxy-mark 0x1/0x1 --on-port 50080”h]”hŒh# iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY \ --tproxy-mark 0x1/0x1 --on-port 50080”…””}”hjÒsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jh³hÇh´KEhj¥h²hubhÞ)”}”(hŒOr the following rule to nft::”h]”hŒOr the following rule to nft:”…””}”(hjàh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KHhj¥h²hubj)”}”(hŒQ# nft add rule filter divert tcp dport 80 tproxy to :50080 meta mark set 1 accept”h]”hŒQ# nft add rule filter divert tcp dport 80 tproxy to :50080 meta mark set 1 accept”…””}”hjîsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1jh³hÇh´KJhj¥h²hubhÞ)”}”(hŒwNote that for this to work you'll have to modify the proxy to enable (SOL_IP, IP_TRANSPARENT) for the listening socket.”h]”hŒyNote that for this to work you’ll have to modify the proxy to enable (SOL_IP, IP_TRANSPARENT) for the listening socket.”…””}”(hjüh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KLhj¥h²hubhÞ)”}”(hŒÏAs an example implementation, tcprdr is available here: https://git.breakpoint.cc/cgit/fw/tcprdr.git/ This tool is written by Florian Westphal and it was used for testing during the nf_tables implementation.”h]”(hŒ8As an example implementation, tcprdr is available here: ”…””}”(hj h²hh³Nh´Nubj‡)”}”(hŒ-https://git.breakpoint.cc/cgit/fw/tcprdr.git/”h]”hŒ-https://git.breakpoint.cc/cgit/fw/tcprdr.git/”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”juh1j†hj ubhŒj This tool is written by Florian Westphal and it was used for testing during the nf_tables implementation.”…””}”(hj h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KOhj¥h²hubeh}”(h]”Œredirecting-traffic”ah ]”h"]”Œ2. redirecting traffic”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´K8ubhÉ)”}”(hhh]”(hÎ)”}”(hŒ$3. Iptables and nf_tables extensions”h]”hŒ$3. Iptables and nf_tables extensions”…””}”(hj6h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhj3h²hh³hÇh´KUubhÞ)”}”(hŒNTo use tproxy you'll need to have the following modules compiled for iptables:”h]”hŒPTo use tproxy you’ll need to have the following modules compiled for iptables:”…””}”(hjDh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KWhj3h²hubhŒ block_quote”“”)”}”(hŒ9- NETFILTER_XT_MATCH_SOCKET - NETFILTER_XT_TARGET_TPROXY ”h]”hŒ bullet_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hŒNETFILTER_XT_MATCH_SOCKET”h]”hÞ)”}”(hjah]”hŒNETFILTER_XT_MATCH_SOCKET”…””}”(hjch²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KYhj_ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjZubj^)”}”(hŒNETFILTER_XT_TARGET_TPROXY ”h]”hÞ)”}”(hŒNETFILTER_XT_TARGET_TPROXY”h]”hŒNETFILTER_XT_TARGET_TPROXY”…””}”(hjzh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´KZhjvubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjZubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1jXh³hÇh´KYhjTubah}”(h]”h ]”h"]”h$]”h&]”uh1jRh³hÇh´KYhj3h²hubhÞ)”}”(hŒ&Or the floowing modules for nf_tables:”h]”hŒ&Or the floowing modules for nf_tables:”…””}”(hjœh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K\hj3h²hubjS)”}”(hŒ- NFT_SOCKET - NFT_TPROXY ”h]”jY)”}”(hhh]”(j^)”}”(hŒ NFT_SOCKET”h]”hÞ)”}”(hj³h]”hŒ NFT_SOCKET”…””}”(hjµh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K^hj±ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hj®ubj^)”}”(hŒ NFT_TPROXY ”h]”hÞ)”}”(hŒ NFT_TPROXY”h]”hŒ NFT_TPROXY”…””}”(hjÌh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´K_hjÈubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hj®ubeh}”(h]”h ]”h"]”h$]”h&]”j”j•uh1jXh³hÇh´K^hjªubah}”(h]”h ]”h"]”h$]”h&]”uh1jRh³hÇh´K^hj3h²hubeh}”(h]”Œ!iptables-and-nf-tables-extensions”ah ]”h"]”Œ$3. iptables and nf_tables extensions”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´KUubhÉ)”}”(hhh]”(hÎ)”}”(hŒ4. Application support”h]”hŒ4. Application support”…””}”(hj÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhjôh²hh³hÇh´KbubhÉ)”}”(hhh]”(hÎ)”}”(hŒ 4.1. Squid”h]”hŒ 4.1. Squid”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhjh²hh³hÇh´KeubhÞ)”}”(hŒÄSquid 3.HEAD has support built-in. To use it, pass '--enable-linux-netfilter' to configure and set the 'tproxy' option on the HTTP listener you redirect traffic to with the TPROXY iptables target.”h]”hŒÌSquid 3.HEAD has support built-in. To use it, pass ‘--enable-linux-netfilter’ to configure and set the ‘tproxy’ option on the HTTP listener you redirect traffic to with the TPROXY iptables target.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Kghjh²hubhÞ)”}”(hŒvFor more information please consult the following page on the Squid wiki: http://wiki.squid-cache.org/Features/Tproxy4”h]”(hŒJFor more information please consult the following page on the Squid wiki: ”…””}”(hj$h²hh³Nh´Nubj‡)”}”(hŒ,http://wiki.squid-cache.org/Features/Tproxy4”h]”hŒ,http://wiki.squid-cache.org/Features/Tproxy4”…””}”(hj,h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”j.uh1j†hj$ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÝh³hÇh´Klhjh²hubeh}”(h]”Œsquid”ah ]”h"]”Œ 4.1. squid”ah$]”h&]”uh1hÈhjôh²hh³hÇh´Keubeh}”(h]”Œapplication-support”ah ]”h"]”Œ4. application support”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´Kbubeh}”(h]”Œtransparent-proxy-support”ah ]”h"]”Œtransparent proxy support”ah$]”h&]”uh1hÈhhh²hh³hÇh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÇuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(hÍNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”j|Œerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÇŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jVjSj¢jŸj0j-jñjîjNjKjFjCuŒ nametypes”}”(jV‰j¢‰j0‰jñ‰jN‰jF‰uh}”(jShÊjŸhûj-j¥jîj3jKjôjCjuŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.