€•?Œ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Œ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:”…””}”(hhø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:”…””}”(hjhž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”…””}”hj$sbah}”(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:”…””}”(hj2hž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”…””}”hj@sbah}”(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:”…””}”(hjNhž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));”…””}”hj\sbah}”(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: ”…””}”(hjjhž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”…””}”(hjthžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”jvuh1jrhjjubeh}”(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žhubhÊ)”}”(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ÚhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸ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 Nubjs)”}”(hŒ-https://git.breakpoint.cc/cgit/fw/tcprdr.git/”h]”hŒ-https://git.breakpoint.cc/cgit/fw/tcprdr.git/”…””}”(hjþhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”juh1jrhjö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”…””}”(hj"hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¹hjhž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:”…””}”(hj0hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KWhjhž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Ê)”}”(hjMh]”hŒNETFILTER_XT_MATCH_SOCKET”…””}”(hjOhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KYhjKubah}”(h]”h ]”h"]”h$]”h&]”uh1jIhjFubjJ)”}”(hŒNETFILTER_XT_TARGET_TPROXY ”h]”hÊ)”}”(hŒNETFILTER_XT_TARGET_TPROXY”h]”hŒNETFILTER_XT_TARGET_TPROXY”…””}”(hjfhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h KZhjbubah}”(h]”h ]”h"]”h$]”h&]”uh1jIhjFubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1jDhŸh³h KYhj@ubah}”(h]”h ]”h"]”h$]”h&]”uh1j>hŸh³h KYhjhž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\hjhžhubj?)”}”(hŒ- NFT_SOCKET - NFT_TPROXY ”h]”jE)”}”(hhh]”(jJ)”}”(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^hjubah}”(h]”h ]”h"]”h$]”h&]”uh1jIhjšubjJ)”}”(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&]”uh1jIhjšubeh}”(h]”h ]”h"]”h$]”h&]”j€juh1jDhŸh³h K^hj–ubah}”(h]”h ]”h"]”h$]”h&]”uh1j>hŸh³h K^hjhž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”…””}”(hjôhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¹hjñhž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 Kghjñhž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: ”…””}”(hjhžhhŸNh Nubjs)”}”(hŒ,http://wiki.squid-cache.org/Features/Tproxy4”h]”hŒ,http://wiki.squid-cache.org/Features/Tproxy4”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”juh1jrhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Klhjñhž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”jhŒ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”}”(jBj?jŽj‹jjjÝjÚj:j7j2j/uŒ nametypes”}”(jB‰jމj‰j݉j:‰j2‰uh}”(j?h¶j‹hçjj‘jÚjj7jàj/jñuŒ 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.