3. 설치하기

리눅스 커널에 iptables와 bridge패치를 하고 컴파일을 할 것이다. 모든 작업은 root로 한다.

3.1. 리눅스 커널 패치

커널 소스는 /usr/src/linux 에 풀어 놓는다.
# mv linux-2.4.19.tar.bz2 /usr/src
#cd /usr/src
/usr/src# tar vjxf linux-2.4.19.tar.bz2            압축을 푼다. bunzip2 패키지가 필요하다.
/usr/src# ln -s linux-2.4.19 linux                 압축이 풀린 디렉토리를 linux라는 이름으로 심볼릭 링크를 생성한다.

bridge 패치를 패치한다.
# mv bridge-nf-0.0.7-against-2.4.19.diff /usr/src
# cd /usr/src/linux
/usr/src/linux# patch -p1 < ../bridge-nf-0.0.7-against-2.4.19.diff

iptable 패치는 patch-o-matic 이라는 방식으로 커널 패치를 한다.
# tar vjxf patch-o-matic-20030107.tar.bz2
# cd cd patch-o-matic-20030107
# ./runme extra
Hey! KERNEL_DIR is not set.
Where is your kernel? [/usr/src/linux]              커널 소스를 /usr/src에 풀어서 linux라고 링크를 걸었다면 엔터를 친다
                                                    아니면 실제 커널이 있는 경로를 적어준다
다음과 같이 나올 것이다.
Welcome to Rusty's Patch-o-matic!

Each patch is a new feature: many have minimal impact, some do not.
Almost every one has bugs, so I don't recommend applying them all!
-------------------------------------------------------
Already applied: submitted/01_2.4.19

Testing... 02_2.4.20.patch NOT APPLIED ( 17 missing files)
The submitted/02_2.4.20 patch:
   Authors: Various (see below)
   Status: Included in stock 2.4.20 kernel
   
   This big patch contains all netfilter/iptables changes between stock kernel
   versions 2.4.19 and 2.4.20.
   
   submitted/DSCP.patch
   + New DSCP target to mangle table (Harald Welte + Matthew G. Marsh)
   submitted/ECN.patch
   + New ECN target to mangle table (Harald Welte)
   submitted/REJECT_mark.patch
   + Don't copy nfmark value of old packet (Henrik Nordstrom)
   submitted/ahesp-static.patch
   + Fix static build of ahesp match (Paul P Komkoff Jr)
   submitted/conntrack+nat-helper-unregister.patch
   + Fix helper unregister in case of clashing ports (Harald Welte)
   submitted/conntrack.patch
   + Add new 'conntrack' match (Marc Boucher)
   submitted/dscp.patch
   + New 'dscp' match (Harald Welte)
   submitted/ecn.patch
   + New 'ecn' match (Harald Welte)
   submitted/helper.patch
   + New 'helper' match (Martin Josefsson, Harald Welte)
   submitted/ip6tables-exthdr-bug.patch.ipv6
   + Fix broken ipv6 extensionheader parser (Andras Kis-Szabo)
   submitted/ipv6-agr.patch.ipv6
   + New ip6tables 'eui64' match (Andras Kis-Szabo)
   submitted/length.patch.ipv6
   + New ip6tables 'length' match (Imran Patel, James Morris)
   submitted/log-tunnel-fix.patch.ipv6
   + Fix ip6tables 'LOG' target MAC address in case of tunnels
   (Peter Bieringer, Andras Kis-Szabo)
   submitted/nat-memoryleak-fix.patch
   + Fix memoryleak at iptable_nat unload time (zhongyu)
   submitted/ownercmd.patch
   + Extend 'owner' match to match cmdline (Marc Boucher)
   submitted/pkttype.patch
   + New 'pkttype' match (Michal Ludvig)
   submitted/ulog-nlgroup-shift-fix.patch
   + Fix error with shifting nlgroup in ULOG target (Harald Welte)
   submitted/ulog-sparc-bitops-fix.patch
   + Include linux/bitops.h instead of asm/bitops.h
   submitted/z-newnat16.patch
   + Redesign of conntrack and nat helper framework, for more info see http://cvs.netfilter.org/cgi-bin/cvsweb/netfilter/documentation/newnat-summary.txt
   (Harald Welte, Jozsef Kadlecsik, and others)
   submitted/z-newnat_assertfix.patch
   + Fix erroneously printed ASSERT messages when debugging of newnat
   enabled (Martin Josefsson)
   submitted/z-newnat_changeexpect-lockfix.patch
   + Fix locking bug in ip_conntrack_change_expect() (Martin Josefsson)
   Further changes, not previuosly in patch-o-matic:
   + ip6tables usage counter fix (Harald Welte)
   + ip_queue cleanup (James Morris)
   + minor spelling fixes
   + __constant_htons() macro changes
   + ipt_unclean: srcport _can_ be zero
   + yet another ipchains GFP_ATOMIC fix
