⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 squid+iptables的透明代理配置.htm

📁 Squid入门资料
💻 HTM
📖 第 1 页 / 共 5 页
字号:
    <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>您好,耶寇,欢迎进入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>个人专集</A> <BR><A 
            href="http://bbs.chinaunix.net/forum/profile.php?mode=editprofile&amp;sid=91d6aea3a7dd35826746d693d82b3177">个人资料</A> 
            | <A 
            href="http://bbs.chinaunix.net/forum/privmsg.php?folder=91d6aea3a7dd35826746d693d82b3177">您没有新的站内信件</A> 
            | <A 
            href="http://bbs.chinaunix.net/forum/login.php?logout=true&amp;sid=91d6aea3a7dd35826746d693d82b3177">注销登录</A></SPAN></TD>
          <TD><!--广告位置--><A href="http://blog.chinaunix.net/" 
            target=_blank><IMG height=60 
            alt=ChinaUnix博客,全新改版、速度更快、内容更丰富,快快去更新您的博客! 
            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">高级搜索</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&amp;show_type=&amp;start=0&amp;postdays=0&amp;postorder=asc&amp;highlight=">Squid+iptables的透明代理配置 
            </A>[原创精华]<BR><BR><SPAN class=gensmall><B>前往页面 <B>1</B>, <A 
            href="http://bbs.chinaunix.net/forum/viewtopic.php?t=107156&amp;show_type=&amp;postdays=0&amp;postorder=asc&amp;start=10">2</A>, 
            <A 
            href="http://bbs.chinaunix.net/forum/viewtopic.php?t=107156&amp;show_type=&amp;postdays=0&amp;postorder=asc&amp;start=20">3</A>&nbsp;&nbsp;&nbsp;<A 
            href="http://bbs.chinaunix.net/forum/viewtopic.php?t=107156&amp;show_type=&amp;postdays=0&amp;postorder=asc&amp;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=&amp;mode=newtopic&amp;f=38"><IMG 
            alt=发表新帖 src="Squid+iptables的透明代理配置.files/post.gif" align=middle 
            border=0></A>&nbsp;&nbsp;&nbsp;<A 
            href="http://bbs.chinaunix.net/forum/posting.php?show_type=&amp;mode=reply&amp;t=107156"><IMG 
            alt=回复帖子 src="Squid+iptables的透明代理配置.files/reply.gif" align=middle 
            border=0></A></SPAN></TD>
          <TD vAlign=center align=left width=*><SPAN 
            class=nav>&nbsp;&nbsp;&nbsp;<A class=nav 
            href="http://www.chinaunix.net/">首页</A> -&gt; <A class=nav 
            href="http://bbs.chinaunix.net/forum">论坛首页</A> -&gt; <A class=nav 
            href="http://bbs.chinaunix.net/forum/viewforum.php?f=38">Proxy服务器</A></SPAN></TD>
          <TD align=right><A class=nav 
            href="http://bbs.chinaunix.net/forum/favorites.php?t=107156&amp;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&amp;title='+escape(d.title)+'&amp;url='+escape(d.location.href)+'&amp;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&amp;show_type=&amp;view=previous">阅读上一个主题</A> 
      :: <A class=nav 
      href="http://bbs.chinaunix.net/forum/viewtopic.php?t=107156&amp;show_type=&amp;view=next">阅读下一个主题</A> 
      &nbsp;</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&nbsp;&nbsp; </B>&nbsp;&nbsp; </SPAN><BR><SPAN 
      class=postdetails>版主 - 天使<BR><BR><BR><IMG title=天使 alt=天使 src="" 
      border=0><BR>注册时间: 2002-09-02<BR>最后登录: 2005-08-27<BR>帖子总数: <A 
      href="http://www.chinaunix.net/cgi-bin/forum/search.cgi?mode=all_author&amp;key=firer2000&amp;u=18029" 
      target=_blank>1330</A><BR>精华帖子: <A 
      href="http://www.chinaunix.net/cgi-bin/forum/search.cgi?forum_num=-1&amp;mode=author_name&amp;key=firer2000&amp;u=18029" 
      target=_blank>3</A><BR>原创精华: <A 
      href="http://www.chinaunix.net/cgi-bin/forum/search.cgi?forum_num=-1&amp;mode=author_name&amp;key=firer2000&amp;u=18029" 
      target=_blank>2</A><BR>来自: 长春<BR>BLOG主页:<A 
      href="http://blog.chinaunix.net/index.php?blogId=621" 
      target=_blank>进入</A><BR>在线状态: ...<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=&amp;p=699139#699139"><IMG 
            title=帖子总数 height=9 alt=帖子总数 
            src="Squid+iptables的透明代理配置.files/icon_minipost.gif" width=12 
            border=0></A><SPAN class=postdetails>发表于: 2003-07-04 15:35<SPAN 
            class=gen>&nbsp;</SPAN>&nbsp; &nbsp;发表主题: Squid+iptables的透明代理配置 
            </SPAN></TD>
          <TD vAlign=top noWrap align=right><A class=nav 
            href="http://bbs.chinaunix.net/forum/tuijian.php?pid=699139&amp;fid=38" 
            target=_blank><IMG alt=推荐此帖为精华,以便版主设置 
            src="Squid+iptables的透明代理配置.files/tuijian.gif" border=0></A> <A 
            class=nav 
            href="http://bbs.chinaunix.net/forum/jubao.php?pid=699139&amp;fid=38" 
            target=_blank><IMG alt=举报此帖,以便版主处理 
            src="Squid+iptables的透明代理配置.files/jubao.gif" border=0></A> <A 
            href="http://bbs.chinaunix.net/forum/posting.php?show_type=&amp;mode=quote&amp;p=699139"><IMG 
            title=引用并回复 alt=引用并回复 
            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>硬件环境:兼容机 双网卡 
            <BR>软件环境: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>以上五步执行完毕,squid整个程序就会被安装在/usr/local/squid目录下.接下来再执行以下几步: 
            <BR>第六步:进入目录/usr/local,以root身份执行下面的命令,创建cache目录和改变整个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,进入/usr/local/squid/bin目录,执行./squid -z创建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(记得把一句加上,我用的这个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>最后启动squid: <BR>[root@www 
            local]#/usr/local/squid/bin/squid <BR>查看进程列表: <BR>[root@www 
            local]#px ax <BR>应该出现如下几个进程: <BR>......... usr/local/squid 
            <BR>......... squid <BR>......... unlink <BR>并且系统中应该有如端口被监听: <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正常启动了. <BR>###如果squid不能正常工作,可能是域名的设置问题,需要设置域名。 
            <BR>让系统启动时自动运行squid <BR>编辑/ect/rc.d/local文件,在末尾加上: <BR>su nobody -c 
            "/usr/local/squid/bin/squid" 
            <BR>------------------------------------------------------------------------------------------------ 
            <BR>OK,通过以上设置我们就以就squid代理上网了. 
            <BR>可以在ie浏览器中设置使用代理服务器,添入192.168.0.101:3128就可以上网了. 
            <BR>但这一步还没有实现透明代理,接下来我们开始设置iptables <BR><BR>二.设置iptables <BR>1、 
            首先使用linuxconf工具将enable routing 项打开。在configure linuxconf modules 
            里选择firewall的项。 <BR>2、 #setup <BR>进入services 去掉ipchains。 
            <BR>3、在/etc/rc.d/目录下用touch命令建立firewall文件,执行chmod u+x 
            firewall以改变文件属性,编辑 
            <BR><BR>/etc/rc.d/rc.local文件,在末尾加上/etc/rc.d/firewall以确保开机时能自动运行该脚本. 
            <BR>firewall内容为: <BR>modprobe ip_tables <BR>modprobe ip_nat_ftp 
            <BR>modprobe ip_conntrack <BR>modprobe ip_conntrack_ftp <BR>echo 
            1&gt;/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"&gt;/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是内部网卡,eth0是外部网卡。 <BR>内网ip地址为172.16.0.0/23 
            <BR>eth0对应的ip地址为:211.141.67.10 <BR>结束. <BR>然后设置网关和dns后就可上网了. 
            <BR>如需要还可以添加一些防火墙以增强安全性,具体参考本站: <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>三:设置squid支持用户认证: <BR>说明:透明代理和用户认证功能不能同时应用。否则用户认证功能不起作用。 
            <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. 
            拷贝生成的执行文件ncsa_auth到squid执行文件目录 <BR># cp ncsa_auth 
            /usr/local/squid/bin <BR><BR>4. 从Apache软件包中得到程序htpasswd 
            <BR>假设apache软件安装在/var/www目录下 <BR>#cd /usr/www/bin 
            <BR>5.用htpasswd生成供Squid利用的用户名和密码认证数据库文件 
            <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>这时在/usr/local/squid下就生成了passwd文件,并且加入了用户test。 <BR>6. 加其它更多的用户 
            <BR>#htpasswd /usr/loal/squid/etc/passwd newuser <BR><BR>7. 
            修改squid.conf,enable ncsa_auth用户认证功能 <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>定义相关的用户类 <BR>acl auth_user proxy_auth 
            REQUIRED <BR>注意,REQUIRED关键字指明了接收所有合法用户的访问。 <BR>7.设置http_access 
            <BR>http_access allow auth_user 
            <BR>注意,如果你在改行中指定了多个允许访问的用户类的话,应该把要认证的用户类放在第一个。如下所示: 
            <BR>错误的配置:http_access allow auth_user all manager 
            <BR>正确的配置:http_access allow auth_user manager all</SPAN><SPAN 
            class=postbody><BR><BR></SPAN><SPAN 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -