iptables移植到开发板

来源:互联网 发布:大数据分析展现工具 编辑:程序博客网 时间:2024/04/29 08:40

1、iptables的移植
到netfilter官方网站(http://www.netfilter.org/)下载iptables最新源码并解压,编译方法具体可以参考iptables目录下的INSTALL文件。
./configure –host=arm-linux-gnueabi –prefix=/home/iptables –enable-static –disable-shared –with-ksource=./../../linux-2.6.30/
make
make install
arm-linux-gnueabi-strip /home/iptables/sbin/xtables-multi
将指定目录下/home/ipables/sbin的可执行程序拷贝到开发板的/usr/sbin下
(拷贝的时候要注意,所有的命令都是软链接到xtables-multi,因此一般的拷贝cp会将整个复制一遍,导致整个工具变大,正确的做法①先压缩,拷贝压缩文件后解压,②直接拷贝xtables-multi,像iptables、iptables-save工具使用软链接sudo cp -s xtables-multi iptables-save直接创建)

-–host: 指定交叉编译工具,一般为arm-none-linux-gnueabi、arm-linux-gnueabihf、arm-linux等,具体要和目标板用的交叉编译工具对应。
–-prefix: 指定安装目录,编译后的文件会全部放在安装目录中。必须是绝对路径!
–-enable-static:使用静态编译。
–-disable-shared:禁止动态编译。
–-with-ksource:指定目标板的内核目录。如果不指定,可能会提示:/usr/sbin/iptables: line 1: syntax error: unexpected “)”错误。当然,因为这个是可选项,如果没有提示错误,也可以不加这一项
2、内核的配置
为了使用iptables工具,需要配置内核来支持该工具,其实iptables工具主要是调用到内核里面的netfilter代码功能。这次是采用编译进内核的方式,当然也可以使用编译成模块的方式。
配置如下:
Networking —->
Networking options —->
[*] Network packet filtering (replaces ipchains) —>
[*]Advanced netfilter configuration
Core Netfilter Configuration —>
<*> Netfilter connection tracking support
<*> Netfilter Xtables support (required for ip_tables)
<*>”iprange” address range match support
<*>”multiport” Multiple port match support
<*>”state” match support
IP: Netfilter Configuration —>
<*> IPV4 connection tracking (required for masq/NAT)
[*]proc/sysctl compatibility with old connection tracking
<*> IP tables support (required for filtering/masq/NAT)
<*> IP range match support
<*> Packet filtering
<*> REJECT target support
<*> raw table support(required for NOTRACK/TRACE)
<*> Full NAT
说明:
1)若是不清楚,可以全部选中。
Networking —>
Networking options —>
Network packet filtering (replaces ipchains) —>(mini2440的内核版本稍高,选项不是这样的,但大同小异)
Core Netfilter Configuration —> 可以全选为build in (*)也可以全选为modules(M)
IP: Netfilter Configuration —> 可以全选为build in(*) 也可以全选为modules(M)
2)如果在开发板上执行 iptable -L -n出现以下信息,那么就需要重新配置和编译内核:
iptables v1.4.2: can’t initialize iptables table `filter’: Table does not exist (do you need to insmod?)Perhaps iptables or your kernel needs to be upgraded.
3)串口一直打印nf_conntrack:table full, dropping packet错误
在开发板的/etc/sysctl.conf中添加如下
net.netfilter.nf_conntrack_max = 655350
net.netfilter.nf_conntrack_tcp_timeout_established = 1200

0 0