-----------------------------------------------------------------
Do you want to apply this patch [N/y/t/f/a/r/b/w/v/q/?]
엔터를 친다

iptable패치에는 내용이 여러 가지가 존재한다. y를 누르면 패치가 된다. 그러나 전부 패치를 하면 안 된다. 나중에 커널을 컴파일 하면 에러가 나기 때문에 꼭 필요한 것만 y를 눌러 패치 한다. b 를 누르면 뒤로 돌아갈 수 있다.

지금 패치 할 것은 패킷에서 String을 검색하여 패킷을 버리거나 거부 하는 String match support 이다. 이것을 이용하면 Nimda, CodeRed 등의 웜이나 바이러스의 패킷을 차단 할 수 있다.

계속 엔터를 쳐서 가다 보면 아래와 같은 화면이 나올것 이다.
Welcome to Rusty's Patch-o-matic!

Each patch is a new feature: many have minimal impact, some do not.
Almost every one has bugs, so I don't recommend applying them all!
-------------------------------------------------------
Already applied: submitted/01_2.4.19

Testing... string.patch NOT APPLIED ( 2 missing files)
The extra/string patch:
   Author: Emmanuel Roger <winfield@freegates.be>
   Status: Working, not with kernel 2.4.9
   
   This patch adds CONFIG_IP_NF_MATCH_STRING which allows you to
   match a string in a whole packet.
   
   THIS PATCH DOES NOT WORK WITH KERNEL 2.4.9 !!!
   
-----------------------------------------------------------------
Do you want to apply this patch [N/y/t/f/a/r/b/w/v/q/?] 

여기서 y를 누르면 String match가 패치 된다.

계속 엔터를 치면 다른 패치들이 나온다. 필요한 것들이 있으면 패치한다.

3.2. 커널 옵션 설정하기

iptables 와 bridge기능을 사용할 수 있게 커널 옵션을 설정한다. 사용 할 랜카드 2개도 설정을 할 것이다.

커널 옵션은 다음과 같이 설정한다. menuconfig 를 이용하려면 데비안에서는 libncurses5-dev 패키지가 꼭 필요하다. 데비안에서 패키지는 apt-get 나 dselect를 이용하여 설치한다. 다른 배포판도 마찬가지 이다. 대부분의 배포판에서는 기본적으로 설치되어 있을 것이다.
# cd /usr/src/linux
/usr/src/linux# make menuconfig

랜카드 드라이버 설정. 본인이 사용하고 있는 랜카드는 3Com 590, Intel EtherPress/100 이다. 각자 가지고 있는 랜카드를 설정하자.
Network device support  --->
  Ethernet (10 or 100Mbit)  --->
    [*] Ethernet (10 or 100Mbit)                                                                    
    < >   Sun Happy Meal 10/100baseT support                                                            
    < >   Sun GEM support                                                                               
    [*]   3COM cards                                                                                
    < >     3c501 "EtherLink" support                                                                   
    < >     3c503 "EtherLink II" support                                                                
    < >     3c505 "EtherLink Plus" support                                                              
    < >     3c507 "EtherLink 16" support (EXPERIMENTAL)                                                 
    < >     3c509/3c529 (MCA)/3c579 "EtherLink III" support                                             
    < >     3c515 ISA "Fast EtherLink"                                                                  
    <*>     3c590/3c900 series (592/595/597) "Vortex/Boomerang" support                                 
    < >   AMD LANCE and PCnet (AT1500 and NE2100) support                                               
    [ ]   Western Digital/SMC cards                                                                 
    [ ]   Racal-Interlan (Micom) NI cards                                                           
    < >   AT1700/1720 support (EXPERIMENTAL)                                                            
    < >   DEPCA, DE10x, DE200, DE201, DE202, DE422 support                                              
    < >   HP 10/100VG PCLAN (ISA, EISA, PCI) support                                                    
    [ ]   Other ISA cards                                                                           
    [*]   EISA, VLB, PCI and on board controllers                                                   
    < >     AMD PCnet32 PCI support                                                                     
    < >     Adaptec Starfire/DuraLAN support                                                            
    < >     Ansel Communications EISA 3200 support (EXPERIMENTAL)                                       
    < >     Apricot Xen-II on board Ethernet                                                            
    < >     CS89x0 support                                                                              
    < >     DECchip Tulip (dc21x4x) PCI support                                                         
    < >     TOSHIBA TC35815 Ethernet support                                                            
    < >     Generic DECchip & DIGITAL EtherWORKS PCI/EISA                                               
    < >     Digi Intl. RightSwitch SE-X support                                                         
    < >     Davicom DM910x/DM980x support                                                               
    <*>     EtherExpressPro/100 support                                                                 
    < >     Myson MTD-8xx PCI Ethernet support                                                          
    < >     National Semiconductor DP8381x series PCI Ethernet support                                  
    < >     PCI NE2000 and clones support (see help)                                                    
    < >     RealTek RTL-8139 C+ PCI Fast Ethernet Adapter support (EXPERIMENTAL)                        
    < >     RealTek RTL-8139 PCI Fast Ethernet Adapter support                                          
    < >     SiS 900/7016 PCI Fast Ethernet Adapter support                                              
    < >     SMC EtherPower II                                                                           
    < >     Sundance Alta support                                                                       
    < >     TI ThunderLAN support                                                                       
    < >     VIA Rhine support                                                                           
    < >     Winbond W89c840 Ethernet support                                                            
    [ ]   Pocket and portable adapters

