본문 바로가기
운영체제 (LNX,WIN)

DDoS 대응을 위한 iptables GeoIP 모듈 설치 및 관리 프로세스

by 날으는물고기 2009. 7. 1.

DDoS 대응을 위한 iptables GeoIP 모듈 설치 및 관리 프로세스

728x90

iptables GeoIP 모듈이란?

iptables의 GeoIP 모듈은 네트워크 패킷의 소스 또는 목적지 IP 주소를 국가별로 필터링할 수 있게 해주는 기능입니다. 예를 들어, 특정 국가에서 발생하는 공격이나 불필요한 접근을 차단할 때 효과적입니다.

  • 활용사례
    • 특정 국가의 IP를 통해 유입되는 트래픽 차단
    • DDOS 공격에 대한 국가 단위 차단 대응
    • 서비스 지역 제한 정책 구현

작업 준비

필요 소스파일

  • Linux Kernel 2.6.27.4
    • ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.27.4.tar.bz2
  • iptables 1.4.2
    • http://ftp.netfilter.org/pub/iptables/snapshot/iptables-20081028.tar.bz2
  • patch-o-matic-ng
    • http://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/patch-o-matic-ng-20081028.tar.bz2

설치 위치

cd /usr/src
tar xvfj linux-2.6.27.4.tar.bz2
ln -s linux-2.6.27.4 linux

tar xvfj iptables-20081028.tar.bz2
ln -s iptables-20081028 iptables

tar xvfj patch-o-matic-ng-20081028.tar.bz2

GeoIP 패치 적용

iptables 환경 구성 후 패치 적용
패치를 적용하기 전에 반드시 iptables 소스에서 configure를 실행합니다.

cd /usr/src/iptables
./configure

cd /usr/src/patch-o-matic-ng-20081028
./runme --download
./runme geoip

connlimit는 커널 2.6.23 이후부터 기본 지원이므로 별도 패치 불필요.

커널 컴파일 및 GeoIP 활성화

기존 커널 설정 가져오기

cd /usr/src/linux
cp /boot/config-$(uname -r) .config
make menuconfig
  • 메뉴 이동
    Networking
    └── Networking option
          └── Network packet filtering framework (Netfilter)
                ├── Core Netfilter Configuration (모듈형태<M>)
                └── GeoIP match support (모듈형태<M> 체크)

커널 컴파일

make bzImage
make modules
make modules_install
make install

시스템 재부팅 후 모듈 확인

depmod -a
modprobe xt_geoip
lsmod | grep geoip

iptables 소스 컴파일 (GeoIP 확장 활성화)

컴파일 진행

cd /usr/src/iptables
./configure
make

이 과정에서 오류 발생 시 다음 조치를 합니다.

 

발생한 오류 해결법

오류 1: xt_geoip.h 파일 없음

cp /usr/src/patch-o-matic-ng-20081028/patchlets/geoip/linux-2.6/include/linux/netfilter/xt_geoip.h \
   /usr/src/iptables/include/linux/netfilter/
make

오류 2: IPTABLES_VERSION 미선언 문제

아래 파일을 수정합니다.

/usr/src/iptables/include/xtables.h

다음 코드를 추가합니다.

#define IPTABLES_VERSION "1.4.2"

재컴파일 및 설치

make
make install

기존 rpm iptables 명령어 교체 작업

ln -sf /usr/local/sbin/iptables /sbin/iptables
ln -sf /usr/local/sbin/iptables-save /sbin/iptables-save
ln -sf /usr/local/sbin/iptables-restore /sbin/iptables-restore
ln -sf /usr/local/sbin/ip6tables /sbin/ip6tables
ln -sf /usr/local/sbin/ip6tables-save /sbin/ip6tables-save
ln -sf /usr/local/sbin/ip6tables-restore /sbin/ip6tables-restore
ln -sf /usr/local/sbin/iptables-multi /sbin/iptables-multi
ln -sf /usr/local/sbin/ip6tables-multi /sbin/ip6tables-multi

확인

iptables -V

GeoIP DB 설치

국가별 IP 정보를 DB로 변환하여 제공합니다.

 

툴 다운로드 및 빌드

wget http://people.netfilter.org/peejix/geoip/tools/csv2bin-20041103.tar.gz
tar -xvzf csv2bin-20041103.tar.gz
cd csv2bin
make

최신 GeoIP CSV 다운로드 및 변환

wget http://www.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
unzip GeoIPCountryCSV.zip
chmod 755 GeoIPCountryWhois.csv
./csv2bin GeoIPCountryWhois.csv

생성된 DB파일 복사

mkdir -p /var/geoip
cp geoipdb.bin geoipdb.idx /var/geoip/

iptables GeoIP 모듈 활용 예시

특정 국가 차단 예시 명령어

iptables -A INPUT -m geoip --src-cc CN -j DROP

위 명령어는 중국(CN)에서 오는 모든 연결을 차단합니다.

보안 점검 및 가이드

다음 사항을 내부 보안팀 및 사용자에게 제시할 점검 가이드로 활용 가능합니다.

  • 주기적으로 GeoIP DB 최신화
  • DB 파일 접근 권한 확인 (/var/geoip 디렉토리 접근 통제)
  • GeoIP 룰 적용 시 서비스 운영 영향도 평가 및 예외 정책 관리
  • 커널 패치 시 기존 설정 파일(.config) 백업 필수
  • iptables 신규 모듈 추가 시 반드시 기존 버전과 충돌 테스트 수행
  • iptables 적용 후 방화벽 룰 세트 정기적 검토 및 로깅 활성화
  • GeoIP 룰 적용 전후 패킷 드롭 상태 모니터링 수행
728x90
그리드형

댓글