?? squid+iptables的透明代理配置.htm
字號(hào):
<TD bgColor=#000000 colSpan=2 height=1><IMG height=1
src="Squid+iptables的透明代理配置.files/help.html" width=1></TD></TR></TBODY></TABLE><!--------->
<TABLE cellSpacing=0 cellPadding=10 width="95%" align=center border=0>
<TBODY>
<TR>
<TD class=bodyline>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><SPAN class=gensmall>您好,耶寇,歡迎進(jìn)入ChinaUnix論壇<BR><A
href="http://www.chinaunix.net/forum/blog.php" target=_blank><FONT
color=#ff0000>我的博客</FONT></A> | <A
href="http://bbs.chinaunix.net/forum/favorites.php">收藏夾</A> | <A
href="http://www.chinaunix.net/cgi-bin/forum/myarticle.cgi?u=150993"
target=_blank>個(gè)人專集</A> <BR><A
href="http://bbs.chinaunix.net/forum/profile.php?mode=editprofile&sid=91d6aea3a7dd35826746d693d82b3177">個(gè)人資料</A>
| <A
href="http://bbs.chinaunix.net/forum/privmsg.php?folder=91d6aea3a7dd35826746d693d82b3177">您沒有新的站內(nèi)信件</A>
| <A
href="http://bbs.chinaunix.net/forum/login.php?logout=true&sid=91d6aea3a7dd35826746d693d82b3177">注銷登錄</A></SPAN></TD>
<TD><!--廣告位置--><A href="http://blog.chinaunix.net/"
target=_blank><IMG height=60
alt=ChinaUnix博客,全新改版、速度更快、內(nèi)容更豐富,快快去更新您的博客!
src="Squid+iptables的透明代理配置.files/blogtitle.gif" width=242
border=0></A> </TD>
<FORM action=http://www.chinaunix.net/cgi-bin/forum/search.cgi
method=get>
<TD align=right>
<TABLE border=0>
<TBODY>
<TR>
<TD noWrap align=middle><SPAN class=mainmenu><IMG height=13
alt=搜索 hspace=3
src="Squid+iptables的透明代理配置.files/icon_mini_search.gif"
width=12 border=0> <INPUT maxLength=25 size=15 name=key> <INPUT type=submit value=" GO "> <SPAN class=mainmenu><A
href="http://www.chinaunix.net/search.html">高級(jí)搜索</A></SPAN></INPUT>
</SPAN></TD></TR>
<TR>
<TD noWrap></TD></TR></TBODY></TABLE><SPAN class=mainmenu><!--廣告處---></SPAN></TD></TR></FORM></TBODY></TABLE>
<TABLE cellSpacing=2 cellPadding=2 width="100%" align=center border=0>
<TBODY>
<TR>
<TD vAlign=bottom align=left colSpan=2><A class=maintitle
href="http://bbs.chinaunix.net/forum/viewtopic.php?t=107156&show_type=&start=0&postdays=0&postorder=asc&highlight=">Squid+iptables的透明代理配置
</A>[原創(chuàng)精華]<BR><BR><SPAN class=gensmall><B>前往頁面 <B>1</B>, <A
href="http://bbs.chinaunix.net/forum/viewtopic.php?t=107156&show_type=&postdays=0&postorder=asc&start=10">2</A>,
<A
href="http://bbs.chinaunix.net/forum/viewtopic.php?t=107156&show_type=&postdays=0&postorder=asc&start=20">3</A> <A
href="http://bbs.chinaunix.net/forum/viewtopic.php?t=107156&show_type=&postdays=0&postorder=asc&start=10">下一頁</A>
</B></SPAN><BR><!--廣告---------></TD>
<TD align=right><SPAN class=gensmall><!--廣告---------></SPAN></TD></TR>
<TR>
<TD><!--廣告語 --></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=2 cellPadding=2 width="100%" align=center border=0>
<TBODY>
<TR>
<TD vAlign=bottom noWrap align=left width="10%"><SPAN class=nav><A
href="http://bbs.chinaunix.net/forum/posting.php?show_type=&mode=newtopic&f=38"><IMG
alt=發(fā)表新帖 src="Squid+iptables的透明代理配置.files/post.gif" align=middle
border=0></A> <A
href="http://bbs.chinaunix.net/forum/posting.php?show_type=&mode=reply&t=107156"><IMG
alt=回復(fù)帖子 src="Squid+iptables的透明代理配置.files/reply.gif" align=middle
border=0></A></SPAN></TD>
<TD vAlign=center align=left width=*><SPAN
class=nav> <A class=nav
href="http://www.chinaunix.net/">首頁</A> -> <A class=nav
href="http://bbs.chinaunix.net/forum">論壇首頁</A> -> <A class=nav
href="http://bbs.chinaunix.net/forum/viewforum.php?f=38">Proxy服務(wù)器</A></SPAN></TD>
<TD align=right><A class=nav
href="http://bbs.chinaunix.net/forum/favorites.php?t=107156&mode=add"
target=_blank><IMG alt=將本帖添加到我的收藏夾
src="Squid+iptables的透明代理配置.files/fav_add.gif" border=0>添加到我的收藏夾</A>
<A class=nav
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(vivi=window.open('http://vivi.sina.com.cn/collect/icollect.php?pid=19&title='+escape(d.title)+'&url='+escape(d.location.href)+'&desc='+escape(t),'vivi','scrollbars=no,width=480,height=480,left=75,top=20,status=no,resizable=yes'));vivi.focus();">[收藏此頁到新浪ViVi]</A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><!--<iframe src=http://www.chinaunix.net/other/frame_announce.html width="95%" height=15 frameborder=0 border=0 marginwidth=0 marginheight=0 scrolling=no> </iframe>-->
<TABLE class=forumline style="WORD-BREAK: break-all; BORDER-COLLAPSE: collapse"
cellSpacing=1 cellPadding=3 width="95%" align=center border=0>
<TBODY>
<TR align=right>
<TD class=catHead colSpan=2 height=28><SPAN class=nav><A class=nav
href="http://bbs.chinaunix.net/forum/viewtopic.php?t=107156&show_type=&view=previous">閱讀上一個(gè)主題</A>
:: <A class=nav
href="http://bbs.chinaunix.net/forum/viewtopic.php?t=107156&show_type=&view=next">閱讀下一個(gè)主題</A>
</SPAN></TD></TR>
<TR>
<TH class=thLeft noWrap width=150 height=26>作者</TH>
<TH class=thRight noWrap>留言</TH></TR>
<TR>
<TD class=row1 vAlign=top align=left width=150><SPAN class=name><A
name=699139></A><IMG alt=此人為版主
src="Squid+iptables的透明代理配置.files/teammo.gif" width=16>
<B>firer2000 </B> </SPAN><BR><SPAN
class=postdetails>版主 - 天使<BR><BR><BR><IMG title=天使 alt=天使 src=""
border=0><BR>注冊(cè)時(shí)間: 2002-09-02<BR>最后登錄: 2005-08-27<BR>帖子總數(shù): <A
href="http://www.chinaunix.net/cgi-bin/forum/search.cgi?mode=all_author&key=firer2000&u=18029"
target=_blank>1330</A><BR>精華帖子: <A
href="http://www.chinaunix.net/cgi-bin/forum/search.cgi?forum_num=-1&mode=author_name&key=firer2000&u=18029"
target=_blank>3</A><BR>原創(chuàng)精華: <A
href="http://www.chinaunix.net/cgi-bin/forum/search.cgi?forum_num=-1&mode=author_name&key=firer2000&u=18029"
target=_blank>2</A><BR>來自: 長(zhǎng)春<BR>BLOG主頁:<A
href="http://blog.chinaunix.net/index.php?blogId=621"
target=_blank>進(jìn)入</A><BR>在線狀態(tài): ...<FONT
color=#999999>離線</FONT>...<BR></SPAN></TD>
<TD class=row1 vAlign=top width="100%" height=28>
<TABLE cellSpacing=0 cellPadding=0 width="95%" border=0>
<TBODY>
<TR>
<TD width="100%"><A
href="http://bbs.chinaunix.net//forum/viewtopic.php?show_type=&p=699139#699139"><IMG
title=帖子總數(shù) height=9 alt=帖子總數(shù)
src="Squid+iptables的透明代理配置.files/icon_minipost.gif" width=12
border=0></A><SPAN class=postdetails>發(fā)表于: 2003-07-04 15:35<SPAN
class=gen> </SPAN> 發(fā)表主題: Squid+iptables的透明代理配置
</SPAN></TD>
<TD vAlign=top noWrap align=right><A class=nav
href="http://bbs.chinaunix.net/forum/tuijian.php?pid=699139&fid=38"
target=_blank><IMG alt=推薦此帖為精華,以便版主設(shè)置
src="Squid+iptables的透明代理配置.files/tuijian.gif" border=0></A> <A
class=nav
href="http://bbs.chinaunix.net/forum/jubao.php?pid=699139&fid=38"
target=_blank><IMG alt=舉報(bào)此帖,以便版主處理
src="Squid+iptables的透明代理配置.files/jubao.gif" border=0></A> <A
href="http://bbs.chinaunix.net/forum/posting.php?show_type=&mode=quote&p=699139"><IMG
title=引用并回復(fù) alt=引用并回復(fù)
src="Squid+iptables的透明代理配置.files/icon_quote.gif" border=0></A>
</TD></TR>
<TR>
<TD colSpan=2>
<HR>
</TD></TR>
<TR>
<TD colSpan=2><SPAN class=postbody>Squid+iptables的透明代理配置
<BR>Firer2000 <BR>2003-06-27 <BR>硬件環(huán)境:兼容機(jī) 雙網(wǎng)卡
<BR>軟件環(huán)境:linux7.1+squid-2.3.STABLE4-src.tar <BR>一.squid的安裝配置
<BR>1.下載squid <BR>可以從squid主站下載:http://www.squid-cache.org
<BR>2.編譯安裝squid <BR>第一步:[root@www root]#tar xzvf
squid-2.3.STABLE4-src.tar.gz <BR>第二步:[root@www root]#cd
squid-2.3.STABLE4 <BR>第三步:[root@www squid-2.3.STABLE4]#./configure
--prefix=/usr/localsquid enable-ipf-transparent
<BR><BR>/*指定squid的安裝目錄和啟用透明代理*/ <BR>第四步:[root@www
squid-2.3.STABLE4]#make all <BR>第五步:[root@www
squid-2.3.STABLE4]#make install
<BR>以上五步執(zhí)行完畢,squid整個(gè)程序就會(huì)被安裝在/usr/local/squid目錄下.接下來再執(zhí)行以下幾步:
<BR>第六步:進(jìn)入目錄/usr/local,以root身份執(zhí)行下面的命令,創(chuàng)建cache目錄和改變整個(gè)squid目錄的所有者為
<BR><BR>nobody.nobody: <BR>[root@www squid-2.3.STABLE4]#cd
/usr/local/squid <BR>[root@www squid]# mkdir cache <BR>[root@www
squid]# cd .. <BR>[root@www local]# chown nobody.nobody -R squid
<BR>第七步:改變用戶為nobody,進(jìn)入/usr/local/squid/bin目錄,執(zhí)行./squid -z創(chuàng)建cache交換目錄
<BR>[root@www local]# su nobody <BR>[root@www local]$cd
/usr/local/squid/bin <BR>[root@www local]$./squid -z
<BR>第八步:修改squid.conf文件,確保以下配置: <BR>httpd_accel_host
virtual(記得把一句加上,我用的這個(gè)squid版本沒有這一句) <BR>httpd_accel_port 80
<BR>httpd_accel_with_proxy on <BR>httpd_accel_uses_host_header on
<BR>cache_effective_user nobody <BR>cache_effective_group nobody
<BR>http_access allow all <BR>cache_dir ufs /usr/local/squid/cache
100 16 256 <BR>... <BR>最后啟動(dòng)squid: <BR>[root@www
local]#/usr/local/squid/bin/squid <BR>查看進(jìn)程列表: <BR>[root@www
local]#px ax <BR>應(yīng)該出現(xiàn)如下幾個(gè)進(jìn)程: <BR>......... usr/local/squid
<BR>......... squid <BR>......... unlink <BR>并且系統(tǒng)中應(yīng)該有如端口被監(jiān)聽: <BR>tcp
0 0 0.0.0.0:3128 0.0.0.0:* LISTEN <BR>udp 0 0 0.0.0.0:3130 0.0.0.0:*
<BR>這些說明squid正常啟動(dòng)了. <BR>###如果squid不能正常工作,可能是域名的設(shè)置問題,需要設(shè)置域名。
<BR>讓系統(tǒng)啟動(dòng)時(shí)自動(dòng)運(yùn)行squid <BR>編輯/ect/rc.d/local文件,在末尾加上: <BR>su nobody -c
"/usr/local/squid/bin/squid"
<BR>------------------------------------------------------------------------------------------------
<BR>OK,通過以上設(shè)置我們就以就squid代理上網(wǎng)了.
<BR>可以在ie瀏覽器中設(shè)置使用代理服務(wù)器,添入192.168.0.101:3128就可以上網(wǎng)了.
<BR>但這一步還沒有實(shí)現(xiàn)透明代理,接下來我們開始設(shè)置iptables <BR><BR>二.設(shè)置iptables <BR>1、
首先使用linuxconf工具將enable routing 項(xiàng)打開。在configure linuxconf modules
里選擇firewall的項(xiàng)。 <BR>2、 #setup <BR>進(jìn)入services 去掉ipchains。
<BR>3、在/etc/rc.d/目錄下用touch命令建立firewall文件,執(zhí)行chmod u+x
firewall以改變文件屬性,編輯
<BR><BR>/etc/rc.d/rc.local文件,在末尾加上/etc/rc.d/firewall以確保開機(jī)時(shí)能自動(dòng)運(yùn)行該腳本.
<BR>firewall內(nèi)容為: <BR>modprobe ip_tables <BR>modprobe ip_nat_ftp
<BR>modprobe ip_conntrack <BR>modprobe ip_conntrack_ftp <BR>echo
1>/proc/sys/net/ipv4/ip_forward <BR>iptables -t nat -A PREROUTING
-i eht1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
<BR>iptables -t nat -A POSTROUTING -s 172.16.0.0/23 -o eth0 -j SNAT
--to 211.141.67.10
<BR>##############################################################################
<BR>下面是原文給出的firewall腳本,共參考 <BR>#!/bin/sh <BR>echo "Enable IP
Forwarding..." <BR>echo "1">/proc/sys/net/ipv4/ip_forward
<BR>echo "Starting iptables rules..." <BR>/sbin/modprobe
iptable_filter <BR>/sbin/modprobe ip_tables <BR>/sbin/modprobe
iptable_nat <BR>#Refresh all chains <BR>/sbin/iptables -F -t nat
<BR>iptables -P INPUT DROP <BR>iptables -P FORWARD DROP <BR>iptables
-t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT
--to-ports 3128 <BR>iptables -t nat -A POSTROUTING -s 192.168.0.0/24
-o eth0 -j SNAT --to a.b.c.d <BR>iptables -A FORWARD -m state
--state ESTABLISHED,RELATED -j ACCEPT
<BR>#######################################################################################
<BR>其中,eth1是內(nèi)部網(wǎng)卡,eth0是外部網(wǎng)卡。 <BR>內(nèi)網(wǎng)ip地址為172.16.0.0/23
<BR>eth0對(duì)應(yīng)的ip地址為:211.141.67.10 <BR>結(jié)束. <BR>然后設(shè)置網(wǎng)關(guān)和dns后就可上網(wǎng)了.
<BR>如需要還可以添加一些防火墻以增強(qiáng)安全性,具體參考本站: <BR><A
href="http://www.linuxaid.com.cn/engineer/bye2000/doc/iptables1.htm"
target=_blank>http://www.linuxaid.com.cn/engineer/bye2000/doc/iptables1.htm</A>
<BR><A
href="http://www.linuxaid.com.cn/engineer/bye2000/doc/iptables2.htm"
target=_blank>http://www.linuxaid.com.cn/engineer/bye2000/doc/iptables2.htm</A>
<BR>三:設(shè)置squid支持用戶認(rèn)證: <BR>說明:透明代理和用戶認(rèn)證功能不能同時(shí)應(yīng)用。否則用戶認(rèn)證功能不起作用。
<BR>假定squid source目錄在/tmp/ squid-2.3.STABLE4 <BR>2. # cd /tmp/
squid-2.3.STABLE4/auth_modules/NCSA <BR># make ncsa_auth <BR><BR>3.
拷貝生成的執(zhí)行文件ncsa_auth到squid執(zhí)行文件目錄 <BR># cp ncsa_auth
/usr/local/squid/bin <BR><BR>4. 從Apache軟件包中得到程序htpasswd
<BR>假設(shè)apache軟件安裝在/var/www目錄下 <BR>#cd /usr/www/bin
<BR>5.用htpasswd生成供Squid利用的用戶名和密碼認(rèn)證數(shù)據(jù)庫文件
<BR>生成的密碼文件放在/usr/local/squid/etc 下。 <BR>[root@mail bin]# ./htpasswd
-c /usr/local/squid/etc/passwd test <BR>New password: <BR>Re-type
new password: <BR>Adding password for user test
<BR>這時(shí)在/usr/local/squid下就生成了passwd文件,并且加入了用戶test。 <BR>6. 加其它更多的用戶
<BR>#htpasswd /usr/loal/squid/etc/passwd newuser <BR><BR>7.
修改squid.conf,enable ncsa_auth用戶認(rèn)證功能 <BR><BR>[root@linux etc]# more
squid.conf | grep ncsa_auth <BR>authenticate_program
/usr/local/squid/bin/ncsa_auth /usr/local/squid/etc/passwd
<BR><BR>8.修改ACL部分,象下面這樣: <BR>定義相關(guān)的用戶類 <BR>acl auth_user proxy_auth
REQUIRED <BR>注意,REQUIRED關(guān)鍵字指明了接收所有合法用戶的訪問。 <BR>7.設(shè)置http_access
<BR>http_access allow auth_user
<BR>注意,如果你在改行中指定了多個(gè)允許訪問的用戶類的話,應(yīng)該把要認(rèn)證的用戶類放在第一個(gè)。如下所示:
<BR>錯(cuò)誤的配置:http_access allow auth_user all manager
<BR>正確的配置:http_access allow auth_user manager all</SPAN><SPAN
class=postbody><BR><BR></SPAN><SPAN
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -