Chinaunix

标题: 重编内核后iptables无法启动。 [打印本页]

作者: JonZhao    时间: 2006-03-28 18:26
标题: 重编内核后iptables无法启动。
RHEL4 U3重新编译了2.6.16内核后,iptables 无法启动了。
提示信息如下:

[root@S1 ~]# service iptables start
Applying iptables firewall rules: iptables-restore v1.2.11: iptables-restore: unable to initializetable 'filter'

Error occurred at line: 3
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
                                                           [FAILED]
[root@S1 ~]# uname -a
Linux S1 2.6.16 #1 Sat Mar 25 11:00:54 CST 2006 i686 i686 i386 GNU/Linux
[root@S1 ~]#
作者: flw    时间: 2006-03-28 20:14
手工执行一下
  1. modprobe ip_tables
  2. modprobe iptable_filter
复制代码

然后再 service iptables start 试试!
作者: flw    时间: 2006-03-28 20:16
另外,你可以把下面这个命令的执行结果发上来让大家看看:
  1. ls -al /lib/modules/`uname -r`/kernel/net/ipv4/netfilter
复制代码

如果这几个目录里面没有 ip_tables.ko iptable_filter.ko 这两个文件,
那么你可能需要在 kernel 源码里面执行一下 make install 命令:
  1. cd /usr/src/linux
  2. make install
复制代码


如果这个目录里面有这几个文件的话,
那么你可能需要先执行一下:
  1. depmod -a
复制代码

然后再试试。

[ 本帖最后由 flw 于 2006-3-28 20:20 编辑 ]
作者: JonZhao    时间: 2006-03-29 16:31
[root@S2 ~]# modprobe ip_tables
FATAL: Module ip_tables not found.
[root@S2 ~]# modprobe iptable_filter
FATAL: Module iptable_filter not found.
[root@S2 ~]#


[root@S2 ~]# ls -al /lib/modules/2.6.16/kernel/net/ipv4/netfilter
total 1664
drwxr-xr-x  2 root root   4096 Mar 25 10:13 .
drwxr-xr-x  4 root root   4096 Mar 25 10:13 ..
-rw-r--r--  1 root root 142773 Mar 25 10:13 ip_conntrack_amanda.ko
-rw-r--r--  1 root root 158934 Mar 25 10:13 ip_conntrack_ftp.ko
-rw-r--r--  1 root root 151659 Mar 25 10:13 ip_conntrack_irc.ko
-rw-r--r--  1 root root 778223 Mar 25 10:13 ip_conntrack.ko
-rw-r--r--  1 root root 117161 Mar 25 10:13 ip_conntrack_proto_sctp.ko
-rw-r--r--  1 root root 140801 Mar 25 10:13 ip_conntrack_tftp.ko
-rw-r--r--  1 root root 167267 Mar 25 10:13 ip_queue.ko
[root@S2 ~]#

看来我在编译内核时(默认的,没有改动任何模块,直接保存编译的)没有编译那两个模块,真不感相信最新的内核默认没有这两项。我重编译一遍试试再说。
谢谢flw的大力支持。

[ 本帖最后由 JonZhao 于 2006-3-29 16:36 编辑 ]
作者: platinum    时间: 2006-03-29 16:55
可能选择网络部分的 filter 的时候,没有选择全 netfilter 的部分
实在不行可以用 /boot/config-2.6.xx.xx 来代替 .config 去看一下,了解一下一些相关的依赖关系
作者: JonZhao    时间: 2006-03-31 10:41
原帖由 flw 于 2006-3-28 20:14 发表
手工执行一下
  1. modprobe ip_tables
  2. modprobe iptable_filter
复制代码

然后再 service iptables start 试试!


提示没有这些模块。
作者: JonZhao    时间: 2006-03-31 10:41
原帖由 flw 于 2006-3-28 20:16 发表
另外,你可以把下面这个命令的执行结果发上来让大家看看:
  1. ls -al /lib/modules/`uname -r`/kernel/net/ipv4/netfilter
复制代码

如果这几个目录里面没有 ip_tables.ko iptable_filter.ko 这两个文件,
那 ...


我是新编的内核,估计是没有编上这些模块。
作者: JonZhao    时间: 2006-03-31 10:43
我从新编了一下,
选了一些我觉得相关的,可以还是没有那些模块。
这些模块到底是在哪儿选呀?
作者: flw    时间: 2006-03-31 11:03
进入 make menuconfig 之后,按 / (斜杠),就可以进入搜索模式。
输入你想要的关键字,比如 iptables 就可以找到它的位置。

我这里是 2.6.15.6,我的位置是:
  1. Symbol: IP_NF_IPTABLES [=m]                                               
  2. Prompt: IP tables support (required for filtering/masq/NAT)               
  3.   Defined at net/ipv4/netfilter/Kconfig:183                              
  4.   Depends on: NET && INET && NETFILTER                                    
  5.   Location:                                                               
  6.     -> Networking                                                         
  7.       -> Networking support (NET [=y])                                    
  8.         -> Networking options                                             
  9.           -> Network packet filtering (replaces ipchains) (NETFILTER [=y])
  10.             -> IP: Netfilter Configuration                                
