首 页 教育新闻课件中心论文中心教学教案试题中心语文专题综合下载技术教程公务员  
设为首页
加入收藏
联系我们
您当前的位置:中国教育资源网 -> 技术教程 -> 网络相关 -> 服务器 -> 代理服务器 -> 技术内容 退出登录 用户管理

Squid+iptables的透明代理配置代理服务器教程

论文作者:佚名  论文来源:不详  论文发布时间:2006-6-19 18:14:36  论文发布人:chjchjchj

减小字体 增大字体

              摘要:Squid+iptables的透明代理配置
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_accel_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我也慢慢看着呢  :)
<
[] [返回上一页] [打 印] [收 藏]  
 ∷相关技术评论  (评论内容只代表网友观点,与本站立场无关!) [查看发表评论...]
 
 中国教育资源网免费技术教程下载中心-站内广告 站内广告 中国教育资源网免费技术教程下载中心-站内广告 
 中国教育资源网站内搜索 站内搜索 中国教育资源网站内搜索 
 

   
 中国教育资源网免费技术教程下载中心-栏目导航 栏目导航 中国教育资源网免费技术教程下载中心-栏目导航 
· Windows 9XMEXP · Windows NT20002003
· LinuxBSD · 系统综合
· IISApache · 硬件技术
· Web服务器 · FTP服务器
· 邮件服务器 · 域名服务器
· Windows服务器 · 代理服务器
· 服务器综合
 
中国教育资源网免费技术教程下载中心-相关教程  相关技术 中国教育资源网免费技术教程下载中心-相关教程
· squid 配置详解+认
· Squid+MRTG实现缓存
· 关于squid和mysql的
· netfilter和squid配
· 这样的squid代理配置
· squid可以做socks代
· Squid - A quick st
· squid开多端口代理的
· 回复-置顶: linux+s
· 企业解决方案实践sq
 中国教育资源网免费技术教程下载中心-本月热门教程 本月热门 中国教育资源网免费技术教程下载中心-本月热门教程 
 
 中国教育资源网免费技术教程下载中心-本日热门论文 本日热门 中国教育资源网免费技术教程下载中心-本日热门论文 
 
关于本站 - 网站帮助 - 免费课件 - 美容 - 绿色软件 - 软件下载 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 网站留言
浙ICP备06010405号 Email:cnkjz@163.com 技术支持:名流设计
版权所有 Copyright© 2002-2004 名流