bridge 기능을 사용하기 위한 설정
Networking options  --->
  <*> Packet socket                                                                        
    [ ]   Packet socket: mmapped IO                                                          
    < > Netlink device emulation                                                             
    [*] Network packet filtering (replaces ipchains)                                         
    [ ]   Network packet filtering debugging                                                   
    [*] Socket Filtering                                                                     
    <*> Unix domain sockets                                                                  
    [*] TCP/IP networking                                                                    
    [*]   IP: multicasting                                                                   
    [ ]   IP: advanced router                                                                
    [ ]   IP: kernel level autoconfiguration                                                 
    < >   IP: tunneling                                                                        
    < >   IP: GRE tunnels over IP                                                            
    [ ]   IP: multicast routing                                                              
    [ ]   IP: ARP daemon support (EXPERIMENTAL)                                              
    [ ]   IP: TCP Explicit Congestion Notification support                                     
    [ ]   IP: TCP syncookie support (disabled per default)                                     
      IP: Netfilter Configuration  --->                                                        
    < >   The IPv6 protocol (EXPERIMENTAL)                                                     
    < >   Kernel httpd acceleration (EXPERIMENTAL)                                             
    [ ] Asynchronous Transfer Mode (ATM) (EXPERIMENTAL)                                        
    < > 802.1Q VLAN Support                                                                    
    ---                                                                                        
    < > The IPX protocol                                                                       
    < > Appletalk protocol support                                                           
    Appletalk devices  --->
    < > DECnet Support                                                                         
    <*> 802.1d Ethernet Bridging                                                             
    [*]   netfilter (firewalling) support                                                    
    < > CCITT X.25 Packet Layer (EXPERIMENTAL)                                               
    < > LAPB Data Link Driver (EXPERIMENTAL)                                                 
    [ ] 802.2 LLC (EXPERIMENTAL)                                                             
    [ ] Frame Diverter (EXPERIMENTAL)                                                        
    < > Acorn Econet/AUN protocols (EXPERIMENTAL)                                            
    < > WAN router                                                                           
    [ ] Fast switching (read help!)                                                          
    [ ] Forwarding between high speed interfaces                                             
    QoS and/or fair queueing  --->                                                           
    Network testing  --->

