메뉴 건너뛰기

조회 수 7863 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
iptables를 이용하여 geoip적용하는 방법입니다.

시스템 사양
centos5.3(os는 사실 상관이 없어요.)
iptables 1.4.3 이상
geoip
xtables-addons

wget http://nchc.dl.sourceforge.net/sourceforge/xtables-addons/xtables-addons-1.15.tar.bz2
wget http://www.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
wget http://jengelh.medozas.de/files/geoip/geoip_src.tar.bz2
wget ftp://ftp.netfilter.org/pub/iptables/iptables-1.4.3.2.tar.bz2

이렇게 다운
iptables-1.4.3.2.tar.bz2
압축을 풀고 ./configure 후 make, make install 로 설치
xtables-addons 파일압축을 풀고
./configure --with-xtables=/usr/local 후
make를 하면 centos 5.3의 경우 몇가지 에러가 발생하는데

다음과 같은 오류인 경우 말 그래도 해더에 중복선언이 되어서 발생되는 문제로

make[3]: Entering directory `/usr/src/kernels/2.6.18-128.1.10.el5-x86_64'
CC [M] /root/pp/t/xtables-addons-1.15/extensions/compat_xtables.o
In file included from /root/pp/t/xtables-addons-1.15/extensions/compat_xtables.c:20:
/root/pp/t/xtables-addons-1.15/extensions/compat_skbuff.h:29: error: redefinition of 'skb_reset_network_header'
include/linux/skbuff.h:1016: error: previous definition of 'skb_reset_network_header' was here
/root/pp/t/xtables-addons-1.15/extensions/compat_skbuff.h:33: error: redefinition of 'tcp_hdr'
include/linux/tcp.h:169: error: previous definition of 'tcp_hdr' was here
/root/pp/t/xtables-addons-1.15/extensions/compat_skbuff.h:37: error: redefinition of 'udp_hdr'
include/linux/udp.h:33: error: previous definition of 'udp_hdr' was here
In file included from /root/pp/t/xtables-addons-1.15/extensions/compat_xtables.c:21:
/root/pp/t/xtables-addons-1.15/extensions/compat_xtnu.h:9: error: redefinition of typedef 'bool'
include/linux/types.h:36: error: previous declaration of 'bool' was here
/root/pp/t/xtables-addons-1.15/extensions/compat_xtnu.h:10: error: redeclaration of enumerator 'false'
include/linux/stddef.h:16: error: previous definition of 'false' was here
/root/pp/t/xtables-addons-1.15/extensions/compat_xtnu.h:10: error: redeclaration of enumerator 'true'
include/linux/stddef.h:18: error: previous definition of 'true' was here
/root/pp/t/xtables-addons-1.15/extensions/compat_xtables.c: In function 'xtnu_ip_route_me_harder':
/root/pp/t/xtables-addons-1.15/extensions/compat_xtables.c:376: error: too many arguments to function 'ip_route_me_harder'

=> 다음 부분을 찾아서 주석처리한다.
vim xtables-addons-1.15/extensions/compat_skbuff.h
/*static inline void skb_reset_network_header(struct sk_buff *skb)
{
skb->nh.raw = skb->data;
}
static inline struct tcphdr *tcp_hdr(const struct sk_buff *skb)
{
return (void *)skb_transport_header(skb);
}
static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
{
return (void *)skb_transport_header(skb);
}*/

vim xtables-addons-1.15/extensions/compat_xtnu.h
9~10라인
/*typedef _Bool bool;
enum { false = 0, true = 1, };
*/

마지막으로 vim xtables-addons-1.15/extensions/compat_xtables.c 372라인을 찾아서
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 17) 를
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18) 로 수정
그런뒤에 make , make install 하면 설치 완료...

이제 mkdir -p /var/geoip/LE 로 폴더를 생성하고
geoip_src.tar.bz2
앞축을 풀면 나오는 파일중에 geoip_csv_iv0.pl 파일을 /var/geoip/LE로 복사
cd /var/geoip/LE
해당 폴더에서 GeoIPCountryCSV.zip
파일을 앞축을 푼다.
GeoIPCountryWhois.csv 파일이 있는지 확인하고
./geoip_csv_iv0.pl GeoIPCountryWhois.csv 이렇게 하면 국가별로 KR.iv0 같은 파일이 생성이 됨.
만약 geoip_csv_ip0.pl실행시 에러가 나는 경우
perl -MCPAN -e shell
install Getopt::Long
install IO::Handle
install Text::CSV_XS
를 실행


기존 iptables 1.3.5 버전은 삭제한 후 새로 설치한 iptables 쪽으로 링크를 걸어줍니다. 합니다.
# 기존 버전 삭제
rm -f /sbin/iptables
rm -f /sbin/iptables-save
rm -f /sbin/iptables-restore
rm -f /sbin/ip6tables
rm -f /sbin/ip6tables-save
rm -f /sbin/ip6tables-restore
# 링크 설정
ln -s /usr/local/sbin/iptables /sbin/iptables
ln -s /usr/local/sbin/iptables-save /sbin/iptables-save
ln -s /usr/local/sbin/iptables-restore /sbin/iptables-restore
ln -s /usr/local/sbin/ip6tables /sbin/ip6tables
ln -s /usr/local/sbin/ip6tables-save /sbin/ip6tables-save
ln -s /usr/local/sbin/ip6tables-restore /sbin/ip6tables-restore

모두 정상적으로 실행이 되었다면,
iptables -A INPUT -p tcp --dport 80 -m geoip --src-cc CN -j DROP
해서 정상적으로 동작하는지 확인 후 별도이 메시지가 없으면 성공입니다. :)

  1. No Image

    리눅스 부팅 과정과 커널 패닉 조치요령

    Date2014.02.27 Views8107
    Read More
  2. No Image

    kernel panic 복구

    Date2014.02.27 Views9319
    Read More
  3. No Image

    centos 4.x 데몬

    Date2014.02.27 Views6875
    Read More
  4. No Image

    하드디스크의 속도와 성능테스트강좌 hdparm

    Date2014.02.27 Views7471
    Read More
  5. No Image

    Snort란

    Date2014.02.27 Views7873
    Read More
  6. No Image

    htaccess를 이용한 특정 디렉토리 접근 관리하기

    Date2014.02.27 Views7122
    Read More
  7. No Image

    외부 링크 제한하기

    Date2014.02.27 Views7952
    Read More
  8. No Image

    apache에서 전송 속도 제한하기

    Date2014.02.27 Views6940
    Read More
  9. No Image

    find 명령어로 특정 디렉토리 내 특정 파일들의 특정 문자열 일괄 변경

    Date2014.02.27 Views7195
    Read More
  10. No Image

    URL 포워딩 하는 방법

    Date2014.02.27 Views6958
    Read More
  11. No Image

    ssh timeout 설정

    Date2014.02.27 Views7726
    Read More
  12. No Image

    linux mcrypt 설치 (php 재컴파일 필요)

    Date2014.02.27 Views7824
    Read More
  13. No Image

    apache status 모듈 ( 모니터링 )

    Date2014.02.27 Views8496
    Read More
  14. No Image

    apache 로그정리 (logrotate)

    Date2014.02.27 Views7434
    Read More
  15. No Image

    linux 커널 파라메터 수정

    Date2014.02.27 Views7094
    Read More
  16. No Image

    Mysql 설치시 LinuxThreads 에러 메세지

    Date2014.02.27 Views7496
    Read More
  17. No Image

    리눅스 문자열 치환하기

    Date2014.02.27 Views7807
    Read More
  18. No Image

    suPHP로 웹서버 보안을 강화하자

    Date2014.02.27 Views8781
    Read More
  19. No Image

    CentOS 32Bit 운영체제에서 메모리 4G인식 시키는 방법

    Date2014.02.27 Views7103
    Read More
  20. No Image

    Linux LVM구성하기

    Date2014.02.27 Views8218
    Read More
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 Next
/ 12

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved