免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3780 | 回复: 10
打印 上一主题 下一主题

[网络管理] 城域网环境下 接入学校iptables防火墙设置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-12-05 14:07 |只看该作者 |倒序浏览
网络环境:学校通过教育城域网中心接入互联网

iptables脚本如下:
#!/bin/sh


INET_IFACE1="eth0"

LAN_IFACE1="eth1"


LO_IFACE="lo"
LO_IP="127.0.0.1"

IPTABLES="/sbin/iptables"


#
# Needed to initially load modules
#

/sbin/depmod -a


/sbin/modprobe ipt_multiport
/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_mangle
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_state



/sbin/iptables -F
/sbin/iptables -X
/sbin/iptables -Z
/sbin/iptables -F -t nat
/sbin/iptables -F -t mangle


echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts


$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD DROP


$IPTABLES -N bad_tcp_packets
$IPTABLES -N allowed
$IPTABLES -N tcp_packets
$IPTABLES -N udp_packets
$IPTABLES -N icmp_packets

#
# bad_tcp_packets chain
#

$IPTABLES -A bad_tcp_packets -p tcp --tcp-flags SYN,ACK SYN,ACK \
-m state --state NEW -j REJECT --reject-with tcp-reset
$IPTABLES -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP

$IPTABLES -A bad_tcp_packets -p tcp -m multiport --dport 135,137,138,139 -j DROP
$IPTABLES -A bad_tcp_packets -p tcp -m multiport --dport 445,1022,1023,1433,1434 -j DROP
$IPTABLES -A bad_tcp_packets -p tcp -m multiport --dport 2500,2745,3128,3332,4444,5000 -j DROP
$IPTABLES -A bad_tcp_packets -p tcp -m multiport --dport 5238,5300,5554,6346,6667,9393 -j DROP

# allowed chain


$IPTABLES -A allowed -p TCP --syn -j ACCEPT
$IPTABLES -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A allowed -p TCP -j DROP

#
# TCP rules
#
$IPTABLES -A tcp_packets -p TCP -s 10.122.0.0/255.255.255.0 --dport 22 -j ACCEPT
$IPTABLES -A tcp_packets -p TCP -s 10.112.20.0/255.255.255.0 --dport 22 -j ACCEPT
#
# UDP ports
#

$IPTABLES -A udp_packets -p UDP --destination-port 135:139 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 445 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 69 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 593 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 1343 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 4444 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 1029 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 1068 -j DROP

#
# ICMP rules
#

$IPTABLES -A icmp_packets -p ICMP  --icmp-type 8 -j ACCEPT
$IPTABLES -A icmp_packets -p ICMP  --icmp-type 0 -j ACCEPT

#
#  INPUT chain
#

#
# Bad TCP packets we don't want.
#

$IPTABLES -A INPUT -p tcp -j bad_tcp_packets
$IPTABLES -A INPUT -p udp -j udp_packets
$IPTABLES -A INPUT -p ALL -i $LO_IFACE -j ACCEPT

#
# Rules for incoming packets from the internet.
#

$IPTABLES -A INPUT -p ICMP -j icmp_packets
$IPTABLES -A INPUT -p ALL -j tcp_packets
#$IPTABLES -A INPUT -p TCP -j allowed

#
#  FORWARD chain
#

$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -p udp -j udp_packets
$IPTABLES -A FORWARD -p tcp -j bad_tcp_packets
$IPTABLES -A FORWARD -p tcp -d 10.112.20.6 --dport 80 -j ACCEPT
$IPTABLES -A FORWARD -p tcp --dport 20 -j ACCEPT
$IPTABLES -A FORWARD -p tcp --dport 21 -j ACCEPT
$IPTABLES -A FORWARD -p TCP -i $LAN_IFACE1 -j ACCEPT
$IPTABLES -A FORWARD -p udp -j ACCEPT
$IPTABLES -A FORWARD -p icmp -j icmp_packets
#
# OUTPUT chain
#

#
# Bad TCP packets we don't want.
#

$IPTABLES -A OUTPUT -p tcp -j bad_tcp_packets
$IPTABLES -A OUTPUT -p udp -j udp_packets

