免费注册 查看新帖 |

Chinaunix

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

iptables怪问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-07 14:55 |只看该作者 |倒序浏览
20可用积分
不知道是我的防火墙的配置问题还是系统的bug,当我运行防火墙一段时间后,就出现了eth1的断网现象,向给为高人求解

但我怎么看我的防火墙策略都没有哪里不对啊。。。人都晕了,向CU的高手求救。

[root@manifold ~]# cat /etc/redhat-release
CentOS release 5.2 (Final)
[root@manifold ~]# uname -a
Linux manifold.com 2.6.18-92.el5PAE #1 SMP Tue Jun 10 19:22:41 EDT 2008 i686 i686 i386 GNU/Linux
[root@manifold ~]# lsb_release
LSB Version:    :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
[root@manifold ~]# cat /usr/local/virus/iptables/iptables.rule.real
#!/bin/bash
#Written by manifold.
#Readme:This script is used to abandon attack.
#Date:2009-07-19
#Change first:2009-08-15
#Change:2009-08-24

#Set the network parameters.
INIF=""
INNET=""
SOURCEIP="219.136.241.35"

export INIF INNET

#Abondon the DOS attack.
echo "1" > /proc/sys/net/ipv4/tcp_syncookies

#Ignore the "ping" package.
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

#Open the reverse direction filter.
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
        echo "1" > $i
done

#Record some problems packets.
#..................martian source 192.168.0.200 from 192.168.0.222, on dev eth0
for i in /proc/sys/net/ipv4/conf/*/log_martians; do
        echo "0" > $i
done

for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do
        echo "0" > $i
done

for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do
        echo "0" > $i
done

for i in /proc/sys/net/ipv4/conf/*/send_redirects; do
        echo "0" > $i
done

#Set the environment and clean the default iptables policy.
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

iptables -F
iptables -X
iptables -Z
iptables -P INPUT   DROP
iptables -P OUTPUT  ACCEPT
iptables -P FORWARD ACCEPT
#Warnning:This policy "lo accept" must be add!If not add,something about the run_server.sh will be error.Firstly the Game's login page can't work properly.
#And if add the policy to iptables chains.The result of "iptables -L -n" will perform a accept list like "ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0".
#Don't be confused by it.
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state RELATED -j ACCEPT

#Abondon the host that write in iptables.deny
if [ -f /usr/local/virus/iptables/iptables.deny ]; then
        for ip in `/bin/cat /usr/local/virus/iptables/iptables.deny`
        do
        /sbin/iptables -I INPUT -s $ip -j DROP
        done
fi

#Abondon the host that write in iptables.adve
if [ -f /usr/local/virus/iptables/iptables.adve ]; then
        for ip in `/bin/cat /usr/local/virus/iptables/iptables.adve|/bin/awk '{print $1}'`
        do
        /sbin/iptables -I INPUT -s $ip -j DROP
        done
fi

#Accept the host that write in iptables.allow.
if [ -f /usr/local/virus/iptables/iptables.allow ]; then
        for ip2 in `/bin/cat /usr/local/virus/iptables/iptables.allow`
        do
        /sbin/iptables -I INPUT -s $ip2 -j ACCEPT
        done
fi

#Some policy to reject the www.
if [ -f /usr/local/virus/httpd-err/iptables.http ]; then
        sh /usr/local/virus/httpd-err/iptables.http
fi
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT


#Allow some services' data input.
#Check the Port of the ssh services and add a iptables policy.
#SSH_PORT=`cat /etc/ssh/sshd_config|grep -w Port | awk '{print $2}'`

iptables -A INPUT -p TCP --dport  80  -j ACCEPT
iptables -A INPUT -p TCP --dport  443  -j ACCEPT      
iptables -A INPUT -p TCP --dport  3306  -j ACCEPT   
iptables -A INPUT -p TCP --dport  843  -j ACCEPT     
iptables -A INPUT -p TCP --dport  14410 -j ACCEPT      
iptables -A INPUT -p TCP --dport  8000  -j ACCEPT      
iptables -A INPUT -p TCP --dport  63572  -j ACCEPT      
iptables -A INPUT -p TCP -s "$SOURCEIP" --dport  5666  -j ACCEPT


#Allow some types of ICMP.
#If you want to allow the ping package,so as the syn signal,you must add the ICMP package type 8 to AICMP to accept list.
AICMP="0 3 3/4 4 8 11 12 14 16 18"
for tyicmp in $AICMP
do
        iptables -A INPUT -p icmp --icmp-type $tyicmp -j ACCEPT
done


