Learning together

Learning together with open source fans. QQ群:8021887


  • 网站首页

  • 站内留言

  • 关于本站

  • 我的相册

  • 联系羽飞

  • 内容订阅
  • Centos5.3+iptables+l7-filter+IPP2P的实现!

    作者: 羽飞 | 发布时间: 星期一, 01/25/2010 - 19:04 |

    这两天和一位朋友,相互研究了一下在IPTABLES中增加新的模块功能。

    在网上查了些资料,都没有成功实现,最后,经过测试与调试,最终实现。

    现在就把具体步骤贴出来,与大家分享。

    个人建议:在安装最新的软件前,大家最好看一下他们的版本与适合的版本。否则,出了问题也找不到原因!

    系统环境:

    CentOS 5.3

    Kernel 2.6.18-128.el5

    iptables 已经卸载(采用源码进行安装)

    1.下载所需软件包

    kernel 2.6.19.7
    # wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.19.7.tar.bz2

    iptables 1.3.7
    # wget http://www.netfilter.org/projects/iptables/files/iptables-1.3.7.tar.bz2

    L7-filter http://sourceforge.net/project/showfiles.php?group_id=80085
    netfilter-layer7-v2.9.tar.gz

    l7-protocols-2007-06-22.tar.gz

    以上软件全部下载在用户的家目录,全部解压到/usr/src/

    2.配置编译新内核

    先给内核打包:(当前目录/usr/src)

    # cd linux-2.6.19.7

    # patch -p1 < /usr/src/netfilter-layer7-v2.9/kernel-2.6.18-2.6.19-layer7-2.9.patch (给内核打上L7-filter的内核补丁)

    接下来,就是编译内核

    # make menuconfig

    选择好layer 7 (位置如下)

    -> Networking x
    x -> Networking support (NET [=y]) x
    x -> Networking options x
    x -> Network packet filtering (replaces ipchains) (NETFILTER [=y]) x
    x -> IP: Netfilter Configuration x
    x -> IP tables support (required for filtering/masq/NAT) (IP_NF_IP x
    x -> Layer 7 match support (EXPERIMENTAL) (IP_NF_MATCH_LAYER7 [= x

    # make bzImage

    # make modules

    # make modules_install

    以上这三步,用的时间有点长,在实验的时候,做了好几次,郁闷啊!!!!

    # make install

    # reboot(选择编译好的内核启动系统,也可以在/etc/grub.conf中进行一下设置,就不用在启动的时候选择了)

    # uname -r (查看新的内核)

    3.更新升级Iptalbes的Layer7补丁:(当前目录/usr/src)

    # cd cd iptables-1.3.7

    # patch -p1 < /usr/src/netfilter-layer7-v2.9/iptables-layer7-2.9.patch

    # chmod +x extensions/.layer7-test

    # make KERNEL_DIR=/usr/src/linux-2.6.19.7

    # make install KERNEL_DIR=/usr/src/linux-2.6.19.7

    # iptables -V(查看IPTABLES的版本)
    4. 安装Layer7 协议文件:(当前目录/usr/src)

    # cd l7-protocols-2007-06-22

    # make install

    5.使用iptables layer-7 filter:

    # iptables -t mangle -I PREROUTING -m layer7 –l7proto edonkey -j DROP (禁止edonkey)
    # iptables -t mangle -I PREROUTING -m layer7 –l7proto bittorrent -j DROP (禁止bt)
    # iptables -t mangle -I PREROUTING -m layer7 –l7proto qq -j DROP (禁止QQ通讯)
    # iptables -t mangle -I PREROUTING -m layer7 –l7proto msnmessenger -j DROP (禁止edonkey)
    # iptables -t mangle -I PREROUTING -m layer7 –l7proto xunlei -j DROP (禁止迅雷)
    # iptables -t mangle -I PREROUTING -m layer7 –l7proto kugoo -j DROP (禁止kugoo)
    # iptables -t mangle -I PREROUTING -m layer7 –l7proto yahoo -j DROP (禁止Yahoo! Messenger)

    6.增加iptables的ipp2p模块:

    下载patch-o-matic-ng-20060701软件

    ftp://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/

    安装IPTABLES的补丁

    cd /usr/src/ patch-o-matic-ng-20060701

    # export KERNEL_DIR=/usr/src/linux-2.6.19.7

    # export IPTABLES_DIR=/usr/src/iptables-1.3.7

    # ./runme ipp2p

    编译内核

    # cd /usr/src/linux-2.6.19.7
    # make modules SUBDIRS=net/ipv4/netfilter

    cp -f /usr/src/linux-2.6.19.7/net/ipv4/netfilter/*.ko /lib/modules/2.6.19.7/kernel/net/ipv4/netfilter

    chmod +x /lib/modules/2.6.19.7/kernel/net/ipv4/netfilter/*.ko

    安装ipp2p协议

    cd ipp2p-0.8.2/

    make

    cp libipt_ipp2p.so /usr/local/lib/iptables/

    cp ipt_ipp2p.ko /lib/modules/`uname -r`/kernel/net/ipv4/netfilter/

    chmod +x /lib/modules/`uname -r`/kernel/net/ipv4/netfilter/ipt_ipp2p.ko

    depmod -a

    进行测试

    iptables -A FORWARD -m ipp2p –edk –kazaa –bit -j DROP
    iptables -A FORWARD -p tcp -m ipp2p –ares -j DROP
    iptables -A FORWARD -p udp -m ipp2p –kazaa -j DROP

    因为没有测试的条件,所以,具体的就没有进行测试,大家如果有条件的话,就自行在环境中测试!!

    相关文章

    1. qrpeng Said,

      正好需要呢。3Q

      [回复]

    2. spacelee Said,

      貌似如果我的服务器是vps(xen虚拟机)就不行了吧

      [回复]

    3. spacelee Said,

      我和你的一模一样,但是我执行到这边的时候
      -> Networking x
      x -> Networking support (NET [=y]) x
      x -> Networking options x
      x -> Network packet filtering (replaces ipchains) (NETFILTER [=y]) x
      x -> IP: Netfilter Configuration x

      进去以后的里面看不到x -> IP tables support (required for filtering/masq/NAT) (IP_NF_IP x 了

      我用 /命令搜索Layer确实找到的路径和你的一样,但是我怎么也无法找到,不知道还有什么别的诀窍吗?

      [回复]

      羽飞 回复:

      VPS我没有试过,你可以用自己的虚拟机做个测试!
      关于你说的找不到的话,你看看你的系统的版本是不是和我的一样!
      如果一样的话,就应该能找到,仔细找一下!

      [回复]

    发表评论