复制代码

[ 本帖最后由 flw 于 2006-3-31 11:07 编辑 ]
作者: JonZhao    时间: 2006-03-31 17:23
经过重新编完内核后
[root@RHEL43 ~]# lsmod
Module                  Size  Used by
iptable_filter          3200  0
ip_tables              12248  1 iptable_filter
xt_tcpudp               3712  0
x_tables               12804  2 ip_tables,xt_tcpudp
autofs4                19204  0
dm_mirror              21456  0
dm_multipath           18696  0
dm_mod                 53400  2 dm_mirror,dm_multipath
button                  6928  0
battery                 9732  0
ac                      5252  0
ipv6                  227296  14
shpchp                 40608  0
i2c_piix4               8976  0
i2c_core               20992  1 i2c_piix4
pcnet32                27908  0
mii                     5632  1 pcnet32
floppy                 57156  0
ext3                  117768  1
jbd                    53524  1 ext3
mptscsih               33360  0
mptbase                47328  1 mptscsih
sd_mod                 16640  0
scsi_mod              127400  2 mptscsih,sd_mod
[root@RHEL43 ~]#

说明ip_iptables模块已经加载。
运行iptables提示如下。


[root@RHEL43 ~]# service iptables restart
Flushing firewall rules:                                   [  OK  ]
Setting chains to policy ACCEPT: filter                    [  OK  ]
Unloading iptables modules:                                [  OK  ]
Applying iptables firewall rules: iptables-restore: line 18 failed
                                                           [FAILED]
[root@RHEL43 ~]#

还是启动不了。
iptables 我重装过,问题还是一样。
晕咧,内核默认具然不加载ip_iptables模块,而且,还要开启其它的一个模块,ip_iptables模块才会出来。
想升级内核真是一波三折呀。
作者: platinum    时间: 2006-03-31 22:30
原帖由 JonZhao 于 2006-3-31 17:23 发表
[root@RHEL43 ~]# service iptables restart
Flushing firewall rules:                                   [  OK  ]
Setting chains to policy ACCEPT: filter                    [  OK  ]
Unloading iptables modules:                                [  OK  ]
Applying iptables firewall rules: iptables-restore: line 18 failed
                                                           [FAILED]
[root@RHEL43 ~]#

从这里入手查
作者: JonZhao    时间: 2006-04-01 00:32
iptables-restore这个文件是个程序,而且是加了密的。
不知道配置文件在哪儿。
作者: kenduest    时间: 2006-04-01 00:47
原帖由 JonZhao 于 2006-4-1 00:32 发表
iptables-restore这个文件是个程序,而且是加了密的。
不知道配置文件在哪儿。


不是,是这样执行:

iptables-restore < /etc/sysconfig/iptables

查阅一下错误显示行数。

==
作者: JonZhao    时间: 2006-04-01 13:52
原帖由 kenduest 于 2006-4-1 00:47 发表


不是,是这样执行:

iptables-restore < /etc/sysconfig/iptables

查阅一下错误显示行数。

==



[root@RHEL43 ~]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
[root@RHEL43 ~]#

第18行为:COMMIT
删除它后报出下错误:

[root@RHEL43 ~]# vi /etc/sysconfig/iptables
[root@RHEL43 ~]# service iptables restart
Flushing firewall rules:                                   [  OK  ]
Setting chains to policy ACCEPT: filter                    [  OK  ]
Unloading iptables modules:                                [  OK  ]
Applying iptables firewall rules: iptables-restore: COMMIT expected at line 19
                                                           [FAILED]
[root@RHEL43 ~]#
作者: JonZhao    时间: 2006-04-01 13:55
搞定。

将这些系统自带的规则全部删除,iptables可以启动了。

-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited

重新编一次内核会对IPTABLES有这么大的影响,那对其它服务会不会也有影响?
谢谢FLW 、 platinum 、 kenduest
谢谢各位!

[ 本帖最后由 JonZhao 于 2006-4-1 13:57 编辑 ]
作者: souldemo    时间: 2007-03-20 16:15
楼主怎么遇到和我 一样 的问题了,
我 也是重新编译的内核,然后就 不能启动iptables了,
我研究过,是由于包含 -m state的语句出的问题,重新编译内核 后
就无法支持了,虽然我在内核配置中选择了state match support,可还是不行,
作者: 万里北国    时间: 2008-11-18 16:07
下面这篇文章里对这个问题有说明:
http://serverbbs.ccw.com.cn/thread-17030-1-3.html

RH系的iptables在用户自行编译内核后不能用RH风格的脚本里面的-A RH-Firewall-1-INPUT了,
只能用通用的iptables 脚本。
作者: Godbach    时间: 2008-11-18 16:50
原帖由 JonZhao 于 2006-4-1 13:55 发表
搞定。

将这些系统自带的规则全部删除,iptables可以启动了。

-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT  ...


之前系统配置的有iptables规则啊




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2