硬件环境:兼容机 双网卡
软件环境:kernel 2.4.7 squid-2.4.STABLE7
一.squid的安装配置
1.
下载squid
可以从squid主站下载:
http://www.squid-cache.org
2.编译安装squid
第一步:[root@www root]#tar xzvf squid-2.4STABLE7.tar.gz
第二步:[root@www root]#cd squid-2.4.STABLE7
第三步:[root@www squid-2.4.STABLE7]#./configure --prefix=/usr/localsquid enable-ipf-transparent
/*指定squid的安装目录和启用透明
代理*/
第四步:[root@www squid-2.4.STABLE7]#make all
第五步:[root@www squid-2.4.STABLE7]#make install
以上五步执行完毕,squid整个
程序就会被安装在/usr/local/squid目录下.接下来再执行以下几步:
第六步:进入目录/usr/local,以root身份执行下面的
命令,创建cache目录和改变整个squid目录的所有者为
nobody.nobody:
[root@www squid-2.4.STABLE7]#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
编辑/ect/rc.d/local文件,在末尾加上:
su nobody -c "/usr/local/squid/bin/squid"
------------------------------------------------------------------------------------------------
OK,通过以上
设置我们就以就squid代理上网了.
可以在ie
浏览器中设置使用代理
服务器,添入192.168.0.101:3128就可以上网了.
但这一步还没有实现透明代理,接下来我们开始设置iptables
二.设置iptables
在/etc/rc.d/目录下用touch命令建立firewall文件,执行chmod u+x firewall以改变文件属性,编辑
/etc/rc.d/rc.local文件,在末尾加上/etc/rc.d/firewall以确保开机时能自动运行该脚本.
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是外部网卡。
结束.
然后设置网关和dns后就可上网了.
如需要还可以添加一些
防火墙以增强安全性,具体参考本站:
http://www.linuxaid.com.cn/engineer/bye2000/doc/iptables1.htm
http://www.linuxaid.com.cn/engineer/bye2000/doc/iptables2.htm