ipfilter+squid配置实例
ipfilter+squid配置实例,ipfilter+squid配置实例
ipfilter+squid配置实例文档说明:给如我一样的菜鸟,本人全部测试过了全部参考peijun.jiang----使用ipfilter设置小型企业防火墙http://www.cnfug.org/journal/5/05.html葱头------freebsd 服务器设置简明攻略加上squid,以提供web cache功能,对内进行QQ,ftp,上网时间等控制,对外提供mail ,web,ftp服务,网络拓扑图 1. 主机A: 装freebsd4.9-stable,有3块网卡rl1: 218.85.158.244----接公网 ed0: 131.107.3.3/24-----为对内服务提供区域网卡(有web,mail,ftp等服务) rl0: 192.168.1.7/24-----对内提供上网2. 主机B: 对外提供www,mail服务, ip地址为:131.107.3.5/243. 主机C 对外提供ftp服务,装serv-U ip地址为:131.107.3.8/24internet | | (rl1公ip,ed0私ip,rl0私ip)C主机-----A主机:freebsd---------------- B主机 | | N台工作站 (一)安装squid,这个不用说了我的配置文件squid.confhttp_port 3128cache_mem 32 MBcache_swap_low 90cache_swap_high 95maximum_object_size 4096 KBcache_dir /usr/local/squid/cache 100 16 256cache_access_log /usr/local/squid/logs/access.logcache_log /usr/local/squid/logs/cache.logcache_store_log /usr/local/squid/logs/store.logcache_dns_program /usr/local/squid/bin/dnsserverunlinkd_program /usr/local/squid/bin/unlinkdacl all src /DownloadFiles2005september2005-09-13 .0.0.0 .0.0.0acl wwwtime time SMTWHFA 08:00-18:00 #定上网时间,只对http请求acl allow_ip_alltime src /DownloadFiles2005september2005-09-13192.168.1.1232 #定上网ip,此处ip上网不限时acl allow_ip_8time src /DownloadFiles2005september2005-09-13192.168.1.1332 192.168.1.14/32 #定上网ip,此处ip上网10小时acl manager proto cache_objectacl localhost src /DownloadFiles2005september2005-09-13127.0.0.1255.255.255.255acl SSL_ports port 443 563acl Safe_ports port 80 21 443 563 70 210 1025-65535acl CONNECT method CONNECThttp_access allow allow_ip_alltimehttp_access allow allow_ip_8time wwwtimehttp_access allow manager localhosthttp_access deny managerhttp_access deny !Safe_portshttp_access deny CONNECT !SSL_portshttp_access deny allicp_access allow allmiss_access allow allcache_effective_user nobodycache_effective_group nogroup起动squid测试squid是否正常工作如果squid能正常工作,加上下面四句,是用于透明代理加速模式的,httpd_accel_host virtualhttpd_accel_port 80httpd_accel_with_proxy onhttpd_accel_uses_host_header on(二 )squid测试成功后,装ipfilter定制内核:mykernelcd /usr/src/sys/i386/confcp GENERIC mykernel加上options IPFILTERoptions IPFILTER_LOGoptions IPFILTER_DEFAULT_BLOCK/usr/sbin/config mykernelcd ../../compile/mykernelmake depend all install重起在/etc/建立ipnat.rules文件我的规则如下,这里要说明一点,ipfilter对web请求的处理与ipfilter对QQ请求的处理是不一样的ipfilter对80端口的请求是转发到本机3128端口上的,再由squid通过3128端口向外部web发请求ipfilter对其它端口的处理则是通过NAT直接出去的ipnat.rules:rdr rl0 0.0.0.0/0 port 80 -> 192.168.1.7 port 3128 tcp/udp #对web请求转到本机3128端口,由squid来处理#注意->符号左右的要有空格,以下同map rl1 192.168.1.0/24 -> 0/32 portmap tcp/udp 10000:30000 #对其它请求的处理则用NAT出去map rl1 192.168.1.0/24 -> 0/32map rl1 131.107.3.0/24 -> 0/32 portmap tcp/udp 30001:60000 map rl1 131.107.3.0/24 -> 0/32 portmaprdr rl1 218.85.158.244/32 port 80 -> 131.107.3.5 port 80rdr rl1 218.85.158.244/32 port 25 -> 131.107.3.5 port 25rdr rl1 218.85.158.244/32 port 110 -> 131.107.3.5 port 110rdr rl1 218.85.158.244/32 port ftp -> 131.107.3.8 port ftprdr rl1 218.85.158.244/32 port 30001-50000 -> 131.107.3.8 port 30001 tcp(三)我的ipf.rules:先提醒一下,ipf对规则处理的先后顺序和ipfw不同,ipfw的规则是一旦匹配就不再进行规则处理了,而ipf将继续寻找其他匹配规则,因此通常是最后一个匹配规则生效,但是,ipf也可以用quick参数来改变这个状况,不再搜寻其他规则block in log quick all with shortblock in log quick all with ipoptsblock in log quick all with fragblock in log quick all with opt lssrblock in log quick all with opt ssrr pass out on rl0 allpass in on rl0 allpass out on ed0 allpass in on ed0 allpass out quick on lo0 allpass in quick on lo0 allblock