案例配置要求: 

公司有三个部门:工程部门(2..10--2.20)软件部门  2.21--2.30)、经理办 2.31--2.40)、

以及DMZ 区域(192.168.3.100web服务器

上班时间 (周一---周五 0800--1800) 

      工程部门   上班时间仅能登录ftpqq聊天,不允许http ,不能使用迅雷下班后无限制

      软件部门  可以使用http不允许站点sina ,不允许使用迅雷 ,连接数 最多3,不允许看图片不允许qq聊天不允许使用pplive ,下班后无限制

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

      dmz区域:实现对www服务器发布

周六、日任何部门都可以正常上网。

案例拓扑

案例分析:

1、针对工程部门,通过iptables+l7等模块实现控制;

2、软件部门、经理办公室,根据要求要通过squidiptables+L7等模块结合实现;

3、周一到周五上班时间通过squid透明代理实现上网,下班后,通过nat实现上网;

4、周六、周日也通过squid透明代理实现上网,并不做任何限制。

注:squid透明代理实现过程:

当我们在客户端浏览器中打开一个web请求,比如“ http://liuyuan51.blog.51cto.com ”,这时将陆续发生以下事件:

1.客户端向DNS请求“liuyuan51.blog.51cto.com,得到相应的IP地址2.3.4.5。然后,客户端使用某一端口(比如1066)向该IP地址的80端口发起web连接请求,请求web页面。

2.当该请求包通过透明代理服务器时,被squid防火墙将该数据包重定向到代理服务器的绑定端口3128。于是,透明代理服务器用某一端口(比如1088)2.3.4.580端口发起web连接请求,请求web页面。

3.收到响应的web页面后,代理服务器把该数据传送给客户端。

4.客户端浏览器显示该页面。

liuyuan51.blog.51cto.com的角度看来,连接是在192.168.101.1111088端口和2.3.4.580端口之间建立的。从client的角度看来,连接是在192.168.1.1001066端口和2.3.4.580端口之间建立的。

案例配置过程:

1、地址规划:

防火墙:eth0: 192.168.101.111/24

        eth1:192.168.2.1/24

        eth2:192.168.3.1/24

工程部门  192.168.2.10--192.168.2.20

软件部门  192.168.2.21--192.168.2.30

经理办    192.168.2.31--192.168.2.40

DMZ    192.168.3.100    web服务器

2、首先开启路由功能

# vim /etc/sysctl.conf 

7 net.ipv4.ip_forward = 1

#sysctl -p /etc/sysctl.conf   //加载配置文件使更改生效

3、配置一条规则SNAT规则,实现可以正常访问外网

iptables -t nat -A  POSTROUTING  -s 192.168.2.0/24   -o eth0 -j MASQUERADE

#--设置filter表的默认规则,拒绝所有---

iptables -P INPUT  DROP

iptables -P OUTPUT  DROR

iptables -P FORWARD  DROP

工程部门

   #仅允许访问外网ftp

iptables -t filter -A FORWARD -m iprange --src-range 192.168.2.10-192.168.2.20 -m time --timestart 08:00  --timestop 18:00 --weekdays Mon,Tue,Web,Thu,Fri  -p tcp --dport 21  -j ACCEPT

   #针对状态,允许ftp数据包返回----

iptables -t filter -A  FORWARD -m state --state ESTABLISHED,RELATED  -j ACCEPT

 

  #----工作时间拒绝qq聊天-------

iptables -t filter -A FORWARD -m iprange  --src-range 192.168.2.10-192.168.2.20 -m time --timestart 08:00  --timestop 18:00 --weekdays Mon,Tue,Web,Thu,Fri -m layer7 --l7proto qq -j DROP

  #---下班后,因为都是无限制,直接写一个网段---

iptables -t filter -A FORWARD -s 192.168.2.0/24 -m time --timestart 18:01  --timestop 07:59 --weekdays Mon,Tue,Web,Thu,Fri -j ACCEPT 

软件部门、经理办

 #上班时间通过squid来整体控制192.168.2.21-40网段

#周一到周五

iptables -t nat -A PREROUTING -m  iprange --src-range 192.168.2.21-192.168.2.40 -m time --timestart 08:00 --timestop 18:00 -p tcp --dport 80 -j REDIRECT --to-port 3128

#周六、日

iptables -t nat -A PREROUTING -m  iprange --src-range 192.168.2.10-192.168.2.40 -m time --weekdays Sun,Sat  -p tcp --dport 80 -j REDIRECT --to-port 3128

 #周一到周五允许客户端dns查询通过

iptables -t filter -A FORWARD -m iprange --src-range 192.168.2.21-192.168.2.40 -m time --timestart 08:00 --timestop 18:00 --weekdays Mon,Tue,Wed,Thu,Fri -p udp --dport 53 -j ACCEPT

#周六、日允许客户端dns查询通过

 iptables -t filter -A FORWARD -m iprange --src-range 192.168.2.10-192.168.2.40 -m time  --weekdays Sat,Sun -p udp --dport 53 -j ACCEPT

#针对squidiptables配置

#iptables -t filter -A INPUT -p tcp --dport 3128 -j ACCEPT

#iptables -t filter -A OUTPUT -p tcp -m state --state ESTABLISHED -j ACCEPT

#iptables -t filter -A OUTPUT -p tcp --dport 80 -s 192.168.101.111 -j ACCEPT

#iptables -t filter -A INPUT  -m state --state ESTABLISHED -j ACCEPT

#iptables -t filter -A OUTUT -p udp --dport 53 -j ACCEPT   //dns查询

#-----squid的透明代理配置,

# vim /etc/squid/squid.conf

929 http_port 3128 transparent

3004 visible_hostname   192.168.2.1

4138 dns_nameservers  222.88.88.88 222.85.85.85   //指明dns_nameserver

#------squid的控制部分

 590 acl soft  src 192.168.2.21-192.168.2.30

 591 acl worktime time MTWHF 08:00-18:00

 592 acl p_w_picpaths urlpath_regex -i \.jpg$

 593 acl sina   url_regex -i sina

 594 acl connumber maxconn 3

 595 acl jingli  src  192.168.2.31-192.168.2.40

 596 http_access allow soft worktime !p_w_picpaths !sina  !connumber  //软件部门

 597 http_access allow jingli          //经理办

 598 acl suoyou  src 192.168.2.10-192.168.2.40

 599 http_access allow suoyou  

# service squid start   启动squid服务

#-----允许经理办上班时间qq聊天

iptables -t filter -A FORWARD -m iprange  --src-range  192.168.2.31-192.168.2.40 -m time --timestart 08:00 --timestop 18:00 --weekdays Mon,Tue,Web,Thu,Fri -m layer7 --l7proto qq -j ACCEPT

 

DMZ区域web服务器发布

  #---Web服务器发布-----

#iptables -t nat -A PREROUTING  -d 192.168.101.111 -p tcp --dport 80 -i eth0 -j DNAT --to 192.168.3.100

#iptables -t filter -A FORWARD -d 192.168.3.100 -p tcp --dport 80 -i eth0 -j ACCEPT

案例结束。