#About MTU limit.
iptables -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1400:1536 -j TCPMSS --clamp-mss-to-pmtu

if [ -f /usr/local/virus/iptables/iptables.rule.add ];then
/bin/sh /usr/local/virus/iptables/iptables.rule.add
fi

[root@manifold ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 80003ES2LAN Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
NETMASK=255.255.255.192
IPADDR=219.136.241.11
GATEWAY=219.136.241.254
TYPE=Ethernet
[root@manifold ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Intel Corporation 80003ES2LAN Gigabit Ethernet Controller (Copper)
DEVICE=eth1
BOOTPROTO=static
ONBOOT=yes
NETMASK=255.255.255.192
IPADDR=121.136.223.120
GATEWAY=121.136.223.65
TYPE=Ethernet

[root@manifold ~]# crontab -l
*/5 * * * * /bin/sh /usr/local/virus/iptables/iptables.rule.real

因为这个防火墙脚本配合了其他的攻击检测脚本。。。但是我测试过了,其他的脚本全部都不运行,只运行这个防火墙的脚本,一段时间后,eth1断网。。。补充说明一下eth0是电信的IP,eth1是网通的IP。。。

再补充一点:selinux我是关闭了来做测试的。

[ 本帖最后由 yumanifold 于 2009-9-7 15:09 编辑 ]

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
2 [报告]
发表于 2009-09-07 14:57 |只看该作者
为什么楼主用crontab任务?

论坛徽章:
0
3 [报告]
发表于 2009-09-07 14:58 |只看该作者

回复 #2 chenyx 的帖子

因为这个防火墙脚本配合了其他的攻击检测脚本。。。但是我测试过了,其他的脚本全部都不运行,只运行这个防火墙的脚本,一段时间后,eth1断网。。。。eth1是网通的。。。eth0是电信的。。。

论坛徽章:
0
4 [报告]
发表于 2009-09-07 16:04 |只看该作者
你的脚本太过于庞大了。

如果你怀疑你iptables脚本有问题,你可以禁止掉iptables,观察观察。

系统不可能有这bug的,你可以再添加一块独立网卡试试。

如果你什么都不方便的话,那么你找台机子,搭建一个类似的环境,测试测试你的脚本,看看会不会出现你说的eth1断开现象。

论坛徽章:
0
5 [报告]
发表于 2009-09-07 17:34 |只看该作者

回复 #4 marsaber 的帖子

没用,待eth1断开之后,我再关掉iptables也一样不通。。。唯有重启机器才行。。。我测试过很多情况了,所以唯有暂时定义为系统bug。。。

有其他的意见吗?参考一下,我看能不能想出什么来。。。其他服务器也是双线,只不过其他的都是将双线IP都放到了eth0上面,由IDC机房的路由来定义数据的流向。。。

实验是没可能了,我手头上没有空的机器,这台机器都是因为要改双网卡双线,所以才暂时替换下来的做测试的。。。

[ 本帖最后由 yumanifold 于 2009-9-7 17:37 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2009-09-07 17:37 |只看该作者

回复 #4 marsaber 的帖子

现在才注意到,原来楼上是marsaber啊?哈哈。。。我近期也在研究selinux,有不会的还得请教尹大侠您呢,哈哈

论坛徽章:
0
7 [报告]
发表于 2009-09-07 20:12 |只看该作者

回复 #6 yumanifold 的帖子

你是???


eth1断开之后,我再关掉iptables也一样不通
这样的话,就不能排除到底是不是iptables脚本的问题了。

论坛徽章:
0
8 [报告]
发表于 2009-09-07 20:27 |只看该作者

回复 #7 marsaber 的帖子

iptables都已经关掉了,都还是一个样。。。而且似乎iptables运行了一段时间之后才会出现这种情况的。。。如果是iptables脚本造成的,那么应该在iptables脚本执行之后就会立即断开啊。。。。所以才会怀疑是系统的bug,但是又不死心,所以就发上来看看。。。

论坛徽章:
0
9 [报告]
发表于 2009-09-07 20:30 |只看该作者

回复 #7 marsaber 的帖子

我是?我只是个小人物而已,只是有拜读过您的大作

论坛徽章:
0
10 [报告]
发表于 2009-09-07 20:42 |只看该作者

回复 #8 yumanifold 的帖子

有没有考虑过硬件问题呢?

eth1断开之后,怎么弄就好了?
ifdown+ifup?service network restart?
断开之后,ifconfig eth1看到有没有DROP掉的包?有的话,多不?

找另外一台机子,安装同样的系统、执行同样的脚本,还出现这种情况吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP