|
| FC4下升级内核到2.6.15.4及给netfilter打补丁
1.编辑环境
VMware workstation 5.5.1 (我是自定义的,硬盘是IDE) Fedora Core release 4 Kernel 2.6.11-1.1369_FC4
2.安装FC4系统
安装时选择自定义安装,软件包只选择development tools这个选项,开始安装系统...
3.下载需要的原码包
cd /usr/src
(下载内核源代码) wget -c http://www./pub/linux/ ... ux-2.6.15.4.tar.bz2
(下载netfilter源代码) wget -c http://ftp./pub/iptables/iptables-1.3.5.tar.bz2
(下载netfilter补丁)
wget -c http://ftp./pub/pat ... ng-20060209.tar.bz2
(下载ipp2p源代码,patch-o-ma自带的是0.7.2的,0.8.1_rc1可以支持更多的协议)
wget -c http://www./downloads/ipp2p-0.8.1_rc1.tar.gz
(下载netfilter-layer7源代码) wget -c http://keihanna.urceforge.n ... -layer7-v2.1.tar.gz
(下载netfilter-layer7协议) wget -c http://belnet.dl. ... s-2006-01-22.tar.gz
(下载geoip根据地理位置匹配用的2个文件,我们也把它下载下来,如果你不用,可以不下) wget -c http://people./peej ... 0050410/geoipdb.bin wget -c http://people./peej ... 0050410/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 < /usr/src/netfilter-layer7-v2.1/kernel-2.6.13-2.6.15-layer7-2.1.patch cd /usr/src/iptables-1.3.5 patch -tp1 < /usr/src/netfilter-layer7-v2.1/iptables-layer7-2.1.patch chmod +x /usr/src/iptables-1.3.5/extensions/.layer7-test 6.选择内核模块
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 <M> 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.看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 socks -j ACCEPT 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
12.完成基本测试
终于写完了,好累啊,现在已经是凌晨5:00点了,如果时间够的话我会多做些测试的,明天还要上班.没办法啊!!! 其实还有很多要测试的地方,希望看到这篇文档而且对这个敢兴趣的朋友可以测试下!!! |
|
|