案例:

公司有三个部门

 

工程部门  2.10--2.20

 

软件部门  2.21-2.30

经理办    2.31-2.40

 

上班时间 (周一---周五 082000

          工程部门 ftp  下班后无限制

 

         软件部门  http   不允许非法站点sina ,不允许使用迅雷 ,连接数 最多3个不允许聊天  不允许下载电影,不允许浏览图片 下班后无限制

 

       

      经理办公室   http  qq 都可以,下班后无限制

 

         dmz区域www服务器进行发布

 

     iptable+l7   +squid  +透明代理

分析:

 

iptables+squid实验应用层过滤_squid

 1:把规则设置成全部禁止之前要让你这台机器可以ssh上不然自己会掉,还要让你机器的内部可以通讯
Iptables –t filter –A INPUT –s 192.168.101.80 –p tcp –-dport 22 –m state –-state NEW,ESTABLISHED –j ACCEPT
Iptables –t filter –A OUTPUT –d192.168.101.80 –p tcp –-sport 22 –m state –-state ESTABLISHED –j ACCEPT
Iptables –t filter -A INPUT –i lo –j ACCEPT
Iptables –t filter -A OUTPUT –o lo –j ACCEPT

2:把所有规则设置成全部禁止的
Iptables –P INPUT  DROP
Iptables –P OUTPUT  DROP
Iptables –P FORWARD  DROP
3:先写软件部门的
首先让软件部门可以上网(通过透明代理服务器),然后再进行限制
Iptables –t nat –A PREROUTING –m iprange –-src-range 192.168.2.21-192.168.2.30 –m time –-timestart 08:00 –timestop 20:00 –p tcp --dport 80 –j REDIRECT –-to-ports 3128
Iptables –t filter –A INPUT –p tcp --dport 3128 –j ACCEPT
Iptables –t filter –A OUTPUT –m state –-state ESTABLISHED,RELATED –j ACCEPT
Iptables –t filter –A OUTPUT –p tcp –-dport 80 –j ACCEPT
Iptables –t filter –A OUTPUT –p udp –-dport  53 –j ACCEPT
Iptables –t filter –A INPUT –m state –-state ESTABLISHED,RELATED –j ACCEPT
Iptables –t filter –A FORWARD –m iprange –src-range 192.168.2.21-192.168.2.30 –p udp –-dport 53 –m time –-timestart 08:00 –-timestop
20:00 –o eth0 –j ACCEPT 
Iptables –t filter –A FORWARD –m state –-state ESTABLISHED,RELATED –j ACCEPT 
Iptables –t nat –A POSTROUTING –s 192.168.2.0/24 –o eth0 –j MASQUERADE
4:下面对软件部进行访问控制,首先用squid进行控制
Vim /etc/squid/squid.conf
首先做透明代理
900行左右的http_port 3128后面加上transparent
里面插入
acl ruanjianbu src 192.168.2.21-192.168.2.30/255.255.255.255
 411 acl worktime time M T W H F 08:00-20:00
 412 acl badsite url_regex -i sina
 413 acl badcont urlpath_regex  -i \.jpg$
 414 acl maxconn  maxconn 200
 415 http_access deny ruanjianbu worktime badsite
接着用iptables对qq和xunlei控制
iptables -t filter -A FORWARD -m iprange --src-range 192.168.2.21-192.168.2.30 -m time --timestart 08:00 --timestop 20:00 -m layer7 --l7proto qq -j DROP
iptables -t filter -A FORWARD -m iprange --src-range 192.168.2.21-192.168.2.30 -m time --timestart 08:00 --timestop 20:00 -m layer7 --l7proto xunlei -j DROP
5:下面开始写经理办的
iptables -t nat -A PREROUTING -m iprange --src-range 192.168.2.31-192.168.2.40 -p tcp --dport 80 -j REDIRECT --to-ports 3128
iptables -t filter -A FORWARD  -m iprange --src-range 192.168.2.31-192.168.2.40 -p udp --dport 53 -o eth0 -j ACCEPT
iptables -t filter -A FORWARD -m iprange --src-range 192.168.2.31-192.168.2.40 -m time --timestart 08:00 --timestop 20:00 -m layer7 --l7proto qq -j ACCEPT
6:最后写工程部的
iptables -t nat -A POSTROUTING -m iprange --src-range 192.168.2.10-192.168.2.20 -m time --timestart 08:00 --timestop 20:00 -p tcp --dport 21 -j MASQUERADE
iptables -t filter -A FORWARD -m iprange --src-range 192.168.2.10-192.168.2.20 -m time --timestart 08:00 --timestop 20:00 -p tcp --dport 21 -j ACCEPT
modprobe ip_nat_ftp加载ftp模块
7:对下班时候做控制
iptables -t filter -A FORWARD -s 192.168.2.0/24 -m time --timestart 20:01 --timestop 23:59 -j ACCEPT
iptables -t filter -A FORWARD -s 192.168.2.0/24 -m time --timestart 00:00 --timestop 07:59 -j ACCEPT
iptables -t nat -A PREROUTING -m time --timestart 20:01 --timestop 23:59 -p tcp --dport 80 -j REDIRECT --to-ports 3128
iptables -t nat -A PREROUTING -m time --timestart 00:00 --timestop 07:59 -p tcp --dport 80 -j REDIRECT --to-ports 3128
iptables -t nat -A POSTROUTING -m time --timestart 20:01 --timestop 23:59 -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -m time --timestart 00:00 --timestop 07:59 -o eth0 -j MASQUERADE
8:写DMZ区域的(用远程登陆模拟)
iptables -t nat -A PREROUTING -d 192.168.101.40 -p tcp --dport 3389 -j DNAT --to 192.168.3.100
iptables -t filter -A FORWARD -d 192.168.3.100 -p tcp --dport 3389 -j ACCEPT
 

 

1:把规则

1:把规则设置成