메뉴 건너뛰기

조회 수 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

    ftp passive mode 설정

    Date2014.02.27 Views8095
    Read More
  2. No Image

    APM 소스 설치

    Date2014.02.27 Views8068
    Read More
  3. No Image

    APM 소스 설치

    Date2014.02.27 Views7735
    Read More
  4. No Image

    vsftp 이란?

    Date2014.02.27 Views9258
    Read More
  5. No Image

    파일 속성 명령어 : chattr, lsattr

    Date2014.02.27 Views9614
    Read More
  6. No Image

    history 파일 삭제 제한하기

    Date2014.02.27 Views7778
    Read More
  7. No Image

    apache + mysql 자동 실행 방법 (소스설치)

    Date2014.02.27 Views7966
    Read More
  8. No Image

    도메인 포워딩 설정

    Date2014.02.27 Views7968
    Read More
  9. No Image

    리눅스 보안 Tip

    Date2014.02.27 Views8785
    Read More
  10. No Image

    SQL 인젝션 복구 쿼리

    Date2014.02.27 Views8248
    Read More
  11. No Image

    외부에서 apache 정보 못보도록 설정하기

    Date2014.02.27 Views8013
    Read More
  12. No Image

    도메인에 자동으로 www 붙도록 설정하기

    Date2014.02.27 Views7581
    Read More
  13. No Image

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

    Date2014.02.27 Views7136
    Read More
  14. No Image

    iptable에서 TCP SYN Flooding 차단 설정

    Date2014.02.27 Views9555
    Read More
  15. No Image

    yum rpmforge 등록하기

    Date2014.02.27 Views7806
    Read More
  16. No Image

    iptables GEOIP 모듈 설치. (국가별 IP 차단)

    Date2014.02.27 Views7863
    Read More
  17. No Image

    tmp 보안 셋팅

    Date2014.02.27 Views7086
    Read More
  18. No Image

    Linux LVM구성하기

    Date2014.02.27 Views8218
    Read More
  19. No Image

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

    Date2014.02.27 Views7103
    Read More
  20. No Image

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

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

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved