linux redhat5.4   iptables+Layer7小案例 的實現

案例:三個部門,工程部 軟件部 經理辦公室實現iptables過濾




工程部門:192.168.2.10192.168.2.20 /30 192.168.2.10 192.168.2.11 192.168.2.12/30 192.168.2.16/30 192.168.2.20

軟件部門: 192.168.2.21-192.168.2.30 /30 2.21/32 2.22/32 2.23/32 192.168.2.24/30[24-27]

2.28--2.30/32

經理辦公室: 192.168.2.31-192.168.2.40

拓撲圖:

183959790.png

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

[root@localhost ~]# iptables -t filter -A INPUT -s 192.168.2.1 -p tcp --dport 22 -j ACCEPT

[root@localhost ~]# iptables -t filter -A OUTPUT -d 192.168.2.1 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

[root@localhost ~]# iptables -P INPUT DROP

[root@localhost ~]# iptables -P OUTPUT DROP

root@localhost ~]# iptables -P FORWARD DROP

1: 工程部門

上班時間 的限制可以訪問 ftp服務器 [192.168.1.166]filter forward

iptables -t filter -A FORWARD -m iprange --src-rang 192.168.2.10-192.168.2.20 -m time --timestart 08:00 --timestop 20:00

--weekdays Mon,Tue,Wed,Thu,Fri -p tcp --dport 21 -d 192.168.1.166 -j ACCEPT

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

modprobe ip_nat_ftp

不允許聊天 qq L7

[root@localhost ~]# iptables -t filter -I FORWARD 2 -m iprange --src-rang 192.168.2.10-192.168.2.20 -m time --timestart 08:00 --timestop 20:00 --weekdays

Mon,Tue,Wed,Thu,Fri -m layer7 --l7proto qq -j DROP

不允許http上網 (NAT)

下班後無限制

[root@localhost ~]# iptables -t filter -I FORWARD 2 -s 192.168.2.0/24 -o eth1 -m time

--timestart 20:01 --timestop 07:59 -j ACCEPT

2: 軟件部門

因爲軟件部門和經理辦公室在上班時間都要上網,所以在上班時間DNS的數據包能夠forward

root@localhost ~]# iptables -t filter -I FORWARD 2 -m iprange --src-range 192.168.2.21-192.168.2.40 -m time --timestart 08:00 --timestop 20:00

--weekdays Mon,Tue,Wed,Thu,Fri -p udp --dport 53 -j ACCEPT

上班時間 限制可以訪問 http 新浪 中華網站 無限制 (SQUIID)

iptables -t nat -R PREROUTING 1 -i eth0 -p tcp --dport 80 -j REDIRECT --to-ports 3128

打開squid的配置文件,squid 默認是拒絕所有,在squid配置文件做可訪問的策略

590

590 acl soft src 192.168.2.21-192.168.2.30/255.255.255.255

591 acl worktime MTWHF 08:00-20:00

592 http_access allow soft worktime

[root@localhost ~]# iptables -t filter -A INPUT -i eth0 -p tcp --dport 3128 -j ACCEPT

[root@localhost ~]# iptables -t filter -A OUTPUT -m state --state ESTABLISHED -j ACCEPT

iptables -t filter -A OUTPUT -o eth1 -p tcp --dport 80 -j ACCEPT

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

iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT NDS解析能夠出去

打開squid配置文件設置透明代理

http_port 3128 transparent

*.163.com 無圖片

打開squid 的配置文件

acl soft src 192.168.2.21-192.168.2.30/255.255.255.255

acl worktime time MTWHF 08:00-20:00

acl badcontent urlpath_regex -i \.jpg$

acl badsite dstdom_regex -i sina

http_access deny soft worktime badsite

http_access allow soft worktime !badcontent

不允許聊天 qq (L7)

[root@localhost ~]# iptables -t filter -I FORWARD 2 -m iprange --src-range 192.168.2.21-192.168.2.30 -m time --timestart 08:00 --timestop 20:00 --weekdays

Mon,Tue,Wed,Thu,Fri -m layer7 --l7proto qq -j DROP

不允許迅雷下載資源

[root@localhost ~]# iptables -t filter -I FORWARD 2 -m iprange --src-range 192.168.2.21-192.168.2.30 -m time --timestart 08:00 --timestop 20:00 --weekdays

Mon,Tue,Wed,Thu,Fri -m layer7 --l7proto xunlei -j DROP

最大連接數3

打開配置文件

acl badconn maxconn 3

http_access allow soft worktime !badcontent !badconn

3: 經理辦公室

上班時間 http qq smtp pop3 (L7)

下班後無限制

4:DMZ

acl manager1 src 192.168.2.31-192.168.2.40/255.255.255.255

http_access allow manager1 worktime

上班時間可以QQ

[root@localhost ~]# iptables -t filter -I FORWARD 2 -m iprange --src-range 192.168.2.31-192.168.2.40 -m time --timestart 08:00 --timestop 20:00 --weekdays

Mon,Tue,Wed,Thu,Fri -m layer7 --l7proto qq -j ACCEPT

發佈 : www rdp (NAT PREROUTING)

iptables -t nat -A PREROUTING -d 192.168.1.44 -p tcp --dport 3389 -j DNAT --to 192.168.3.100

iptables -t filter -I FORWARD 1 -i eth1 -d 192.168.3.100 -p tcp --dport 3389 -j ACCEPT


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章