mini6410防火墙(Netfilter/iptables)移植

一 配置编译内核,使其支持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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值