p1.jpg (22.87 KB, 下载次数: 36)

p1.jpg

论坛徽章:
0
2 [报告]
发表于 2007-12-05 14:10 |只看该作者

希望大家指教下

有什么问题,如何改进,谢谢

论坛徽章:
0
3 [报告]
发表于 2007-12-05 14:30 |只看该作者
$IPTABLES -A bad_tcp_packets -p tcp --tcp-flags SYN,ACK SYN,ACK \
-m state --state NEW -j REJECT --reject-with tcp-reset
$IPTABLES -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP


第二条已经包括第一条了

$IPTABLES -A udp_packets -p UDP --destination-port 135:139 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 445 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 69 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 593 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 1343 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 4444 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 1029 -j DROP
$IPTABLES -A udp_packets -p UDP --destination-port 1068 -j DROP


$IPTABLES -A udp_packets -p UPD -m mulitport --dports 135:139,445,69,593,1343,4444,1029,1068 -j DROP

论坛徽章:
0
4 [报告]
发表于 2007-12-05 17:57 |只看该作者
$IPTABLES -A bad_tcp_packets -p tcp --tcp-flags SYN,ACK SYN,ACK \
-m state --state NEW -j REJECT --reject-with tcp-reset
$IPTABLES -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP


--tcp-flags SYN,ACK SYN,ACK -m state NEW  SYN 和 ACK置位 状态为NEW
! --syn -m state NEW  RST 或ACK被置位 状态为NEW

论坛徽章:
0
5 [报告]
发表于 2007-12-05 18:19 |只看该作者
记得以前用hping2测试过,都被! --syn -m state NEW过滤了

-p tcp --tcp-flags SYN,ACK SYN,ACK -m state --state NEW
这种包不也是(不属于任何链接的)新链接,但它没有第一次握手吗

论坛徽章:
0
6 [报告]
发表于 2007-12-06 07:41 |只看该作者
原帖由 banevv 于 2007-12-5 17:57 发表
$IPTABLES -A bad_tcp_packets -p tcp --tcp-flags SYN,ACK SYN,ACK \
-m state --state NEW -j REJECT --reject-with tcp-reset
$IPTABLES -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DRO ...


Iptables 指南 1.1.19
附录 B. 常见问题与解答
B.2. 未设置SYN的NEW状态包
B.3. NEW状态的SYN/ACK包

注意此处顺序 如果只是第二句那么 NEW NOT SYN 包是被丢掉了,但是用tcp-reset来回应ACK/SYN似乎要好一些?

论坛徽章:
0
7 [报告]
发表于 2007-12-06 09:15 |只看该作者
说得也是

用tcp-reset来回应ACK/SYN似乎要好一些

呵呵

论坛徽章:
0
8 [报告]
发表于 2007-12-06 10:06 |只看该作者
现在操作系统的协议栈没那么脆弱,规则里太多没必要的东西了
要用到的它自然会加载,不用的不要去 modprobe

论坛徽章:
0
9 [报告]
发表于 2007-12-06 10:31 |只看该作者
原帖由 platinum 于 2007-12-6 10:06 发表
现在操作系统的协议栈没那么脆弱,规则里太多没必要的东西了
要用到的它自然会加载,不用的不要去 modprobe

谢谢白金 能不能具体点啊?

论坛徽章:
0
10 [报告]
发表于 2007-12-06 11:56 |只看该作者
/sbin/depmod -a


/sbin/modprobe ipt_multiport
/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_mangle
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_state

这些可以去掉
/sbin/iptables -Z

可以去掉
/sbin/iptables -F -t nat
/sbin/iptables -F -t mangle

之后需要添加
iptables -X -t nat
iptables -X -t mangle
rmmod iptable_mangle

如果是 RedHat 系列发行版,上述可以通通用 service iptables stop 代替
不该加的加了,该加的你却没有,应该 modprobe ip_nat_ftp
具体可以参考 http://linux.chinaunix.net/bbs/v ... d=796056&extra=

至于你的策略,我不清楚你的具体需求,只是觉得太过繁琐有点画蛇添足,所以没细看
总之一点,要学会利用 -P policy,而不要一个一个去 DROP
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP