回复-置顶: linux+squid+iptables企业方案征集
发表于:2007-05-25来源:作者:点击数:
标签:
申明,本人脚本禁止转载,请尊重本人劳动成果: 试试: 首先本人认为01是不可能实现的,而11我又不会 SQL 和SAMBA认证只会基本认证,除此之外其余均能实现 假设子网192.168.1.0/24,某个域名为www.163.com通过PING的其IP为202.108.36.196,通过其IP限制收发该
申明,本人脚本禁止转载,请尊重本人劳动成果:
试试:
首先本人认为01 是不可能实现的,而11我又不会
SQL和SAMBA认证只会基本认证,除此之外其余均能实现
假设子网192.168.1.0/24,某个域名为www.163.com通过PING 的其IP为202.108.36.196,通过其IP限制收发该域名邮件(可在iptables中实现)
外网网卡为eth0内网网卡为eht1,为eth1绑定192.168.1.201和192.168.0.201
cp eth1 eth1:1
修改eht1:1
没有限制的用户为192.168.0.201以后的IP用MAC标志
由于AS3没有安装GCC而本身的SQUID里又没有NCSA文件,固重新安装GCC和SQUID,
tar zxvf squid-2.5.STABLE7.tar.gz
cd squid-2.5.STABLE7
./configure --prefix=/usr/local/squid
--sysconfdir=/etc/squid #配置文件位置
--enable-arp-acl #客户端的MAC地址进行管理
--enable-
linux.netfilter #允许使用
Linux的透明功能
--enable-pthreads
--enable-err-language="Simplify_Chinese"
--enable-default-err-language="Simplify_Chinese"
#上面两个选项告诉Squid编入并使用简体中文错误信息
--enable-storeio=ufs,null #可以不用缓冲
--enable-auth="basic" #认证方式
--enable-baisc-auth-helpers="NCSA" #认证程序为
--enable-underscore #允许解析的URL中出现下划线
make
make install
开始配置squid.conf
##################################################################################################
#
服务器配置
icp_port 0
cache_store_log none
cache_a
clearcase/" target="_blank" >ccess_log /dev/null
cache_log /dev/null
http_port 3128
cache_mem 128 MB
cache_dir null /tmp
pid_filename none
client_netmask 255.255.255.255
half_closed_clients on
#用户分类
auth_param basic program /usr/bin/ncsa_auth /usr/etc/passwd
auth_param basic children 5
auth_param basic re
alm Tianfuming proxy-caching server
auth_param basic credentialsttl 2 hours
acl normal proxy_auth REQUIDE #用户认证
acl advance arp 00:01:02:1f:2c:3e 00:01:02:3c:1a:8b ... #10 IP/MAC绑定用户名认证上网;
acl lana src 192.168.1.0/24
acl lanb src 192.168.0.1-192.168.0.200/32
#行为分类
acl download urlpath_regex -i \.mp3$ \.exe$ \.avi$ \.rar$ \.rvmb$ \.jpg #禁止
下载
#acl conncount maxconn 5 #最大连接数
acl worktime MTWHF 8:00-18:00 # 04、允许全体人员在固定时间,有部分限制,
#不在此时间之内,撤除限制(在http_access中限制)
acl qq dstdomain .snnu.edu.cn
acl badwords url_regex sex
acl localhost src 127.0.0.1/32
acl all src 0.0.0.0/0.0.0.0
http_access allow advance # 03 允许部分人完全没有限制;
http_access allow localhost
#http_access deny conncount normal
http_access deny !
http_access deny badwords worktime # 不允许访问特定url字符网站
http_access deny qq worktime # 06 不允许访问特定的站点
http_access allow lana # 02 允许部分人可以下载
http_access deny download worktime # 05 不允许下载的特定url字符:exe/zip等等;
http_access allowd lanb homepage #08、允许部分人员只能浏览指定网站;
http_access allow normal
http_access deny all #除这些,禁止所有
#结合透明代理 07、透明代理与用户认证共存
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
####################################################################################
iptables脚本
####################################################################################
#! /bin/sh
UPLINK="eth0"
UPIP="a.b.c.d"
LANLINK="eth1"
ROUTER="yes"
#NAT="UPIP/dynamic"
NAT="UPIP"
INTERFACES="lo eth0 eth1"
SERVICES="80 22 25 110 "
deny=""
case "$@" in
start)
echo -n "Starting firewall..."
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp
iptables -P INPUT DROP
iptables -A INPUT -i ! ${UPLINK} -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD DROP
iptables -A FORWARD -p tcp -m multiport --dport 25 80 110 -j ACCEPT
iptables -A FORWARD -d !202.108.36.196 -p tcp -m multiport --dprot 25 110 -j DROP ##09、只允许收发邮件(所有域名邮件
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT #(smtp,pop3))和只能收某域名收发某域名邮件
#iptables -P OUTPUT DROP
#enable public access to certain services
for x in ${SERVICES}
do
iptables -A INPUT -p tcp --dport ${x} -m state --state NEW -j ACCEPT
done
for y in ${deny}
do
iptables -A OUTPUT -p tcp --dport ${y} -j DROP
iptables -A OUTPUT -p udp --dport ${y} -j DROP
done
#enable system-log
#iptables -A INPUT -j LOG --log-prefix "bad input:"
iptables -A INPUT -p tcp -i ${UPLINK} -j REJECT --reject-with tcp-reset
#iptables -A INPUT -p udp -i ${UPLINK} -j REJECT --reject-with icmp-port-unreachable
#explicitly disable ECN
if [ -e /proc/sys/net/ipv4/tcp_ecn ]
then
echo 0 > /proc/sys/net/ipv4/tcp_ecn
fi
#disable spoofing on all interfaces
for x in ${INTERFACES}
do
echo 1 > /proc/sys/net/ipv4/conf/${x}/rp_filter
done
if [ "$ROUTER" = "yes" ]
then
#we're a router of some kind, enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
if [ "$NAT" = "dynamic" ]
then
#dynamic IP address, use masquerading
iptables -t nat -A POSTROUTING -o ${UPLINK} -j MASQUERADE
elif [ "$NAT" != "" ]
then
#static IP, use SNAT
iptables -t nat -A PREROUTING -i ${LANLINK} -d ! ${UPIP} -j DNAT --to-ports 3128
iptables -t nat -A POSTROUTING -o ${UPLINK} -j SNAT --to ${UPIP}
fi
fi
echo "OK!"
exit 0
;;
stop)
echo -n "Stopping firewall..."
iptables -F INPUT
iptables -P INPUT ACCEPT
iptables -F OUTPUT
iptables -P OUTPUT ACCEPT
#turn off NAT/masquerading, if any
#iptables -t nat -F POSTROUTING
echo "OK!"
exit 0
;;
restart)
$0 stop
$0 start
;;
show)
clear
echo ">-------------------------------------------------------------------"
iptables -L
echo ">-------------------------------------------------------------------"
iptables -t nat -L POSTROUTING
exit 0
;;
*)
echo "Usage: $0 {start|stop|restart|show}"
exit 1
esac
段誉 回复于:2004-12-20 01:42:36
|
多谢,并请大家测试。
PS:可能不会搞代理了,但是希望能给大家提供交流的平台。
|
chris_wan 回复于:2004-12-22 19:19:51
|
晕倒,这么好的东东竟然没有人顶...........................
楼主我帮你测试,有什么问题请教你.
我的MSN: chris_wan@hotmail.com (24小时在线)
QQ:278352648 (不是常在线)
|
chris_wan 回复于:2004-12-22 19:22:57
|
强列建议加精--置顶!
|
sailboy 回复于:2004-12-24 19:00:05
|
谢谢
|
chris_wan 回复于:2004-12-28 16:59:55
|
好象有点错误,请看
[root@sztl-fw2 firewall]# ./firewall.sh
Usage: ./firewall.sh {start|stop|restart|show}
[root@sztl-fw2 firewall]# ./firewall.sh start
Starting firewall...Bad argument `DROP'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `80'
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.8: Unknown arg `--dprot'
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.8: Unknown arg `--to-ports'
Try `iptables -h' or 'iptables --help' for more information.
OK!
[root@sztl-fw2 firewall]# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh state NEW
ACCEPT tcp -- anywhere anywhere tcp dpt:smtp state NEW
ACCEPT tcp -- anywhere anywhere tcp dpt:pop3 state NEW
REJECT tcp -- anywhere anywhere reject-with tcp-reset
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@sztl-fw2 firewall]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
SNAT all -- anywhere anywhere to:192.168.9.1
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
|
chris_wan 回复于:2005-01-03 11:39:21
|
嗯,怎么没人回呢
|
tianfuming 回复于:2005-01-04 12:09:24
|
你把该脚本放到/sbin下然后chmod +x /sbin/firewall
然后/sbin/firewall start试试
|
Linux小鱼儿 回复于:2005-01-14 15:11:06
|
[code:1:a4eff34bb4]tianfuming
你好,你在这里说到可以[/code:1:a4eff34bb4]
[code:1:a4eff34bb4]重新安装GCC[/code:1:a4eff34bb4]
我想问一下是怎么个装法,我没有Rhat9 的光盘。
|
sailboy 回复于:2005-01-18 16:44:24
|
支持.!!!
|
unixli 回复于:2005-03-02 11:27:16
|
[quote:0d6724ff88="chris_wan"]l-fw2 firewall]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source ..........[/quote:0d6724ff88]
iptables -A FORWARD -d !202.108.36.196 -p tcp -m multiport --[color=red:0d6724ff88]dprot[/color:0d6724ff88] 25 110 -j DROP
这句有笔误,dprot应改为dport
|
lzlux 回复于:2005-03-26 16:55:37
|
http_access allowd lanb homepage #08、允许部分人员只能浏览指定网站;
???
有http_access allowd .... 这个命令参数吗??
|
zhangxiaosan 回复于:2005-03-28 11:43:15
|
zhichi
|
joyaid 回复于:2005-05-01 21:55:32
|
up
|
dqi 回复于:2005-05-08 22:30:02
|
我用的代理服务器redhat linux 9.0 ADSL共享上网,客户机WIN2000连接外部的VPN服务器连接不上,错误721。我的iptables设置的很简单:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o ppp0 -j MASQUERADE
就那么多。那位大哥知道在加点iptables命令,我的VPN就可以连接上?
|
原文转自:http://www.ltesting.net
|