메뉴 건너뛰기

조회 수 7861 추천 수 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
해서 정상적으로 동작하는지 확인 후 별도이 메시지가 없으면 성공입니다. :)

List of Articles
번호 제목 날짜 조회 수
56 원격 접속 FreeNX (NOMACHINE) 설치/접속 (vnc 보다 훨 2014.02.27 12306
55 find 명령어 정리 2014.02.27 7320
54 yum 업데이트 빠르게 하기 (yum-fastestmirror 플러그인 2014.02.27 7748
53 bash 스크립트에서 네트워크 정보 확인하기 2014.02.27 14050
52 리눅스 - 동시접속자 확인 방법 2014.02.27 7699
51 특정 데몬의 메모리 점유율 확인하기 2014.02.27 8051
50 리눅스에서 윈도우 파일시스템 마운트하기 2014.02.27 7836
49 find명령과 grep명령을 이용하여 파일안의 문자열 찾기 2014.02.27 7287
48 SAMBA 설치 2014.02.27 7314
47 Linux 사용자 계정 추가 및 도메인 연결과정 2014.02.27 7322
46 apache, mod_ssl 설치 (apache 1.3.37버전) 2014.02.27 7660
45 리눅스 NFS (네트워크 파일 시스템 ) 설치하기 2014.02.27 7110
44 mod_expires 모듈 추가 및 이미지 캐싱 설정방법 2014.02.27 7862
43 대용량 HDD 파티셔닝(Mass storage Partitioning) 2014.02.27 7351
42 webmin 설치하기 2014.02.27 7482
41 webmin 설치하기 file 2014.02.27 8710
40 LINUX - 특정 파일이 속한 RPM 패키지 확인 및 설정 파일 경로 2014.02.27 7940
39 ethtool을 이용한 랜카드 설정 2014.02.27 7929
38 telnet 설정하기 2014.02.27 7021
37 리눅스 부팅 과정과 커널 패닉 조치요령 2014.02.27 8107
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 Next
/ 12

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved