#!/bin/bash
#wds
#2007.12.6
clear
echo "Please wait ................................"
kernel=$(uname -r)
version=$(echo $kernel | cut -d. -f2)
if [ "$version" -eq 6 ]
then
dir_down=$(pwd);
dir=$(pwd)/src
linux_bz2=$(ls linux-* | awk -F".tar" '{print $1}');
iptables_bz2=$(ls iptables-* | awk -F".tar" '{print $1}');
patch_bz2=$(ls patch-o-matic-ng-* | awk -F".tar" '{print $1}');
netfilter_bz2=$(ls netfilter-* | awk -F".tar" '{print $1}');
#-----------------------------------------------------------------------------------------------
export KERNEL_DIR=$dir/$linux_bz2;
export IPTABLES_DIR=$dir/$iptables_bz2;
export PATCH_O_MATIC_NG=$dir/$patch_bz2;
#------------------------------------------------------------------------------------------------
[ ! -e /$dir ] && mkdir -p $dir
[ ! -e /$dir/$linux_bz2 ] && tar -jxf ${linux_bz2}.tar.bz2 -C $dir
[ ! -e /$dir/$iptables_bz2 ] && tar -jxf ${iptables_bz2}.tar.bz2 -C $dir
[ ! -e /$dir/$netfilter_bz2 ] && tar -zxf ${netfilter_bz2}.tar.gz -C $dir
[ ! -e /$dir/$patch_bz2 ] && tar -jxf ${patch_bz2}.tar.bz2 -C $dir
#-update-kernel-----------------------------------------------------------------------------------
cd $dir/$linux_bz2
patch -p1 <../$netfilter_bz2/kernel-2.6.13-2.6.16-layer7-2.2.patch > /dev/null
wait
#-update-iptables---------------------------------------------------------------------------------
cd $dir/$iptables_bz2
patch -p1 <../$netfilter_bz2/iptables-layer7-2.2.patch > /dev/null
wait
#-update-patch----------------------------------------------------------------------------------------------
cd $dir/$patch_bz2
echo "y" | ./runme ipp2p
wait
echo "y" | ./runme time
wait
echo "y" | ./runme connlimit
wait
echo "y" | ./runme random
wait
#-make-kernel----------------------------------------------------------------------------------------c
cd $dir/$linux_bz2
echo "`pwd` is you address:"
else
echo "you kernel is not supper"
fi
linux-2.6.14.2内核升级
现在升级内核的方法有很多比如原码升级,rpm升级,yum升级等,我觉的还是原码升级比较专业,可以自己定制自己的内核。
1.编辑环境
虚拟机 VMware Workstation 6.0.0 build-
Red hat 4
Kernel version 2.6.-9-42
Iptables v1.2.11
2.下载原码包
官方网站(可以得到最新的补丁和内核,还有安装说明):
http://www.kernel.org/pub/linux/kernel/v2.6/
http://ftp.netfilter.org/pub/iptables/
http://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/
http://sourceforge.net/projects/l7-filter/
下载后解压缩
3基本安装顺序
0) 配置环境变量
1)生成.config文件
2)给内核打补丁
3)给防火墙打补丁
4)给防火墙增加新特性
5)make menuconfig,把新的选项选上(即第二步“打进去”的选项),保存退出
6)make
7)make modules_install
8)make install
9)编辑/boot/grub/grub.conf,把默认启动改为0(即选择新的内核启动)
10)reboot
11)升级iptables
0) vi profile
export KERNEL_DIR=/home/wds/kernel/linux-2.6.14.2
export IPTABLES_DIR=/home/wds/kernel/iptables-1.3.5
export PATCH_O_MATIC_NG=/home/wds/kernel/patch-o-matic-ng-20060510
黑体字的地方是你放置原码的地方
[wds@localhost kernel]# source profile 倒入环境变量
[wds@localhost kernel]# set | more 查看是否倒入
1) 生成.config文件
这一步也不是必需的,只是为了方便以后的步骤,因为.config文件的作用是纪录“哪 些选项选了,哪些选项没有选”的,仅此而已,如果有兴趣你可以研究一下makefile, 看看.config有什么用最简单生成.config的方法就是执行make menuconfig,然 后什么都不做,保存退出也可以 cp /boot/config-2.6.xxx ./.config
2) 给内核打补丁
进入内核文件夹(linux-2.6.14.2)
patch -p1 <../netfilter-layer7-v2.2/kernel-2.6.13-2.6.16
-layer7-2.2.patch
3) 给防火墙打补丁
进入防火墙目录(iptables-1.3.5):
patch -p1 < ../netfilter-layer7-v2.2/iptables-layer7-2.2.patch
4) 增加新特性
进入(patch-o-matic-ng-20060510)
里面有个patchlets 文件夹为新特性文件夹可以进去看一下都有什么新特性
退回到上一级目录进行新特性的安装,我主要使用ipp2p(防p2p软件)
Time(按时间过滤) connlimit(控制并发) random(随机丢包)
./runme time
./runme ipp2p
./runme connlimit
./runme random
进入内核目录输入make menuconfig 命令会出现上边的图片,具体按下边配置
1. 有SCSI卡(如VMware 中的BusLogic BT946C) 的要把它编译成模块(M) 不然会在make install 出错 。 (其它关于SCSI的选项为内核内建,Buslogic可以选择为模块,只是最后需要制作initrd模块)
Device Drivers --->SCSI device support ---><*> SCSI disk support
Device Drivers --->SCSI device support --->SCSI low-level drivers ---> <*> BusLogic SCSI support
2. Linux Kernel Configuration ---> Networking ---> Networking options ---> Network packet filtering (replaces ipchains) ---> IP: Netfilter Configuration --->
你会发现下面多了几个后面带“(NEW)”字眼的,这就是我们刚才“打进去”的补丁.
3. 其他选项请参照网上帮助.
6) make
保存后退出.并执行make 命令如果你的虚拟机内存大的话可以在make后加参数 -j
后加数字表示增加多少的线程.
7) make modules_install
编译模块………………………………
8) make install
安装……………………………………
9)编辑/boot/grub/grub.conf,把默认启动改为0(即选择新的内核启动)
10) reboot 从新启动计算机
11) 升级防火墙 iptables
Cd /home/wds/iptables-1.3.5 目录.从新加载环境变量source profile ,或
export KERNEL_DIR=/home/wds/ linux-2.6.14.2
export IPTABLES_DIR=/home/wds/iptables-1.3.5
执行命令: make BINDIR=/sbin LIBDIR=/lib MANDIR=/usr/share/man install
执行完后测试: iptables -V 看是否为iptables-1.3.5
11.1 字符串匹配,可以用做内容过滤
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.2 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.3 时间匹配
iptables -A FORWARD -m time --timestart 08:00 --timestop 17:00 -j DROP
11.4 备注匹配,可以支持最多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.5 同时连接个数限制匹配
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.6 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
DOC文件下载:
[attach]10256[/attach]
[ 本帖最后由 ipitx 于 2008-11-9 11:11 编辑 ]
ipitx 于 2008-11-11 16:41:44发表:
我是一个比较好的宣传者.这些都是我找的资料而也.
dejianh 于 2008-11-09 14:53:52发表:
强悍 虚心学习中!!!
OnlyGE 于 2008-11-09 11:22:52发表:
高手啊