• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • Squid+iptables的透明代理配置

    發表于:2007-05-25來源:作者:點擊數: 標簽:
    Squid+iptables的透明代理配置 Firer2000 2003-06-27 硬件環境:兼容機雙網卡 軟件環境:linux7.1+squid-2.3.STABLE4-src.tar 一.squid的安裝配置 1.下載squid 可以從squid主站下載:http://www.squid-cache.org 2.編譯安裝squid 第一步:[root@wwwroot]#tarxzv

    Squid+iptables的透明代理配置
    Firer2000
    2003-06-27
    硬件環境:兼容機 雙網卡
    軟件環境:linux7.1+squid-2.3.STABLE4-src.tar
    一.squid的安裝配置
    1.下載squid
      可以從squid主站下載:http://www.squid-cache.org
    2.編譯安裝squid
      第一步:[root@www root]#tar xzvf squid-2.3.STABLE4-src.tar.gz
      第二步:[root@www root]#cd squid-2.3.STABLE4
      第三步:[root@www squid-2.3.STABLE4]#./configure --prefix=/usr/localsquid enable-ipf-transparent 

    /*指定squid的安裝目錄和啟用透明代理*/
      第四步:[root@www squid-2.3.STABLE4]#make all
      第五步:[root@www squid-2.3.STABLE4]#make install
    以上五步執行完畢,squid整個程序就會被安裝在/usr/local/squid目錄下.接下來再執行以下幾步:
      第六步:進入目錄/usr/local,以root身份執行下面的命令,創建cache目錄和改變整個squid目錄的所有者為

    nobody.nobody:
             [root@www squid-2.3.STABLE4]#cd /usr/local/squid
             [root@www squid]# mkdir cache
             [root@www squid]# cd ..
             [root@www local]# chown nobody.nobody -R squid
      第七步:改變用戶為nobody,進入/usr/local/squid/bin目錄,執行./squid -z創建cache交換目錄
             [root@www local]# su nobody
             [root@www local]$cd /usr/local/squid/bin
             [root@www local]$./squid -z
      第八步:修改squid.conf文件,確保以下配置:
             httpd_aclearcase/" target="_blank" >ccel_host virtual(記得把一句加上,我用的這個squid版本沒有這一句)
             httpd_accel_port 80
             httpd_accel_with_proxy on
             httpd_accel_uses_host_header on
     cache_effective_user nobody
     cache_effective_group nobody
      http_access allow all
     cache_dir ufs /usr/local/squid/cache 100 16 256
             ...
      最后啟動squid:
            [root@www local]#/usr/local/squid/bin/squid
      查看進程列表: 
            [root@www local]#px ax
      應該出現如下幾個進程:
    ......... usr/local/squid
    ......... squid
    ......... unlink
     并且系統中應該有如端口被監聽:
    tcp 0 0 0.0.0.0:3128 0.0.0.0:* LISTEN
    udp 0 0 0.0.0.0:3130 0.0.0.0:*
    這些說明squid正常啟動了.
    ###如果squid不能正常工作,可能是域名的設置問題,需要設置域名。
    讓系統啟動時自動運行squid
    編輯/ect/rc.d/local文件,在末尾加上:
    su nobody -c "/usr/local/squid/bin/squid"
    ------------------------------------------------------------------------------------------------
    OK,通過以上設置我們就以就squid代理上網了.
    可以在ie瀏覽器中設置使用代理服務器,添入192.168.0.101:3128就可以上網了.
    但這一步還沒有實現透明代理,接下來我們開始設置iptables

    二.設置iptables
    1、 首先使用linuxconf工具將enable routing 項打開。在configure linuxconf modules 里選擇firewall的項。
    2、 #setup
    進入services 去掉ipchains。
    3、在/etc/rc.d/目錄下用touch命令建立firewall文件,執行chmod u+x firewall以改變文件屬性,編輯

    /etc/rc.d/rc.local文件,在末尾加上/etc/rc.d/firewall以確保開機時能自動運行該腳本.
    firewall內容為:
    modprobe ip_tables
    modprobe ip_nat_ftp
    modprobe ip_conntrack
    modprobe ip_conntrack_ftp
    echo 1>/proc/sys/net/ipv4/ip_forward
    iptables -t nat -A PREROUTING -i eht1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
    iptables -t nat -A POSTROUTING -s 172.16.0.0/23 -o eth0 -j SNAT --to 211.141.67.10
    ##############################################################################
    下面是原文給出的firewall腳本,共參考
    #!/bin/sh
    echo "Enable IP Forwarding..."
    echo "1">/proc/sys/net/ipv4/ip_forward
    echo "Starting iptables rules..."
    /sbin/modprobe iptable_filter
    /sbin/modprobe ip_tables 
    /sbin/modprobe iptable_nat
    #Refresh all chains
    /sbin/iptables -F -t nat
    iptables -P INPUT DROP
    iptables -P FORWARD DROP
    iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
    iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j SNAT --to a.b.c.d
    iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
    #######################################################################################
    其中,eth1是內部網卡,eth0是外部網卡。
    內網ip地址為172.16.0.0/23 
    eth0對應的ip地址為:211.141.67.10
    結束.
    然后設置網關和dns后就可上網了. 
    如需要還可以添加一些防火墻以增強安全性,具體參考本站:
    http://www.linuxaid.com.cn/engineer/bye2000/doc/iptables1.htm
    http://www.linuxaid.com.cn/engineer/bye2000/doc/iptables2.htm
    三:設置squid支持用戶認證:
    說明:透明代理和用戶認證功能不能同時應用。否則用戶認證功能不起作用。
    假定squid source目錄在/tmp/ squid-2.3.STABLE4
    2. # cd /tmp/ squid-2.3.STABLE4/auth_modules/NCSA
    # make ncsa_auth

    3. 拷貝生成的執行文件ncsa_auth到squid執行文件目錄
    # cp ncsa_auth /usr/local/squid/bin

    4. 從Apache軟件包中得到程序htpasswd
    假設apache軟件安裝在/var/www目錄下
    #cd /usr/www/bin
    5.用htpasswd生成供Squid利用的用戶名和密碼認證數據庫文件
    生成的密碼文件放在/usr/local/squid/etc 下。
     [root@mail bin]# ./htpasswd -c /usr/local/squid/etc/passwd test
    New password:
    Re-type new password:
    Adding password for user test
    這時在/usr/local/squid下就生成了passwd文件,并且加入了用戶test。
    6. 加其它更多的用戶
    #htpasswd /usr/loal/squid/etc/passwd newuser

    7. 修改squid.conf,enable ncsa_auth用戶認證功能

    [root@linux etc]# more squid.conf | grep ncsa_auth
    authenticate_program /usr/local/squid/bin/ncsa_auth /usr/local/squid/etc/passwd

    8.修改ACL部分,象下面這樣:
    定義相關的用戶類
    acl auth_user proxy_auth REQUIRED
    注意,REQUIRED關鍵字指明了接收所有合法用戶的訪問。
    7.設置http_access
    http_access allow auth_user
    注意,如果你在改行中指定了多個允許訪問的用戶類的話,應該把要認證的用戶類放在第一個。如下所示:
    錯誤的配置:http_access allow auth_user all manager
    正確的配置:http_access allow auth_user manager all

     firer2000 回復于:2003-07-04 15:36:02
    有問題請指出~

     段譽 回復于:2003-07-07 17:57:42
    暫時沒有,長期關注。

     workaholic 回復于:2003-07-08 09:29:51
    我也慢慢看著呢  :)

     firer2000 回復于:2003-07-09 13:42:21
    [quote:3d3211e12f="workaholic"]我也慢慢看著呢  :)[/quote:3d3211e12f]    

    呵呵,多謝關心呀!

     startdd 回復于:2003-07-11 02:28:54
    支持!

     linuxs 回復于:2003-07-14 10:50:48
    關注

     jzcjy 回復于:2003-08-26 12:35:42
    如何實現在多網段下的支持。

     firer2000 回復于:2003-08-26 16:21:08
    我采用的方法是安裝多個網卡,然后在iptables的規則里面添加相應的項目。

     windywolf 回復于:2003-08-27 11:30:30
    你說的
    7. 修改squid.conf,enable ncsa_auth用戶認證功能 
    我用過,覺得不好,因為整個內網的機子,只要知道
    用戶口令就能使用代理了
    我一直想用mac來限制機子,可是,用帶enable-acl-arp
    選項安裝squid,始終在squid.conf中沒有acl arp 條目出現
    自己加又不生效,現在只能用限ip的方法了
    不知道大家還有沒有更好的管理方法(單指squid
    不包括iptables)

     windywolf 回復于:2003-08-27 11:34:58
    firer2000   
    你的ftp網站密嗎是什么呀
    想上去看看

     firer2000 回復于:2003-08-28 10:11:03
    你用的是那個版本的squid?用2.5的試試!

     firer2000 回復于:2003-08-28 10:11:38
    我的ftp用戶名和密碼都是firer2000

     windywolf 回復于:2003-08-28 14:12:14
    我用的是squid-2.5.STABLE3.tar.gz
    這個版本應該沒有什么問題吧
    你能用acl advance arp xx.xx.xx.xx嗎???

     firer2000 回復于:2003-08-29 07:49:59
    這個我沒有試過,你看看精華貼,里面有這方面的說明,我見過

     repairer 回復于:2003-09-05 22:18:43
    請問通過以上設置,客戶機可以用qq和msn嗎?謝謝!

     antsnm 回復于:2003-09-06 19:23:22
    我作了密碼認證可是怎么就是通不過認證呢?是不是對加密進行設置?

     firer2000 回復于:2003-09-08 08:33:43
    你是說輸入用戶名和密碼后不能通過?

     lpy001 回復于:2003-09-10 08:53:23
    root@localhost squid]# cd bin
    [root@localhost bin]# ls
    RunAccel  RunCache  squidclient
    [root@localhost bin]# ./squid -z
    bash: ./squid: No such file or directory
    [root@localhost bin]# cd..
    bash: cd..: command not found
    [root@localhost bin]# cd..
    bash: cd..: command not found
    [root@localhost bin]# cd ..
    [root@localhost squid]# cd ..
    [root@localhost local]# su nobody
    This account is currently not available

      在執行./squid和su nobody時出錯;
    1.cache目錄是建在/usr/local下,是還是建在/usr/local/squid目錄下?
    2.chown nobody.nobody -R squid是什么意思?

     段譽 回復于:2003-09-11 13:06:37
    缺省情況下,squid是在/usr/sbin目錄下,至于cache目錄,和你的配置文件——squid.conf有關系,在配置文件里面定義這個目錄的位置。

     forx86 回復于:2003-10-03 09:10:29
    "下面是原文給出的firewall腳本,共參考 
    #!/bin/sh 
    echo "Enable IP Forwarding..." 
    echo "1">/proc/sys/net/ipv4/ip_forward 
    echo "Starting iptables rules..." 
    /sbin/modprobe iptable_filter 
    /sbin/modprobe ip_tables  
    /sbin/modprobe iptable_nat 
    #Refresh all chains 
    /sbin/iptables -F -t nat 
    iptables -P INPUT DROP 
    iptables -P FORWARD DROP 
    iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128 
    iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j SNAT --to a.b.c.d 
    iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT "
    上邊的iptables -P INPUT DROP 
    這樣用這個腳本能打開網頁嗎?試試這個腳本怎么打不開網頁?????
    請老大指點。

     NetDC 回復于:2003-11-12 10:22:27
    [quote:837df5860d="firer2000"]iptables -P INPUT DROP 
    iptables -P FORWARD DROP [/quote:837df5860d]

    這里我不是很明白,INPUT和FORWARD規則都DROP掉了,nat還能用嗎?雖然POSTROUTING 在INPUT之前,可是我當時做的一個nat好像不能把所有的INPUT都drop掉,要不nat就不能工作。

    討教一下,謝謝。

     paulwang 回復于:2004-05-21 10:06:11
    [code:1:0bab3e474e]
    這里我不是很明白,INPUT和FORWARD規則都DROP掉了,nat還能用嗎?雖然POSTROUTING 在INPUT之前,可是我當時做的一個nat好像不能把所有的INPUT都drop掉,要不nat就不能工作。 

    討教一下,謝謝。
    [/code:1:0bab3e474e]

    聽說, INPUT, OUTPUT,FORWARD 這三條鏈對同一個數據包, 只有其中一條有效, 既NAT不關 INPUT和OUTPUT的事,
    見別人的文章:http://www.linuxforum.net/doc/iptable-wu.html

    另外:上面的解決方案中好象同時起用了透明代理和NAT吧, 不光是透明代理吧。

    還有: 我很菜,請指教

     wingger 回復于:2005-02-03 15:51:33
    [quote:aab337cb6e="NetDC"]

    這里我不是很明白,INPUT和FORWARD規則都DROP掉了,nat還能用嗎?雖然POSTROUTING 在INPUT之前,可是我當時做的一個nat好像不能把所有的INPUT都drop掉,要不nat就不能工作。

    討教一下,謝謝。[/quote:aab337cb6e]

    -p是缺省規則,表示,不區配的包使用的規則

     wingger 回復于:2005-02-04 13:37:17
    [quote:b066cfc110]3、在/etc/rc.d/目錄下用touch命令建立firewall文件,執行chmod u+x firewall以改變文件屬性,編輯 

    /etc/rc.d/rc.local文件,在末尾加上/etc/rc.d/firewall以確保開機時能自動運行該腳本. 
    firewall內容為: 
    modprobe ip_tables 
    modprobe ip_nat_ftp 
    modprobe ip_conntrack 
    modprobe ip_conntrack_ftp 
    echo 1>/proc/sys/net/ipv4/ip_forward 
    iptables -t nat -A PREROUTING -i eht1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128 
    iptables -t nat -A POSTROUTING -s 172.16.0.0/23 -o eth0 -j SNAT --to 211.141.67.10 
    ###########################################[/quote:b066cfc110]


    [quote:b066cfc110]下面是原文給出的firewall腳本,共參考 
    #!/bin/sh 
    echo "Enable IP Forwarding..." 
    echo "1">/proc/sys/net/ipv4/ip_forward 
    echo "Starting iptables rules..." 
    /sbin/modprobe iptable_filter 
    /sbin/modprobe ip_tables 
    /sbin/modprobe iptable_nat 
    #Refresh all chains 
    /sbin/iptables -F -t nat 
    iptables -P INPUT DROP 
    iptables -P FORWARD DROP 
    iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128 
    iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j SNAT --to a.b.c.d 
    iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT 
    ###########################################[/quote:b066cfc110]


    [code:1:b066cfc110]iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT[/code:1:b066cfc110]
    有差別哦!我的MSN不通過代理就不能上線!為啥呢,要什么特別的設置嗎

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>