如何做一个TCP透明饼干中转进口代理代理

代理服务器和透明代理_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
代理服务器和透明代理
上传于||暂无简介
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩3页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢tproxy实现透明代理
Transparent proxy support
=========================
This feature adds Linux 2.2-like transparent proxy support to current kernels.To use it, enable NETFILTER_TPROXY, the socket match and the TPROXY target inyour kernel config. You will need policy routing too, so be sure to enable thatas well.
1. Making non-local sockets work
================================
The idea is that you identify packets with destination address matching a localsocket on your box, set the packet mark to a certain value, and then match on thatvalue using policy routing to have those packets delivered locally:
&&&&&&& # iptables -t mangle -N DIVERT
&&&&&&& # iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT
&&&&&&& # iptables -t mangle -A DIVERT -j MARK --set-mark 1
&&&&&&& # iptables -t mangle -A DIVERT -j ACCEPT
&&&&&&& # ip rule add fwmark 1 lookup 100
&&&&&&& # ip route add local 0.0.0.0/0 dev lo table 100
&&&&&&& Because 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:
&&&&&&& fd = socket(AF_INET, SOCK_STREAM, 0);
&&&&&&& int value = 1;
&&&&&&& setsockopt(fd, SOL_IP, IP_TRANSPARENT, &value, sizeof(value));
&&&&&&& name.sin_family = AF_INET;
&&&&&&& name.sin_port = htons(0xCAFE);
&&&&&&& name.sin_addr.s_addr = htonl(0xDEADBEEF);
&&&&&&& bind(fd, &name, sizeof(name));
&&&&&&& A trivial patch for netcat is available here:
2. Redirecting traffic
======================
&&& Transparent proxying often involves "intercepting" traffic on a router. This is usually done with the iptables REDIRECT 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 TCPgetting the original destination address is racy.)
The 'TPROXY' target provides similar functionality without relying on NAT. Simply
&&&&&&& add rules like this to the iptables ruleset above:
&&&&&&& # iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY \
&&&&&&& & --tproxy-mark 0x1/0x1 --on-port 50080
&&&&&&& Note that for this to work you'll have to modify the proxy to enable (SOL_IP,
&&&&&&& IP_TRANSPARENT) for the listening socket.
3. Iptables extensions
======================
To use tproxy you'll need to have the 'socket' and 'TPROXY' modules
compiled for iptables. A patched version of iptables is available
4. Application support
======================
4.1. Squid
----------
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.&&&&&&& For more information please consult the following page on the Squid wiki:
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。}

我要回帖

更多关于 nginx tcp透明代理 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信