mini6410防火墙(Netfilter/iptables)移植
2013-04-09 18:11
405 查看
一 配置编译内核,使其支持netfilter
Netfilter是内核态提供的包过滤框架,其中包含了各种各样的过滤表,默认的内核配置一般不包含这个框架,所以我们要先配置内核选项让其支持netfilte才行。$cd ~work/my6410Kernel/linux-2.6.38拷贝mini6410配置文件:
cp config_mini6410_a70 .config
完成以上操作后,执行make menuconfig命令,进入基于文本模式的菜单型的Linux内核配置:
.config - Linux/arm 2.6.38 Kernel Configuration ────────────────────────────────────────────────────────────────────────────── ┌───────────────── Linux/arm 2.6.38 Kernel Configuration ─────────────────┐ │ Arrow keys navigate the menu. <Enter> selects submenus --->. │ │ Highlighted letters are hotkeys. Pressing <Y> includes, <N> excludes, │ │ <M> modularizes features. Press <Esc><Esc> to exit, <?> for Help, </> │ │ for Search. Legend: [*] built-in [ ] excluded <M> module < > │ │ ┌────^(-)─────────────────────────────────────────────────────────────┐ │ │ │ Power management options ---> │ │ │ │ [*] Networking support ---> │ │ │ │ Device Drivers ---> │ │ │ │ File systems ---> │ │ │ │ Kernel hacking ---> │ │ │ │ Security options ---> │ │ │ │ -*- Cryptographic API ---> │ │ │ │ Library routines ---> │ │ │ │ --- │ │ │ │ Load an Alternate Configuration File │ │ │ └────v(+)─────────────────────────────────────────────────────────────┘ │ ├─────────────────────────────────────────────────────────────────────────┤ │ <Select> < Exit > < Help > │ └─────────────────────────────────────────────────────────────────────────┘
进入networking support --->
进入networking options -->
将 “Network packet filtering framework (Netfilter)”选中;
.config - Linux/arm 2.6.38 Kernel Configuration ────────────────────────────────────────────────────────────────────────────── ┌────────────────────────── Networking options ───────────────────────────┐ │ Arrow keys navigate the menu. <Enter> selects submenus --->. │ │ Highlighted letters are hotkeys. Pressing <Y> includes, <N> excludes, │ │ <M> modularizes features. Press <Esc><Esc> to exit, <?> for Help, </> │ │ for Search. Legend: [*] built-in [ ] excluded <M> module < > │ │ ┌────^(-)─────────────────────────────────────────────────────────────┐ │ │ │ [ ] Security Marking │ │ │ │ [ ] Timestamping in PHY devices │ │ │ │ [*] Network packet filtering framework (Netfilter) ---> │ │ │ │ < > The DCCP Protocol (EXPERIMENTAL) ---> │ │ │ │ < > The SCTP Protocol (EXPERIMENTAL) ---> │ │ │ │ < > The RDS Protocol (EXPERIMENTAL) │ │ │ │ < > The TIPC Protocol (EXPERIMENTAL) ---> │ │ │ │ < > Asynchronous Transfer Mode (ATM) │ │ │ │ < > Layer Two Tunneling Protocol (L2TP) ---> │ │ │ │ < > 802.1d Ethernet Bridging │ │ │ └────v(+)─────────────────────────────────────────────────────────────┘ │ ├─────────────────────────────────────────────────────────────────────────┤ │ <Select> < Exit > < Help > │ └─────────────────────────────────────────────────────────────────────────┘
由于本人对具体配置并不太熟悉,进入可以将所有选项全部选中(有点多。。过几天再发表重要选项的意义吧!),本人的配置如下:
--- Network packet filtering framework (Netfilter) │ │ │ │ [ ] Network packet filtering debugging │ │ │ │ [*] Advanced netfilter configuration │ │ │ │ Core Netfilter Configuration ---> │ │ │ │ < > IP virtual server support ---> │ │ │ │ IP: Netfilter Configuration ---> │ │ │ │
进入 Core Netfilter Configuration
<*> Netfilter NFQUEUE over NFNETLINK interface │ │ │ │ <*> Netfilter LOG over NFNETLINK interface │ │ │ │ <*> Netfilter connection tracking support │ │ │ │ [*] Connection mark tracking support │ │ │ │ [*] Connection tracking events │ │ │ │ < > DCCP protocol connection tracking support (EXPERIMENTAL) │ │ │ │ < > SCTP protocol connection tracking support (EXPERIMENTAL) │ │ │ │ <*> UDP-Lite protocol connection tracking support │ │ │ │ < > Amanda backup protocol support │ │ │ │ <*> FTP protocol support
-*- Netfilter Xtables support (required for ip_tables) │ │ │ │ *** Xtables combined modules *** │ │ │ │ -*- nfmark target and match support
进入 IP: Netfilter Configuration 配置(略)
然后重新编译内核,带有Netfiler/iptables功能的内核zImage就出现在了arch/arm/boot/中了。
$ make && make zImage
二 交叉编译iptables
Iptables是用户态提供的更改过滤规则的便捷工具,通过使用这个工具,可以方便的改变内核下netfilter的默认规则,也可以根据自己的需求添加自定的规则。1. 到netfilter官方网站(http://www.netfilter.org/)下载iptables(http://www.netfilter.org/projects/iptables/downloads.html)最新源码并解压,编译方法具体可以参考iptables目录下的INSTALL文件;
2. 首先一定要确保当前终端下能识别出arm-linux-gcc命令,接着在/opt目录下创建iptables目录,在终端下切换到iptables代码树。运行./configure --prefix=/opt/iptables --host=arm-linux配置以生成Makefile文件。
cd /opt/iptables-1.4.18/ ./configure --prefix=/opt/iptables --host=arm-linux make KERNEL_DIR=/home/zhangmin/work/my6410Kernel/linux-2.6.38 make NO.SHARED_LIBS=1 make make install
其中:
make KERNEL_DIR=/usr/src/linux(指定内核目录)
make NO.SHARED_LIBS=1(静态链接编译生成可执行文件)
进入/opt/iptables/查看生成的文件:
$tree /opt/iptables /opt/iptables |-- bin | `-- iptables-xml -> /opt/iptables/sbin/xtables-multi |-- include | |-- libiptc | | |-- ipt_kernel_headers.h | | |-- libip6tc.h | | |-- libiptc.h | | |-- libxtc.h | | `-- xtcshared.h | |-- xtables.h | `-- xtables-version.h |-- lib | |-- libip4tc.la | |-- libip4tc.so -> libip4tc.so.0.1.0 | |-- libip4tc.so.0 -> libip4tc.so.0.1.0 | |-- libip4tc.so.0.1.0 | |-- libip6tc.la | |-- libip6tc.so -> libip6tc.so.0.1.0 | |-- libip6tc.so.0 -> libip6tc.so.0.1.0 | |-- libip6tc.so.0.1.0 | |-- libiptc.la | |-- libiptc.so -> libiptc.so.0.0.0 | |-- libiptc.so.0 -> libiptc.so.0.0.0 | |-- libiptc.so.0.0.0 | |-- libxtables.la | |-- libxtables.so -> libxtables.so.10.0.0 | |-- libxtables.so.10 -> libxtables.so.10.0.0 | |-- libxtables.so.10.0.0 | |-- pkgconfig | | |-- libip4tc.pc | | |-- libip6tc.pc | | |-- libiptc.pc | | `-- xtables.pc | `-- xtables | |-- libip6t_ah.so | |-- libip6t_DNAT.so | |-- libip6t_DNPT.so | |-- libip6t_dst.so | |-- libip6t_eui64.so | |-- libip6t_frag.so | |-- libip6t_hbh.so | |-- libip6t_hl.so | |-- libip6t_HL.so | |-- libip6t_icmp6.so | |-- libip6t_ipv6header.so | |-- libip6t_LOG.so | |-- libip6t_MASQUERADE.so | |-- libip6t_mh.so | |-- libip6t_NETMAP.so | |-- libip6t_REDIRECT.so | |-- libip6t_REJECT.so | |-- libip6t_rt.so | |-- libip6t_SNAT.so | |-- libip6t_SNPT.so | |-- libipt_ah.so | |-- libipt_CLUSTERIP.so | |-- libipt_DNAT.so | |-- libipt_ECN.so | |-- libipt_icmp.so | |-- libipt_LOG.so | |-- libipt_MASQUERADE.so | |-- libipt_MIRROR.so | |-- libipt_NETMAP.so | |-- libipt_realm.so | |-- libipt_REDIRECT.so | |-- libipt_REJECT.so | |-- libipt_SAME.so | |-- libipt_SNAT.so | |-- libipt_ttl.so | |-- libipt_TTL.so | |-- libipt_ULOG.so | |-- libipt_unclean.so | |-- libxt_addrtype.so | |-- libxt_AUDIT.so | |-- libxt_CHECKSUM.so | |-- libxt_CLASSIFY.so | |-- libxt_cluster.so | |-- libxt_comment.so | |-- libxt_connbytes.so | |-- libxt_connlimit.so | |-- libxt_connmark.so | |-- libxt_CONNMARK.so | |-- libxt_CONNSECMARK.so | |-- libxt_conntrack.so | |-- libxt_cpu.so | |-- libxt_CT.so | |-- libxt_dccp.so | |-- libxt_devgroup.so | |-- libxt_dscp.so | |-- libxt_DSCP.so | |-- libxt_ecn.so | |-- libxt_esp.so | |-- libxt_hashlimit.so | |-- libxt_helper.so | |-- libxt_HMARK.so | |-- libxt_IDLETIMER.so | |-- libxt_iprange.so | |-- libxt_ipvs.so | |-- libxt_LED.so | |-- libxt_length.so | |-- libxt_limit.so | |-- libxt_mac.so | |-- libxt_mark.so | |-- libxt_MARK.so | |-- libxt_multiport.so | |-- libxt_nfacct.so | |-- libxt_NFLOG.so | |-- libxt_NFQUEUE.so | |-- libxt_NOTRACK.so | |-- libxt_osf.so | |-- libxt_owner.so | |-- libxt_physdev.so | |-- libxt_pkttype.so | |-- libxt_policy.so | |-- libxt_quota.so | |-- libxt_rateest.so | |-- libxt_RATEEST.so | |-- libxt_recent.so | |-- libxt_rpfilter.so | |-- libxt_sctp.so | |-- libxt_SECMARK.so | |-- libxt_set.so | |-- libxt_SET.so | |-- libxt_socket.so | |-- libxt_standard.so | |-- libxt_state.so | |-- libxt_statistic.so | |-- libxt_string.so | |-- libxt_tcpmss.so | |-- libxt_TCPMSS.so | |-- libxt_TCPOPTSTRIP.so | |-- libxt_tcp.so | |-- libxt_TEE.so | |-- libxt_time.so | |-- libxt_tos.so | |-- libxt_TOS.so | |-- libxt_TPROXY.so | |-- libxt_TRACE.so | |-- libxt_u32.so | `-- libxt_udp.so |-- sbin | |-- ip6tables -> xtables-multi | |-- ip6tables-restore -> xtables-multi | |-- ip6tables-save -> xtables-multi | |-- iptables -> xtables-multi | |-- iptables-restore -> xtables-multi | |-- iptables-save -> xtables-multi | `-- xtables-multi `-- share `-- man |-- man1 | `-- iptables-xml.1 `-- man8 |-- ip6tables.8 |-- ip6tables-restore.8 |-- ip6tables-save.8 |-- iptables.8 |-- iptables-extensions.8 |-- iptables-restore.8 `-- iptables-save.8
三 移植到min6410开发板
本人的mini6410环境已搭建起来,即使将带有Netfilter/iptables功能的内核烧写后文件系统中也没有找到iptables命令,必须得移植。将交叉编译好的/opt/iptables整个目录拷贝到文件系统中(或者通过NFS导入到文件系统中)
cp -R /nfsfile/iptables /opt/
再来使用iptables看能否使用:
$/opt/iptables/sbin/iptables -t filter -L Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
可以看到iptables命令已经可以使用,至此 Netfilter/iptables 移植完成!
参考资料:
http://blog.csdn.net/shuxiao9058/article/details/6923517
相关文章推荐
- (八)洞悉linux下的Netfilter&iptables:状态防火墙
- NetFilter/iptables防火墙设置
- 防火墙设置Netfilter/Iptables
- (十三)洞悉linux下的Netfilter&iptables:为防火墙增添功能模块【实战】
- (八)洞悉linux下的Netfilter&iptables:状态防火墙
- (十三)洞悉linux下的Netfilter&iptables:为防火墙增添功能模块【实战】
- 如何使用netfilter/iptables构建防火墙
- 如何使用netfilter/iptables构建防火墙
- Linux下Netfilter/IPTables防火墙案例分析
- 如何使用netfilter/iptables构建防火墙
- 如何使用netfilter/iptables构建防火墙
- 深入浅出Netfilter/iptables防火墙框架(入门篇) 推荐
- (八)洞悉linux下的Netfilter&iptables:状态防火墙
- (八)洞悉linux下的Netfilter&iptables:状态防火墙
- Netfilter/Iptables的防火墙功能介绍 1
- Netfilter/Iptables的防火墙功能介绍 2
- 7-3 10 网络 防火墙 netfilter iptables
- 防火墙、Iptables、netfilter/iptables、NAT 概述
- 防火墙、Iptables、netfilter/iptables、NAT 概述
- 深入浅出Netfilter/iptables防火墙框架(基础篇)