硬件HP DL145:Opteron×2,AMD8111/8131芯片组,1GB内存,Redhat EL Advanced Server 4 for i386。
首先根据从网上找到的资料配置:
squid和iptable的具体安装我在此不做太多说明,一般看看它们的说明即可。我公司用一台机器作为代理上网。eth0连接外部网,eth1连接内部网。下面把我的配置写下来。
iptable的配置,在/etc/rc.d/目录下用touch命令建立firewall文件,执行chmod u+x firewll以更改文件属性,编辑/etc/rc.d/rc.local文件,在末尾加上/etc/rc.d/firewall以确保开机时能自动执行该脚本。
[quote:455be0e1f8]echo "starting ip forward"
echo 1 >/proc/sys/net/ipv4/ip_forward
echo "starting iptables rules"
modprobe ip_tables
modprobe ip_nat_ftp
/sbin/iptables -F -t nat
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128 #将所有80端口的包转发到3128端口
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE #对eth0端口进行欺骗[/quote:455be0e1f8]
squid的配置:
[quote:455be0e1f8]http_port 3128
cache_mem 512 M
cache_swap_low 75
cache_swap_high 95
maximum_object_size 1024 KB
cache_dir ufs /usr/local/squid/cache 60000 16 256
cache_access_log /var/squid/logs/access.log
cache_log /dev/null
cache_store_log none
debug_options ALL,1
icp_access allow all
icp_query_time out 2000
cache_effective_user nobody
cache_effective_group nogroup
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
acl all src 0.0.0.0/0
acl our_networks src 192.168.30.0/24
http_access allow our_networks
http_access deny all
acl QUERY urlpath_regex -i cgi-bin \? \.exe$ \.zip$ \.mp3$ \.mp2$ \.rm$ \.avi$
no_cache deny QUERY
reference_age 3 days
quick_abort_min 16 KB
quick_abort_max 16 KB
quick_abort_pct 95
connect_timeout 60 seconds
read_timeout 3 minutes
request_timeout 30 seconds
client_lifetime 30 seconds
half_closed_clients off
pconn_timeout 60 seconds
ident_timeout 10 seconds
shutdown_lifetime 10 seconds
memory_pools off
memory_pools_limit 0[/quote:455be0e1f8]
其中reference_age 3 days,ident_timeout 10 seconds两行出错:
[quote:455be0e1f8]2005/03/03 15:09:34| parseConfigFile: line 3379 unrecognized: 'reference_age 3 days'
2005/03/03 15:34:57| parseConfigFile: line 1645 unrecognized: 'ident_timeout 10 seconds'[/quote:455be0e1f8]
后来就把reference_age 3 days这行删掉了。
此时透明代理可以实现,把客户端的网关设置为此代理服务器的eth1的IP就可以上网了,客户端浏览器不需要再设置代理。但是客户端DNS有问题,在客户端浏览器输入IP可以访问外网,输入域名就不行,在客户端命令行模式下执行nslookup www.chinaunix.net命令,提示
[quote:455be0e1f8]DNS request time out[/quote:455be0e1f8]
在squid.conf中加入
[quote:455be0e1f8]
acl Safe_ports port 53 # dns[/quote:455be0e1f8]
故障依旧
执行:
[quote:455be0e1f8]iptables -A FORWARD -p udp --dport 53 -j ACCEPT[/quote:455be0e1f8]故障依旧
后来我在代理服务器上面运行setup,重新配置防火墙,在自定义端口那里写了53,然后重启iptables,重新运行自己的firewall脚本问题解决,squid都没有重启,成功!也就是说只是在代理服务器上面增开了53端口。因为没有启动bind服务,用nmap扫描服务器并没有发现53端口开放。
准备测试一些acl的限制,于是在squid.conf里面增加:
[quote:455be0e1f8]acl mmxfile urlpath_regex -i \.mp3$ \.avi$
http_access deny mmxfile[/quote:455be0e1f8]
squid.conf里面本来有:
[quote:455be0e1f8]acl QUERY urlpath_regex -i cgi-bin \? \.exe$ \.zip$ \.mp3$ \.mp2$ \.rm$ \.avi$
no_cache deny QUERY[/quote:455be0e1f8]
重启squid,可是客户端仍然可以下载mp3,不过只下载了前面一部分就停了,已经下载的一部分可以播放,不知道是squid的问题还是网络的问题。
[quote:455be0e1f8][root@amd squid]# tail access.log
1109905921.282 30003 192.168.30.2 TCP_MISS/206 306468 GET http://www.joyhero.net/down/music/barn/0052.mp3 - DIRECT/202.102.246.240 audio/mpeg
1109905957.105 2134 192.168.30.2 TCP_MISS/302 664 GET http://autoupdate.windowsmedia.com/update/update.asp? - DIRECT/207.46.248.96 text/html
1109905967.471 10365 192.168.30.2 TCP_MISS/200 10689 GET http://autoupdate.windowsmedia.com/update/CHS/control.xml - DIRECT/207.46.248.96 text/xml
1109905982.264 29696 192.168.30.2 TCP_MISS/200 354348 GET http://www.joyhero.net/down/music/barn/0012.mp3 - DIRECT/202.102.246.240 audio/mpeg
1109906054.122 1155 192.168.30.2 TCP_MISS/304 202 GET http://www.joyhero.net/down/music/barn/0052.mp3 - DIRECT/202.102.246.240 -[/quote:455be0e1f8]
仔细查看squid.conf,找到限制下载没有成功的原因所在了,是因为在squid.conf里面定义的我的客户端网络为our_networks,这一行:
[quote:455be0e1f8]http_access allow our_networks[/quote:455be0e1f8]
位置在这一行前面:
[quote:455be0e1f8]http_access deny mmxfile[/quote:455be0e1f8]
所以mp3文件已经先通过了,不会再被阻止。[color=red:455be0e1f8]这也是配置squid的acl最常犯的错误,acl规则的顺序问题!!![/color:455be0e1f8]
更改acl顺序后客户端无法下载mp3,这是影音传送带显示的记录:
[quote:455be0e1f8]
2005-03-04 14:45:42.796 正在连接 dn.clubhi.com:80
2005-03-04 14:45:42.796 正在连接 61.129.67.121:80
2005-03-04 14:45:42.812 已连接
2005-03-04 14:45:42.812 GET /2005.mp3 HTTP/1.1
2005-03-04 14:45:42.812 Host: dn.clubhi.com
2005-03-04 14:45:42.812 Accept: */*
2005-03-04 14:45:42.812 User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 9icon_cool.gif
2005-03-04 14:45:42.812 Connection: Keep-Alive
2005-03-04 14:45:42.843 HTTP/1.0 403 Forbidden
2005-03-04 14:45:42.843 Server: squid/2.5.STABLE6
2005-03-04 14:45:42.843 Mime-Version: 1.0
2005-03-04 14:45:42.843 Date: Fri, 04 Mar 2005 06:45:19 GMT
2005-03-04 14:45:42.843 Content-Type: text/html
2005-03-04 14:45:42.843 Content-Length: 1144
2005-03-04 14:45:42.843 Expires: Fri, 04 Mar 2005 06:45:19 GMT
2005-03-04 14:45:42.843 X-Squid-Error: ERR_ACCESS_DENIED 0
2005-03-04 14:45:42.843 X-Cache: MISS from amd.zzzx.net.cn
2005-03-04 14:45:42.843 Connection: keep-alive
2005-03-04 14:45:42.859 等待 5 秒后重试
2005-03-04 14:45:44.812 用户暂停在 0[/quote:455be0e1f8]
[quote:455be0e1f8][root@amd squid]# tail access.log
1109918593.578 1 192.168.30.2 TCP_DENIED/403 1436 GET http://dn.clubhi.com/2005.mp3 - NONE/- text/html
1109918606.563 46 192.168.30.2 TCP_DENIED/403 1436 GET http://dn.clubhi.com/2005.mp3 - NONE/- text/html
1109918611.604 25 192.168.30.2 TCP_DENIED/403 1436 GET http://dn.clubhi.com/2005.mp3 - NONE/- text/html
1109918616.666 24 192.168.30.2 TCP_DENIED/403 1436 GET http://dn.clubhi.com/2005.mp3 - NONE/- text/html[/quote:455be0e1f8]
当我从另外不经过代理的机器下载这个mp3时,速度飞快,几MB的文件时间还没有显示出来就已经下载完了。
flying864 回复于:2005-03-06 08:59:58 | ||||||||||||||||||||||||||||||||||
有遇到过楼主一样的问题!后来解决了,想把解决过程贴出来的,被楼主抢先一步! | ||||||||||||||||||||||||||||||||||
水中风铃 回复于:2005-03-06 18:16:41 | ||||||||||||||||||||||||||||||||||
[code:1:6021ef875c]后来我在代理服务器上面运行setup,重新配置防火墙,在自定义端口那里写了53,然后重启iptables,重新运行自己的firewall脚本问题解决,squid都没有重启,成功!也就是说只是在代理服务器上面增开了53端口。[/code:1:6021ef875c]
究竟做了什么?看不懂! &:roll:运行setup?这是做什么的? 应该是在防火墙上开了53端口吧? | ||||||||||||||||||||||||||||||||||
arbor 回复于:2005-03-06 18:21:04 | ||||||||||||||||||||||||||||||||||
执行setup命令,里面有个配置防火墙的选项,可以配置允许哪些端口,其中最后有个自定义的端口,写上53(DNS),然后执行:service iptables restart ,再运行一下自己写的那个防火墙脚本/etc/rc.d/firewall,OK! | ||||||||||||||||||||||||||||||||||
arbor 回复于:2005-03-11 14:30:14 | ||||||||||||||||||||||||||||||||||
我用一台电脑作客户机作测试没有问题,现在放到网络的出口的地方问题来了,只有和eth1在同一IP段的才可以通过代理上网,其他段都不行,还经常有错误提示:
tail /var/log/message: [quote:11612c8126]Mar 11 13:16:51 amd iptables: &succeeded Mar 11 13:16:51 amd last message repeated 2 times Mar 11 13:16:51 amd kernel: ip_tables: (C) 2000-2002 Netfilter core team Mar 11 13:16:51 amd kernel: ip_conntrack version 2.1 (8191 buckets, 65528 max) - 356 bytes per conntrack Mar 11 13:16:51 amd iptables: &succeeded Mar 11 13:19:22 amd squid[4027]: Squid Parent: child process 4074 exited with status 0 Mar 11 13:19:23 amd squid[6540]: Squid Parent: child process 6542 started Mar 11 13:19:23 amd kernel: audit(1110518363.451:0): avc: &denied &{ getattr } for &pid=6542 exe=/usr/sbin/squid path=/boot dev=hda1 ino=2 scontext=root:system_r:squid_t tcontext=system_u:object_r:boot_t tclass=dir Mar 11 13:26:57 amd iptables: &succeeded Mar 11 13:26:57 amd last message repeated 2 times Mar 11 13:26:57 amd kernel: ip_tables: (C) 2000-2002 Netfilter core team Mar 11 13:26:57 amd kernel: ip_conntrack version 2.1 (8191 buckets, 65528 max) - 356 bytes per conntrack Mar 11 13:26:57 amd iptables: &succeeded Mar 11 13:30:06 amd kernel: tg3: eth0: Link is down. Mar 11 13:30:07 amd kernel: tg3: eth0: Link is up at 100 Mbps, full duplex. Mar 11 13:30:07 amd kernel: tg3: eth0: Flow control is on for TX and on for RX. Mar 11 13:30:10 amd kernel: tg3: eth0: Link is down. Mar 11 13:30:14 amd kernel: tg3: eth1: Link is down. Mar 11 13:32:38 amd (squid): xstrdup: tried to dup a NULL pointer! Mar 11 13:32:38 amd squid[6540]: Squid Parent: child process 6542 exited due to signal 6 Mar 11 13:32:41 amd squid[6540]: Squid Parent: child process 6717 started Mar 11 13:32:41 amd kernel: audit(1110519161.625:0): avc: &denied &{ getattr } for &pid=6717 exe=/usr/sbin/squid path=/boot dev=hda1 ino=2 scontext=root:system_r:squid_t tcontext=system_u:object_r:boot_t tclass=dir [/quote:11612c8126] 特别是这一行经常自己跳出来,不知道什么意思: [color=red:11612c8126]Mar 11 13:32:41 amd kernel: audit(1110519161.625:0): avc: &denied &{ getattr } for &pid=6717 exe=/usr/sbin/squid path=/boot dev=hda1 ino=2 scontext=root:system_r:squid_t tcontext=system_u:object_r:boot_t tclass=dir[/color:11612c8126] 我已经把squid.conf里面加入其他的IP段,改了网卡IP,在防火墙脚本里面增加了其他段的转发,新的防火墙脚本如下: [code:1:11612c8126]echo "starting ip forward" echo 1 >/proc/sys/net/ipv4/ip_forward echo "starting iptables rules" modprobe ip_tables modprobe ip_nat_ftp /sbin/iptables -F -t nat 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.1.0/24 -o eth0 -j SNAT --to 192.168.2.2 iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o eth0 -j SNAT --to 192.168.2.2 iptables -t nat -A POSTROUTING -s 192.168.90.0/24 -o eth0 -j SNAT --to 192.168.2.2 iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE[/code:1:11612c8126] | ||||||||||||||||||||||||||||||||||
60133056 回复于:2005-03-12 13:39:41 | ||||||||||||||||||||||||||||||||||
不错 | ||||||||||||||||||||||||||||||||||
wchun 回复于:2005-03-22 13:10:11 | ||||||||||||||||||||||||||||||||||
我通常在iptables 里面再加上一条,对53端口dns请求转发到电信的dns上去,这样客户端不用再设置其他的dns 了。直接使用网关的ip作为dns. | ||||||||||||||||||||||||||||||||||
niao5929 回复于:2005-03-22 14:50:31 | ||||||||||||||||||||||||||||||||||
好文 | ||||||||||||||||||||||||||||||||||
doubleshe 回复于:2005-03-24 13:19:30 | ||||||||||||||||||||||||||||||||||
我按照你的方法,可是出现这样的提示是因为什么啊!!!!
|
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/
领测软件测试网最新更新
关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved 北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2 技术支持和业务联系:info@testage.com.cn 电话:010-51297073 |