����Linux��
Linux����

��linux as3������iptables+ipp2p����bt��eMule������

����ʱ��:2006-08-16 09:28:26��Դ:��������:��Ԫ
Ϊ�˼�С���縺������bt�ȵ��������ؿ���ͨ��iptables����ipp2p��ģ����ʵ��


/etc/init.d/iptables stop

rpm -q iptables


��ȡiptables ��patch-o-matic-ng
cd /usr/src/
wget http://www.netfilter.org/files/iptables-1.3.3.tar.bz2
wget ftp://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/patch-o-matic-ng-20050331.tar.bz2

��ѹ��������ѹ����
tar xjvf iptables-1.3.3.tar.bz2
tar xjvf patch-o-matic-ng-20051015.tar.bz2

��netfilter�򲹶�
cd /usr/src/linux-2.4
uname -r���ɵõ���2.4.21-15.EL������Ϣ

�޸� Makefile������EXTRAVERSION = -15.ELcustom����Ϊ��EXTRAVERSION = -15.EL��
vi Makefile
VERSION = 2
PATCHLEVEL = 4
SUBLEVEL = 21
EXTRAVERSION = -15.ELcustom

��:
VERSION = 2
PATCHLEVEL = 4
SUBLEVEL = 20
EXTRAVERSION = 2.4.21-15.EL
�����Ƴ�

make mrproper
make oldconfig

���ɣ���make menuconfigʱ����������ڶ��ѡ�����֪�������ѡ�񣬴�ʱ���԰Ѱ�װʱ�������ļ�copy��/usr/src/linux-2.4�У�
cp /boot/config-2.4.* /usr/src/linux-2.4/.config

��netfilter�򲹶�
�⿪patch-o-matic-ng-20051015.tar.bz2 ����,�����Ŀ¼,�ͻᷢ���кܶ�Ŀ¼,��ʵÿ��Ŀ¼��Ӧһ��ģ��.
���ǿ���������ѡ��,���ݲ�ͬ���ֿ�submitted|pending|base|extra,
cd /usr/src/patch-o-matic-ng-20051015

����:KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme base .
��:KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme extra
ִ�к�,������Ƿ��Ѿ�Ӧ�ú���ʾ���Ƿ�Ӧ�ø�ģ��,���������������ģ��,�кܶ����ò��ŵ�,���ҿ��ܺ�ϵͳ�汾�г�ͻ,����������߶�ʮһȫ��ѡ��Ļ�,
һ�㶼���ڱ����ʹ��ʱ����.�����Ƽ���cat /ģ��Ŀ¼��/info ��cat /ģ��Ŀ¼��/help ������,��Ϊ�ʺ��Լ�,��ѡ��.
������������濴����,��Ŀ�ĵ�һ��һ����Ӧ�õ�,������:
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme string ���°汾�Ѿ�û�����ѡ�
ִ�к�,������Ƿ��Ѿ�Ӧ�ú���ʾ���Ƿ�Ӧ�ø�ģ��,��"y"Ӧ��.Ȼ�������һ��
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme comment
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme connlimit
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme time
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme iprange
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme geoip
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme nth
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme ipp2p
KERNEL_DIR=/usr/src/linux-2.4 IPTABLES_DIR=/usr/src/iptables-1.3.3 ./runme quota

����ȫ����ɺ�,
cd /usr/src/linux-2.4
make menuconfig��
ȷ��Prompt for development and/or incomplete code/driversҪѡ��
Ȼ�����Networking options
�ٽ���IP:Netfilter Configuration���ῴ�����Ӻܶ�ģ�飬ÿ�������ĺ��涼�����"NEW",������Ҫ��ѡ��Ϊģ��"M"
���桢�˳������ˣ���netfilter�򲹶��������

����netfilter�
����ֻ��Ҫ����netfilter,����Ҫ���������ں˺�ģ��.������ֻ��Ҫipv4��,ipv6�һ�û�õ�,���Բ�����
cd /usr/src/linux-2.4
make dep
make modules SUBDIRS=net/ipv4/netfilter

