[네트워크][보안] linux bridge firewall 서버 구축 하기 [1]

리눅스로 Bridge Firewall 만들기

이재홍

            pyrasis (at) chol.com

          

리눅스로 BridgeFirewall을 만들어 보자

고친 과정

고침 0.1 2003-06-28 고친이 pyrasis

최초 작성

고침 0.2 2003-08-29 고친이 pyrasis

커널 옵션 부분에서 빠진 부분 추가. Code maturity level options 부분

고침 0.3 2003-09-16 고친이 pyrasis

커널 로그 데몬 설정 (화면에 출력되는 메세지 조절)

——————————————————————————–

차례

1. 서문

1.1. 저작권 정보

1.2. 책임의 한계

1.3. 감사의 글

1.4. 피드백

2. 설치 준비 작업

2.1. 네트워크 구성

2.2. 준비할 것들

2.3. 사용 할 각각의 파일들 구하기

3. 설치하기

3.1. 리눅스 커널 패치

3.2. 커널 옵션 설정하기

3.3. 커널 컴파일

3.4. Bridge utils 설치

3.5. iptables 설치

4. 실행 스크립트 및 세부 설정

4.1. 패킷에 대한 기본적인 이해

4.2. bridge 및 iptables 스크립트 작성

4.3. 정책변경

4.4. 기본적인 명령 사용법

4.5. 자주 사용되는 것들

4.6. 커널 로그 데몬 설정

1. 서문

네트워크 구조를 변경하지 않고 쉽게 방화벽을 설치할 수 있는 Bridge Firewall을 만들어서 사용하자.

본인은 방화벽을 만들면서 수많은 시행착오를 겪었고 많은 문서들을 보아 왔다. 하지만 워낙 네트워크 상황이 다양하다 보니 문서대로 잘 되지 않는 경우도 많았고, 환경도 많이 다른 것도 많았다. 이 문서를 보고 한번에 알맞는 방화벽을 만든다고는 장담할 수는 없다. 하지만 조금이나마 처음 해보는 사람들에게 도움이 되고자 이 문서를 작성 한다.

이 문서는 보호할 네트워크는 공인 IP를 사용한다는 전제 하에 만들어진 문서이다. 본인이 NAT를 사용해보지 않아 NAT에 관한 문서는 차후 준비하겠다.

——————————————————————————–

1.1. 저작권 정보

Copyright (C) 2003 이재홍

이 문서는 GNU Free Documentation License 버전 1.1 혹은 자유 소프트웨어 재단에서 발행한 이후 판의 규정에 따르며 저작권에 대한 본 사항이 명시되는 한 어떠한 정보 매체에 의한 본문의 전재나 발췌도 무상으로 허용됩니다.

——————————————————————————–

1.2. 책임의 한계

본 저자는 문서의 내용이 야기할 수 있는 어떠한 결과에 대해서도 책임을 지지 않습니다. 본 문서에서 내포하고 있는 정보들 및 예제들은 여러분이 알아서 활용하십시오. 비록 최선을 다했으나 이 문서는 틀린 점이나 오류가 있을 수도 있습니다. 만약 여러분이 틀린 점을 발견했다면 꼭 저에게 알려 주시기 바랍니다.

——————————————————————————–

1.3. 감사의 글

이 문서를 작성하는데 도움을 주신 많은 분들에게 감사드립니다.

KLDP의 네트워킹/방화벽 디렉토리의 글들의 도움을 많이 받았습니다. 그곳의 글을 써주시고 변역해주신 모든 분들께 진심으로 감사 드립니다.

——————————————————————————–

1.4. 피드백

이 문서에 대한 발전적인 제안이나 수정사항, 문제점 등에 대한 피드백은 언제든지 환영합니다. <pyrasis (at) chol.com>로 메일을 보내 주십시오.

——————————————————————————–

2. 설치 준비 작업

설치를 위해 준비해야 할 것들.

——————————————————————————–

2.1. 네트워크 구성

방화벽이 없는 네트워크 구성        라우터 ——— 스위칭 허브 ———– PC

                                    |

                                    ———– 서버  

방화벽이 설치 될 네트워크 구성       라우터 ————- eth0-(Bridge Firewall)-eth1 — 스위칭 허브 ——– PC

             (Cross Cable)                                             |

                                                                       ——– 서버  

——————————————————————————–

2.2. 준비할 것들

본인이 Bridge Firewall을 설치한 리눅스 배포판은 데비안 리눅스 3.0 r1(2003년 6월)이며 커널 버전은 2.4.19이다. 다른 배포판에서도 무리 없이 설치할 수 있다.

테스트 해본 하드웨어 사양은 셀러론 1GHz 256RAM 이고 현재 50대 정도의 컴퓨터가 방화벽 뒤에서 인터넷을 사용하고 있다. 사용하고 있는 랜카드는 3Com 3c590, Intel EtherExpress/100이다.

꼭 필요한 것들

리눅스 커널 2.4.19

랜카드 2장

크로스 케이블, 다이렉트 케이블

bridge 커널 패치

bridge utils

iptables 커널 패치

iptables 소스

——————————————————————————–

2.3. 사용 할 각각의 파일들 구하기

bridge 커널 패치 및 bridge utils

Linux ethernet bridging http://bridge.sourceforge.net

bridge-nf-0.0.7-against-2.4.19.diff

bridge-utils-0.9.6.tar.gz

iptables 커널 패치 및 iptables

netfilter/iptables http://www.netfilter.org

patch-o-matic-20030107.tar.bz2

iptables-1.2.8.tar.bz2

리눅스 커널 소스

The Linux Kernel Archives http://www.kernel.org

linux-2.4.19.tar.bz2

위의 파일들을 /root에 받는다.

——————————————————————————–

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

커널 성숙도 옵션. 이 부분을 체크 해야 아래 옵션들이 모두 나오게 된다. Code maturity level options  —>

  [*] Prompt for development and/or incomplete code/drivers

랜카드 드라이버 설정. 본인이 사용하고 있는 랜카드는 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

——————————————————————————–

서진우

슈퍼컴퓨팅 전문 기업 클루닉스/ 상무(기술이사)/ 정보시스템감리사/ 시스존 블로그 운영자

You may also like...

1 Response

  1. smooth jazz 말해보세요:

    smooth jazz

페이스북/트위트/구글 계정으로 댓글 가능합니다.