iptables移植到开发板

本文介绍如何将iptables移植到嵌入式系统,并详细说明了内核配置过程以支持iptables功能。包括下载源码、交叉编译、安装及内核配置选项等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值