����һ����Ŀ¼����ԭ��ģ��,�Է���һ:
mkdir /usr/src/netfilter
cp lib/modules/2.4.21-15.EL/kernel/net/ipv4/netfilter/*.o /usr/src/netfilter/

Ӧ���µ�ģ��
cp -f /usr/src/linux-2.4/net/ipv4/netfilter/*.o lib/modules/2.4.21-15.EL/kernel/net/ipv4/netfilter/

�������modules.dep
depmod -a

���������ʱ,ɾ��û�õ��ļ�
depmod: *** Unresolved symbols in lib/modules/2.4.21-15.EL/kernel/net/ipv4/netfilter/ipchains_core.o
depmod: *** Unresolved symbols in lib/modules/2.4.21-15.EL/kernel/net/ipv4/netfilter/ipfwadm_core.o
ɾ����Щû�õ��ļ�
rm ipchains_core.o
rm ipfwadm_core.o
rm ip_fw_compat.o
rm ip_nat_core.o
rm ip_fw_compat_masq.o
rm ip_nat_helper.o
rm ip_nat_standalone.o
�ڼ���depmod -aֱ�������ִ���

ɾ����Щû�õ��ļ���Щ�����ģ���� netfilter ���ò����������ɾ���ᵼ��ipchains��һЩģ�鲻��ʹ��
����Ҫ��ģ���� /lib/modules/`uname -r`/modules.dep �����й��������� ɾ����Щ�Ժ����� depmod -a��
���������� modules.dep�����������Ͷ��ˣ��Ϳ���ʹ���ˡ�ɾ����Щ�ļ�������������Ҫ��ls -a���鿴


���밲װ�µ�iptables
cd /usr/src/iptables-1.3.3
export KERNEL_DIR=/usr/src/linux-2.4
export IPTABLES_DIR=/usr/src/iptables-1.3.3
make BINDIR=/sbin LIBDIR=/lib MANDIR=/usr/share/man install

���˰�װ������������в���
ipchins����
echo 1 > /proc/sys/net/ipv4/ip_forward :��������ת������
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128 ���������ڲ�����80�˿ڵķ���ת��3128
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 21 -j REDIRECT --to-port 3128 ���������ڲ�����21�˿ڵķ���ת��3128
iptables -t nat -A POSTROUTING -s 192.168.168.0/24 -o eth0 -j SNAT --to xxx.xxx.xxx.xxx

���ݹ���
iptables -I FORWARD -m string --string "��Ѷ" -j DROP
iptables -I FORWARD -s 192.168.3.159 -m string --string "qq.com" -j DROP
iptables -I FORWARD -d 192.168.3.0/24 -m string --string "��ƵӰԺ" -j DROP
iptables -I FORWARD -s 192.168.3.0/24 -m string --string "ɫ��" -j DROP
iptables -I FORWARD -p tcp --sport 80 -m string --string "���" -j DROP

��עӦ��
iptables -I FORWARD -s 192.168.3.159 -p tcp --dport 80 -j DROP -m comment --comment "the bad guy can not online"
iptables -I FORWARD -s 192.168.3.159 -m string --string "qq.com" -j DROP -m comment --comment "denny go to qq.com"

��������Ӧ��
� connlimit ����:��������
--connlimit-above n ����Ϊ���ٸ�
--connlimit-mask n ��������������,Ĭ����connlimit-mask 32 ,��ÿip.
�����Ҫ�������������û�������ʹ��,�Է������������������ÿ��ip�����������...�Ƚ�ʵ��
����:ֻ����ÿ��ipͬʱ5��80�˿�ת��,�����Ķ���:
iptables -I FORWARD -p tcp --syn --dport 80 -m connlimit --connlimit-above 5 -j DROP
����:ֻ����ÿ��ipͬʱ10��80�˿�ת��:
iptables -I FORWARD -p tcp --syn --dport 80 -m connlimit --connlimit-above 10 --connlimit-mask 24 -j DROP
����:Ϊ�˷�ֹDOS̫�����ӽ���,��ô�����������15����ʼ����,�����Ķ���.
/sbin/iptables -A INPUT -s 192.186.1.0/24 -p tcp --syn -m connlimit --connlimit-above 15 -j DROP
/sbin/iptables -A INPUT -s 192.186.1.0/24 -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT

ip��ΧӦ��
iptables -A FORWARD -m iprange --src-range 192.168.1.5-192.168.1.124 -j ACCEPT

ÿ��N��ƥ��
iptables -t mangle -A PREROUTING -m nth --every 10 -j DROP

��ɱBT��P2P����ֻҪһ��: iptables -A FORWARD -m ipp2p --ipp2p -j DROP ��:
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

���ƥ��
iptables -I FORWARD -s 192.168.3.159 -p tcp --dport 80 -m quota --quota 500 -j DROP
iptables -I FORWARD -s 192.168.3.159 -p tcp --dport 80 -m quota --quota 500 -j ACCEPT
���Ͼ�����ͨ��,ֻ��geoip��geoipdb.binû���ص�,����û����
�ڴ˽�Ϊ�׸�שͷ,�����Ӧ��,Ҫ�����Լ�����Ҫ����ϸ��������ģ����.

��iptables -nL �鿴ipp2p�Ѿ���Ч
��������

���� 0 ������