硬件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
11