<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>〈tproxy〉彙整頁面 - MIS 的流水年華</title>
	<atom:link href="https://jameschien.mooo.com/wordpress/tag/tproxy/feed/" rel="self" type="application/rss+xml" />
	<link>https://jameschien.mooo.com/wordpress/tag/tproxy/</link>
	<description>流水記事</description>
	<lastBuildDate>Fri, 28 Jun 2013 01:47:12 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>
	<item>
		<title>使用Squid 3.2 建立Fully Transparent Proxy（TPROXY4.1+）</title>
		<link>https://jameschien.mooo.com/wordpress/2013/06/07/%e4%bd%bf%e7%94%a8squid-3-2-%e5%bb%ba%e7%ab%8bfully-transparent-proxy%ef%bc%88tproxy4-1%ef%bc%89/</link>
					<comments>https://jameschien.mooo.com/wordpress/2013/06/07/%e4%bd%bf%e7%94%a8squid-3-2-%e5%bb%ba%e7%ab%8bfully-transparent-proxy%ef%bc%88tproxy4-1%ef%bc%89/#respond</comments>
		
		<dc:creator><![CDATA[James]]></dc:creator>
		<pubDate>Fri, 07 Jun 2013 07:14:01 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bridge]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[squid]]></category>
		<category><![CDATA[tproxy]]></category>
		<category><![CDATA[transparent]]></category>
		<guid isPermaLink="false">http://jameschien.no-ip.biz/wordpress/?p=105</guid>

					<description><![CDATA[<p>環境中有使用NLTM驗證 + IIS7.5的應用服務並且會檢查Client端IP位址. 原來的transpar &#8230; <a href="https://jameschien.mooo.com/wordpress/2013/06/07/%e4%bd%bf%e7%94%a8squid-3-2-%e5%bb%ba%e7%ab%8bfully-transparent-proxy%ef%bc%88tproxy4-1%ef%bc%89/" class="more-link">閱讀全文 <span class="screen-reader-text">使用Squid 3.2 建立Fully Transparent Proxy（TPROXY4.1+）</span></a></p>
<p>〈<a href="https://jameschien.mooo.com/wordpress/2013/06/07/%e4%bd%bf%e7%94%a8squid-3-2-%e5%bb%ba%e7%ab%8bfully-transparent-proxy%ef%bc%88tproxy4-1%ef%bc%89/">使用Squid 3.2 建立Fully Transparent Proxy（TPROXY4.1+）</a>〉這篇文章最早發佈於《<a href="https://jameschien.mooo.com/wordpress">MIS 的流水年華</a>》。</p>
]]></description>
										<content:encoded><![CDATA[<p>環境中有使用NLTM驗證 + IIS7.5的應用服務並且會檢查Client端IP位址. 原來的transparent proxy無法通過檢查, 需改成TPROXYv4.1+ (Fully Transparent Proxy), 如此一來伺服器看到Client的IP才不會是Proxy Server的IP.</p>
<p>安裝過程發現Squid 3.2.0的ntlm支援有問題, IE會不段重複跳出要求使用者輸入帳號密碼, 查了論壇發現該版本有bug, 改成3.2.7就解決了.</p>
<p>&nbsp;</p>
<p>系統：Centos 6.4</p>
<p>軟體：squid-3.2.7,bridge-utils,ebtables,libcap,libecap. Squid網路上都有包好的rpm檔,下載回來裝即可.若自行編譯核心或想自行編譯squid者請參考<a href="http://wiki.squid-cache.org/Features/Tproxy4">http://wiki.squid-cache.org/Features/Tproxy4</a>. 其他package使用yum安裝.</p>
<p>網路架構：IPv4,主機為bridge模式接在gateway後<br />
<img decoding="async" alt="" src="http://jameschien.no-ip.biz/wordpress/wp-content/uploads/2013/06/060713_0713_Squid32F1.png" /></p>
<p>軟體設定</p>
<ol>
<li>
<div>將主機設定為Bridge.記得先關閉NetworkManager以免設定衝突<br />
建立 /etc/sysconfig/network-scripts/ifcfg-br0 內容如下</div>
<p style="background: black;"><span style="color: #ffffff;">DEVICE=&#8221;br0&#8243;<br />
NM_CONTROLLED=&#8221;no&#8221;<br />
TYPE=&#8221;Bridge&#8221;<br />
BOOTPROTO=&#8221;none&#8221;<br />
IPADDR=&#8221;10.0.0.2&#8243;<br />
NETMASK=&#8221;255.255.255.0&#8243;<br />
BROADCAST=&#8221;10.0.0.255&#8243;<br />
NETWORK=&#8221;10.0.0.0&#8243;<br />
ONBOOT=&#8221;yes&#8221;<br />
GATEWAY=&#8221;10.0.0.1&#8243;<br />
DNS1=10.0.0.3<br />
DNS2=10.0.0.4<br />
DOMAIN=mydomain.com</span></p>
<div>外部網卡 /etc/sysconfig/network-scripts/ifcfg-eth0 內容如下</div>
<p style="background: black;"><span style="color: #ffffff;">DEVICE=&#8221;eth0&#8243;<br />
NM_CONTROLLED=&#8221;no&#8221;<br />
ONBOOT=&#8221;yes&#8221;<br />
TYPE=&#8221;Ethernet&#8221;<br />
BRIDGE=&#8221;br0&#8243;<br />
</span></p>
<div>內部網卡 /etc/sysconfig/network-scripts/ifcfg-eth1 內容如下</div>
<p style="background: black;"><span style="color: #ffffff;">DEVICE=&#8221;eth1&#8243;<br />
NM_CONTROLLED=&#8221;no&#8221;<br />
ONBOOT=&#8221;yes&#8221;<br />
TYPE=&#8221;Ethernet&#8221;<br />
BRIDGE=&#8221;br0&#8243;</span></p>
<div>設定完成後重新開機或重起network服務.</div>
</li>
<li>
<div>確認 /etc/sysctl.conf的相關設定包含下面幾行</div>
<p style="background: black;"><span style="color: #ffffff;">net.ipv4.ip_forward = 1<br />
net.bridge.bridge-nf-call-ip6tables = 01<br />
net.bridge.bridge-nf-call-iptables = 01<br />
net.bridge.bridge-nf-call-arptables = 01<br />
net.ipv4.conf.default.rp_filter = 01<br />
net.ipv4.conf.all.rp_filter = 01<br />
net.ipv4.conf.eth0.rp_filter = 01<br />
net.ipv4.conf.eth1.rp_filter = 01</span></p>
<div>執行以下指令使設定生效</div>
<p style="background: black;"><span style="color: #ffffff;">[root@centos6 etc]# sysctl –p</span></p>
</li>
<li>
<div>設定iptables及ebtables規則</div>
<p>建立執行檔 /usr/local/bin/tproxy.init</p>
<p style="background: black;"><span style="color: #ffffff;">#!/bin/bash<br />
# IPv4-only<br />
# 在lo介面上建立代號為100的路由表格給iptables比對fwmark<br />
ip -f inet rule add fwmark 1 lookup 100<br />
ip -f inet route add local default dev lo table 100<br />
# 以下是不需要進入squid的例外規則, 例如本機有提供web服務<br />
iptables -t mangle -A PREROUTING -d 127.0.0.1 -p tcp &#8211;dport 80 -j ACCEPT<br />
#加入Divert規則將TCP80埠的流量重導到TCP3129<br />
iptables -t mangle -N DIVERT<br />
iptables -t mangle -A DIVERT -j MARK &#8211;set-mark 1<br />
iptables -t mangle -A DIVERT -j ACCEPT<br />
iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT<br />
iptables -t mangle -A PREROUTING -p tcp &#8211;dport 80 -j TPROXY &#8211;tproxy-mark 0x1/0x1 &#8211;on-port 3129<br />
# 將橋接模式的封包移到路由模式<br />
ebtables -t broute -A BROUTING -i eth1 -p ipv4 &#8211;ip-proto tcp &#8211;ip-dport 80 -j redirect &#8211;redirect-target DROP<br />
ebtables -t broute -A BROUTING -i eth0 -p ipv4 &#8211;ip-proto tcp &#8211;ip-sport 80 -j redirect &#8211;redirect-target DROP<br />
</span></p>
<div>賦予執行權限</div>
<p style="background: black;"><span style="color: #ffffff;">[root@centos6 bin]# chmod 755 tproxy.init</span></p>
<div>將上面檔案加入開機程序 /etc/rc.d/rc.local</div>
<p style="background: black;"><span style="color: #ffffff;">#!/bin/sh<br />
#<br />
# This script will be executed *after* all the other init scripts.<br />
# You can put your own initialization stuff in here if you don&#8217;t<br />
# want to do the full Sys V style init stuff.<br />
touch /var/lock/subsys/local<br />
/usr/local/bin/tproxy.init</span></p>
<p style="background: black;">
</li>
<li>
<div>修改squid設定檔 /etc/squid/squid.conf .確認下面2行存在</div>
<p style="background: black;"><span style="color: #ffffff;">#限定IPv4, 避免LOG有錯誤訊息<br />
http_port 0.0.0.0:3128<br />
http_port 0.0.0.0:3129 tproxy</span></p>
<div>重起squid服務.</div>
<p style="background: black;">
</li>
<li>
<div>雖然主機為橋接模式, 但為了讓Squid服務可以運作所以仍需給予伺服IP及相關路由, DNS以存取Web. 另外若使用selinux則另需以下設定：</div>
<p style="background: black;"><span style="color: #ffffff;">setsebool squid_connect_any=yes<br />
setsebool squid_use_tproxy=yes</span></p>
</li>
<li>檢查 /var/log/squid/access.log 若有client的瀏覽紀錄表示squid開始運作.</li>
</ol>
<p>〈<a href="https://jameschien.mooo.com/wordpress/2013/06/07/%e4%bd%bf%e7%94%a8squid-3-2-%e5%bb%ba%e7%ab%8bfully-transparent-proxy%ef%bc%88tproxy4-1%ef%bc%89/">使用Squid 3.2 建立Fully Transparent Proxy（TPROXY4.1+）</a>〉這篇文章最早發佈於《<a href="https://jameschien.mooo.com/wordpress">MIS 的流水年華</a>》。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://jameschien.mooo.com/wordpress/2013/06/07/%e4%bd%bf%e7%94%a8squid-3-2-%e5%bb%ba%e7%ab%8bfully-transparent-proxy%ef%bc%88tproxy4-1%ef%bc%89/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
