免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 680 | 回复: 0
打印 上一主题 下一主题

redhat -netfilter -succesfull [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-02-26 11:51 |只看该作者 |倒序浏览

REDHAT下升级内核到2.6.15.4及给netfilter打补丁
1.编辑环境
[root@testcc ~]# uname -a
Linux testcc 2.6.15.4 #1 Sat Feb 23 03:05:51 CST 2008 i686 i686 i386 GNU/Linux
2.安装redhat 4u4系统
安装时选择自定义安装,软件包只选择development tools这个选项,开始安装系统...
3.下载需要的原码包
cd /usr/src
(下载内核源代码)
wget -c
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.15.4.tar.bz2
(下载netfilter源代码)
wget -c
http://ftp.netfilter.org/pub/iptables/iptables-1.3.5.tar.bz2
(下载netfilter补丁)
wget -c
http://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/patch-o-matic-ng-20060209.tar.bz2
(下载ipp2p源代码,patch-o-ma自带的是0.7.2的,0.8.1_rc1可以支持更多的协议)
wget -c
http://www.ipp2p.org/downloads/ipp2p-0.8.1_rc1.tar.gz
(下载netfilter-layer7源代码)
wget -c
http://keihanna.dl.sourceforge.net/sourceforge/l7-filter/netfilter-layer7-v2.1.tar.gz
(下载netfilter-layer7协议)
wget -c
http://belnet.dl.sourceforge.net/sourceforge/l7-filter/l7-protocols-2006-01-22.tar.gz
(下载geoip根据地理位置匹配用的2个文件,我们也把它下载下来,如果你不用,可以不下)
wget -c
http://people.netfilter.org/peejix/geoip/database/20050410/geoipdb.bin
wget -c
http://people.netfilter.org/peejix/geoip/database/20050410/geoipdb.idx
4.解压代码包和建立geoip目录
cd /usr/src
tar -jxvf linux-2.6.15.4.tar.bz2
tar -jxvf iptables-1.3.5.tar.bz2
tar -jxvf patch-o-matic-ng-20060209.tar.bz2
tar -zxvf netfilter-layer7-v2.1.tar.gz
tar -zxvf l7-protocols-2006-01-22.tar.gz
mkdir /var/geoip
cp geoipdb.bin /var/geoip
cp geoipdb.idx
5.给kernel和iptables打补丁
cd /usr/src
ln -s /usr/src/linux-2.6.15.4 linux
cd /usr/src/linux
make mrproper
cp /boot/config-2.6.11-1.1369_FC4 ./.config
make menuconfig (什么都不做,保存退出,其实可以不做这一步,但是为了保证.cofnig文件的存在,我们还是要做下)
cd /usr/src/patch-o-matic-ng-20060209
KERNEL_DIR=/usr/src/linux IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme string   
(string 2.6.15.4已经包含这个补丁,不用在打了,打你也打不上的patch里没有)
KERNEL_DIR=/usr/src/linux IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme comment   (comment 2.6.15.4已经包含这个补丁)
KERNEL_DIR=/usr/src/linux IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme connlimit (2.6.15.4已经包含这个补丁)
KERNEL_DIR=/usr/src/linux IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme iprange   (2.6.15.4已经包含这个补丁)
KERNEL_DIR=/usr/src/linux IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme geoip
KERNEL_DIR=/usr/src/linux IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme nth
KERNEL_DIR=/usr/src/linux IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme ipp2p
KERNEL_DIR=/usr/src/linux IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme quota
KERNEL_DIR=/usr/src/linux IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme time
cd /usr/src/linux
patch -tp1
cd /usr/src
make menuconfig
(代码成熟度选项)
Code maturity level options  --->
  • Prompt for development and/or incomplete code/drivers
          
  •    Select only drivers expected to compile cleanly
    (网络选项,选择你用的模块,用空格键切换,选择成M,不知道的用默认就可以.)
    Networking  ->
  • Networking support
          
  • Networking options  ->
  • Network packet filtering (replaces ipchains)  ->
  • Network packet filtering (replaces ipchains)  ---> IP: Netfilter Configuration  --->
    (设备驱动程序)
    Device Drivers  ---> SCSI device support  --->SCSI low-level drivers--->  BusLogic SCSI support                                                     
  •    Omit FlashPoint support
    Device Drivers  ---> Network device support  ---> Ethernet (10 or 100Mbit)  --->
  • EISA, VLB, PCI and on board controllers--->
                AMD PCnet32 PCI support
                AMD 8111 (new PCI lance) support
    (文件系统)
    File systems  --->  Second extended fs support
         
  •    Ext2 extended attributes
         
  •      Ext2 POSIX Access Control Lists
         
  •      Ext2 Security Labels
         
  •    Ext2 execute in place support
          Ext3 journalling file system support
         
  •    Ext3 extended attributes
         
  •      Ext3 POSIX Access Control Lists
         
  •      Ext3 Security Labels
         
  • JBD (ext3) debugging support

    !!!保存退出!!!


    7.开始编辑内核
    cd /usr/src/linux
    make
    make modules_install install
    现在你可以去喝杯咖啡看看电视,抽根烟了.呵呵....时间很长啊!!!
    如果你是高手,可以把内核在做的小点,把不该要的都kill掉,该选的都选上.争取做到功能最全,内核最小的境界,哈哈.....
    内核编辑完成
    vi /boot/grub/grub.conf
    把选项
    default=1
    改成
    default=0
    把新内核作为默认启动项
    从新启动系统shutdonw -r now 或者reboot
    启动后选择新的内核2.6.15.4,老的内核2.6.11还保留着,这样你可以在新内核不能启动时,在去老内核下从新编辑
    8.升级iptables
    cd /usr/src/iptables-1.3.5
    export KERNEL_DIR=/usr/src/linux
    export IPTABLES_DIR=/usr/src/iptables-1.3.5
    make BINDIR=/sbin LIBDIR=/lib MANDIR=/usr/share/man install
    9.安装layer7的协议支持
    cd /usr/src/l7-protocols-2006-01-22
    make install
    10.更新ipp2p模块,使他支持更多的协议
    cd /usr/src/ipp2p-0.8.1_rc1
    修改Makefile文件,应该在第36行
    vi Makefile

    IPTABLES_SRC = /usr/src/iptables-1.2.9
    改为
    IPTABLES_SRC = /usr/src/iptables-1.3.5
    make
    cp /usr/src/ipp2p-0.8.1_rc1/libipt_ipp2p.so /lib/iptables
    depmod -a
    11.现在开始测试
    11.1显示内核版本
    uname -r
    显示如下:
    2.6.15.4
    11.2显示iptables版本
    iptables -V
    显示如下:
    iptables v1.3.5
    11.3 字符串匹配,可以用做内容过滤
    iptables -A FORWARD -m string --algo kmp --string "
    www.qq.com
    " -j DROP
    iptables -I FORWARD -d 192.168.3.0/24 -m string --string "宽频影院"  --algo kmp -j DROP
    11.4 Peer-to-Perr 过滤,封杀BT类P2P软件
    iptables -A INPUT -m ipp2p --ipp2p -j DROP
    iptables -A FORWARD -m ipp2p --edk --dc --kazaa --gnu --bit --apple --winmx --soul --ares -j DROP
    11.5 时间匹配
    iptables -A FORWARD -m time --timestart 08:00 --timestop 17:00 -j DROP
    11.6 备注匹配,可以支持最多256个字符
    iptables -I FORWARD -s 192.168.0.100 -p tcp --dport 80 -j DROP -m comment --comment "the bad guy can not online"
    11.7 同时连接个数限制匹配
    iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 10 -j DROP
    iptables -I FORWARD -p tcp --syn --dport 80 -m connlimit --connlimit-above 10 -j DROP
    11.8 ip范围匹配
    iptables -A FORWARD -m iprange --src-range 192.168.0.10-192.168.0.100 -j ACCEPT
    iptables -A FORWARD -m iprange --dst-range 192.168.1.5-192.168.1.124 -j ACCEPT
    11.11 每隔N个匹配
    iptables -t mangle -A PREROUTING -m nth --every 10 -j DROP
    11.12 layer7应用,可以到这里
    http://l7-filter.sourceforge.net
    看layer7的具体用法,l7-protocols里面的协议我只使用了几个
    iptables -A FORWARD -m layer7 --l7proto qq -j ACCEPT
    iptables -I FORWARD -m layer7 --l7proto msn-filetransfer -j DROP
    当用如下命令时有错误,希望高手给解答下,谢谢!!!
    命令:   iptables -I FORWARD -m layer7 --l7proto scoks -j ACCEPT
    错误:   iptables v1.3.5: Couldn't find a pattern definition file for scoks.
    11.13 根据地理位置匹配
    iptables -A INPUT -p tcp --dport 80 -m geoip --src-cc JP,US -j DROP
    iptables -A FORWARD -p tcp --dport 21 -m geoip --src-cc KR -j DROP
    11.14 quota(配额匹配)
    iptables -I FORWARD -s 192.168.0.100 -p tcp --dport 80 -m quota --quota 750 -j DROP
    11.15 网络地址翻译
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    11.16 给数据包打标记和TC流量控制工具相结合
    iptables -A PREROUTING -t mangle -p tcp -j CONNMARK --restore-mark
    iptables -A PREROUTING -t mangle -p tcp -m mark ! --mark 0 -j ACCEPT
    iptables -A PREROUTING -t mangle -p tcp -m ipp2p --ipp2p -j MARK --set-mark 1
    iptables -A PREROUTING -t mangle -p tcp -m mark --mark 1 -j CONNMARK --save-mark
    tc filter add dev eth0 parent 1:0 protocol ip prio 4 handle 1 fw classid 1:11
    tc filter add dev eth1 parent 2:0 protocol ip prio 4 handle 1 fw classid 2:11

    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/61207/showart_483929.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP