loading ...
评论列表 日志列表 访客列表 留言列表
loading...

2007-11-25 | 2.4内核不编译内核Iptables添加模块     朗读全文

For CentOS AS 3.8

1. 安装系统。
因只做网关用,所以选包比较少,只选了编辑器里的VI,和网络里的DHCP,以及开发工具中的内核和原始开发工具。仅此而已。
进入系统用uname –r 命令会看到2.4.21-47.Elsmp ,默认是多处理器,而我的网关是一个CPU的,所以卸掉没用的包
# service sendmail stop
# rpm -e --nodeps kernel-smp
# rpm -e --nodeps kernel-smp-devel
# rpm -e --nodeps sendmial
修改SSH启用root登陆 vi /etc/ssh/sshd.config  启用PermitRootLogin yes
重新启动系统开始配置
# uname -r   (查看当前版本)
2.4.21-47.EL
可以cd  /usr/src 查看是否有这个目录2.4.21-47.EL 和软链 linux_2.4
b. 或者查是否安装了源码包
# rpm -qa|grep kernel
kernel-source-2.4.21-47.EL
如果没有安装,可以在光盘中拷贝过来或安装  rpm -ivh kernel-source-2.4.21-47.i386.rpm. 安装后会在/usr/src/出现linux-2.4连接和linux-2.4.21-47.EL目录.


二.安装说明
处理内核源码.
删除原有的软连接 cp副本来做 如果做错 以后可以从新cp 再重新做
# cp -a linux-2.4.21-47.EL/ ./linux-2.4
# cd /usr/src/linux-2.4
# vi Makefile
    EXTRAVERSION = -47.EL
    EXTRAVERSION = -47.ELcustom 注释这个 改成上面的
# head -n4 Makefile
仔细检查一下版本与 uname -r
# make mrproper
# make menuconfig 直接保存退出
给netfilter打补丁

# cd /usr/src/patch-o-matic-ng-20060509
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme time
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme connlimit
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme iprange
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.5 ./runme ipp2p


加入l7-filter 模块
# cd /usr/src/linux-2.4
# patch -p1 < /usr/src/netfilter-layer7-v2.6/kernel-2.4-layer7-2.6.patch
# cd /usr/src/iptables-1.3.5
# patch -p1 < /usr/src/netfilter-layer7-v2.6/iptables-layer7-2.6.patch
# chmod +x extensions/.layer7-test
l7-filter安装结束

# cd /usr/src/linux-2.4
# make menuconfig
确认
  • Prompt for development and/or incomplete code/drivers要选中
    然后进入Networking options
    再进入IP:Netfilter Configuration 把其想要的选中为模块"M"
    保存退出,给netfilter打补丁完成

    编译netfilter,
    # cd /usr/src/linux-2.4
    # make dep
    # make modules SUBDIRS=net/ipv4/netfilter

    应用新的模块
    # cp -f /usr/src/linux-2.4/net/ipv4/netfilter/*.o /lib/modules/2.4.21-47.EL/kernel/net/ipv4/netfilter/
    此处CentOS系统中无 -f 选项 可手动选 y 进行覆盖

    更新modules.dep
    # depmod -a
    当出现错误时可以把出错的删除.
    例如:rm -rf /lib/modules/2.4.21-47.EL/kernel/net/ipv4/netfilter/ipchains_core.o
    depmod: *** Unresolved symbols in /lib/modules/2.4.21-47.EL/kernel/net/ipv4/netfilter/ipchains_core.o
    depmod: *** Unresolved symbols in /lib/modules/2.4.21-47.EL/kernel/net/ipv4/netfilter/ipfwadm_core.o
    直到再执行 depmod -a 不在出错

    编译安装新的iptables
    # cd /usr/src/iptables-1.3.5
    # export KERNEL_DIR=/usr/src/linux-2.4
    # export IPTABLES_DIR=/usr/src/iptables-1.3.5
    # chmod +x extensions/.ipp2p-test
    # make BINDIR=/sbin LIBDIR=/lib MANDIR=/usr/share/man install

    安装l7-filter协议:
    cd /usr/src/l7-protocols-2006-10-18
    make install


    更新ipp2p模块,使他支持更多的协议         
    # cd /usr/src/ipp2p-0.8.2
    # make
    备份 # cp /lib/iptables/libipt_ipp2p.so /
    # cp /usr/src/ipp2p-0.8.2/libipt_ipp2p.so /lib/iptables/
    # make && make install
    # make && make install
    # depmod -a

    修正modprobe ip_nat_ftp 加载出错
    A:先删除 /lib/modules/2.4.21-47.EL/kernel/net/ipv4/netfilter/ip_nat_core.o
    修改/lib/modules/2.4.21-47.EL/modules.dep,找到 ip_nat_ftp行,删除含有 ip_nat_core 的行,/lib/modules/2.4.21-47.EL/kernel/net/ipv4/ip_nat_core.o
    然后再depmod -a,发现有错误,
    继续删除发生错误的文件,直到depmod -a,没有错误为止


    测试是否成功:
    1、查看 iptables版本
    # iptables -V
    iptables v1.3.5

    查看 ipp2p 版本
    # iptables -m ipp2p -h | grep IPP2P
    IPP2P v0.8.2 options:

    2、IPP2P range
    # iptables -A FORWARD -m iprange --src-range 192.168.1.2-192.168.1.254 -m ipp2p --ipp2p -j DROP

    3、layer 7 ,time ,iprange
    # iptables -A FORWARD -m layer7 --l7proto qq  -m time --timestart 8:00 --timestop 17:30 --days Mon,Tue,Wed,Thu,Fri -m iprange --src-range 192.168.1.5-192.168.1.239 -j DROP

    测试多IP
    iptables -A FORWARD -m multiip --sip 192.168.1.3,192.168.1.8,192.168.1.33 -j DROP

    4、connlimit
    # iptables -I FORWARD -s 192.168.1.15 -p tcp --syn --dport 80 -m connlimit --connlimit-above 3 --connlimit-mask 24 -j DROP

    5、测试域名
    iptables -A FORWARD -m domain --name "sohu.com" -j DROP
  • 评论 (0) |  阅读 (?)  |  固定链接 |  发表于 16:29  | 最后修改于 2007-11-25 16:29

    评论

    正在读取评论信息...
    您还未登录,只能匿名发表评论。或者您可以 登录 后发表。
    *