iptables에서 사용 할 각각의 기능들을 모듈로 설정한다. 모듈 설정은 스페이스 바로 두 번 선택하면 M이라고 표시된다. 이것이 모듈설정이다. *로 설정을 하면 커널로 완전히 포함된다. 모듈로 설정하면 꼭 필요한 것만 쓸 수 있게 하므로 메모리 낭비를 막을 수 있다.
Networking options  --->
  IP: Netfilter Configuration  --->
    <M> Connection tracking (required for masq/NAT)                                             
    <M>   FTP protocol support                                                                  
    <M>   IRC protocol support                                                                  
    <M> Userspace queueing via NETLINK (EXPERIMENTAL)                                           
    <*> IP tables support (required for filtering/masq/NAT)                                     
    <M>   limit match support                                                                   
    <M>   MAC address match support                                                             
    <M>   netfilter MARK match support                                                          
    <M>   Multiple port match support                                                           
    <M>   TOS match support                                                                     
    <M>   AH/ESP match support                                                                  
    <M>   LENGTH match support                                                                  
    <M>   TTL match support                                                                     
    <M>   tcpmss match support                                                                  
    <M>   Connection state match support                                                        
    <M>   Unclean match support (EXPERIMENTAL)                                                  
    <M>   String match support (EXPERIMENTAL)                                                   
    <M>   Owner match support (EXPERIMENTAL)                                                    
    <M>   Packet filtering                                                                      
    <M>     REJECT target support                                                               
    <M>     MIRROR target support (EXPERIMENTAL)                                                
    <M>   Full NAT                                                                              
    <M>     MASQUERADE target support                                                           
    <M>     REDIRECT target support                                                             
    [*]     NAT of local connections (READ HELP)                                            
    <M>     Basic SNMP-ALG support (EXPERIMENTAL)

3.3. 커널 컴파일

이제 패치한 커널을 컴파일 할 차례 이다.

리눅스 배포판이 데비안일 경우 커널 패키지를 만들어서 커널을 설치하는 것이 편하다. kernel-package 라는 패키지가 필요하다.
# cd /usr/src/linux
/usr/src/linux# make-kpkg --revision=1.0 binary-arch              이렇게 하면 /usr/src에 커널 헤더와 커널 이미지 패키지가 생성된다.
/usr/src/linux# cd ..
/usr/src# ls
-rw-r--r--    1 root     root        30158 Mar 27 20:39 bridge-nf-0.0.7-against-2.4.19.diff
-rw-r--r--    1 root     src       3961230 Apr  9 22:58 kernel-headers-2.4.19_1.0_i386.deb            커널 헤더
-rw-r--r--    1 root     src       1274482 Apr  9 22:58 kernel-image-2.4.19_1.0_i386.deb              커널 이미지
lrwxrwxrwx    1 root     src            12 May 14 04:24 linux -> linux-2.4.19
drwxr-xr-x   15 573      573           888 Jun 29 06:38 linux-2.4.19
/usr/src# dpkg -i kernel-headers-2.4.19_1.0_i386.deb
/usr/src# dpkg -i kernel-image-2.4.19_1.0_i386.deb

커널 이미지를 설치 할 때 부팅 디스크를 만들라는 곳에는 N으로 취소를 하고 /vmlinuz 라고 링크를 만든다고 할 때는 Y를 눌러
링크를 만든다

부트로더로 lilo를 사용할 경우
# lilo
Grub를 사용할 경우 /boot/grub/menu.lst 파일을 수정해서 새 커널로 부팅 될 수 있도록 한다

데비안이 아닌 리눅스 배포판의 경우
# cd /usr/src/linux
/usr/src/linux# make dep && make bzImage && make modules && make modules_install
/usr/src/linux# cd arch/i386/boot/
/usr/src/linux/arch/i386/boot# cp bzImage /boot/vmlinuz-2.4.19

부트로더를 lilo를 사용할 경우
/etc/lilo.conf 설정을 변경 한다. 아래와 같은 부분이 있을 것이다.
image=/boot/vmlinuz-2.4.19
        label=Linux
저장을 하고
# lilo

Grub를 사용할 경우
/boot/grub/menu.lst 아래와 같은 부분이 있는데 컴파일한 커널 이미지의 경로를 적어준다.
title Linux
root (hd0,1)ㅔ
kernel /boot/vmlinuz-2.4.19 root=/dev/hda2

3.4. Bridge utils 설치

bridge 기능을 사용하기 위한 프로그램 설치

bridge utils 소스 컴파일 및 설치
# tar vxzf bridge-utils-0.9.6.tar.gz
# cd bridge-utils
~/bridge-utils# ./configure
~/bridge-utils# make
~/bridge-utils# make install

3.5. iptables 설치

패킷제어 명령을 내리기위한 iptables설치

iptables 소스 컴파일 및 설치, KERNEL_DIR=/usr/src/linux 에는 커널 소스가 있는 경로를 적어준다.
# tar vjxf iptables-1.2.8.tar.bz2
# cd iptables-1.2.8
~/iptables-1.2.8# make KERNEL_DIR=/usr/src/linux
~/iptables-1.2.8# make install KERNEL_DIR=/usr/src/linux
~/iptables-1.2.8# make install-devel