메뉴 건너뛰기

조회 수 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
번호 제목 날짜 조회 수
36 kernel panic 복구 2014.02.27 9316
35 centos 4.x 데몬 2014.02.27 6875
34 하드디스크의 속도와 성능테스트강좌 hdparm 2014.02.27 7471
33 Snort란 2014.02.27 7873
32 htaccess를 이용한 특정 디렉토리 접근 관리하기 2014.02.27 7113
31 외부 링크 제한하기 2014.02.27 7952
30 apache에서 전송 속도 제한하기 2014.02.27 6940
29 find 명령어로 특정 디렉토리 내 특정 파일들의 특정 문자열 일괄 변경 2014.02.27 7195
28 URL 포워딩 하는 방법 2014.02.27 6958
27 ssh timeout 설정 2014.02.27 7726
26 linux mcrypt 설치 (php 재컴파일 필요) 2014.02.27 7824
25 apache status 모듈 ( 모니터링 ) 2014.02.27 8493
24 apache 로그정리 (logrotate) 2014.02.27 7434
23 linux 커널 파라메터 수정 2014.02.27 7094
22 Mysql 설치시 LinuxThreads 에러 메세지 2014.02.27 7496
21 리눅스 문자열 치환하기 2014.02.27 7807
20 suPHP로 웹서버 보안을 강화하자 2014.02.27 8781
19 CentOS 32Bit 운영체제에서 메모리 4G인식 시키는 방법 2014.02.27 7103
18 Linux LVM구성하기 2014.02.27 8218
17 tmp 보안 셋팅 2014.02.27 7084
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 Next
/ 12

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved