메뉴 건너뛰기

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

List of Articles
번호 제목 날짜 조회 수
236 ftp passive mode 설정 2014.02.27 8095
235 APM 소스 설치 2014.02.27 8068
234 APM 소스 설치 2014.02.27 7735
233 vsftp 이란? 2014.02.27 9258
232 파일 속성 명령어 : chattr, lsattr 2014.02.27 9614
231 history 파일 삭제 제한하기 2014.02.27 7787
230 apache + mysql 자동 실행 방법 (소스설치) 2014.02.27 7966
229 도메인 포워딩 설정 2014.02.27 7970
228 리눅스 보안 Tip 2014.02.27 8785
227 SQL 인젝션 복구 쿼리 2014.02.27 8248
226 외부에서 apache 정보 못보도록 설정하기 2014.02.27 8013
225 도메인에 자동으로 www 붙도록 설정하기 2014.02.27 7581
224 htaccess를 이용한 특정 디렉토리 접근 관리하기 2014.02.27 7136
223 iptable에서 TCP SYN Flooding 차단 설정 2014.02.27 9555
222 yum rpmforge 등록하기 2014.02.27 7806
» iptables GEOIP 모듈 설치. (국가별 IP 차단) 2014.02.27 7863
220 tmp 보안 셋팅 2014.02.27 7086
219 Linux LVM구성하기 2014.02.27 8218
218 CentOS 32Bit 운영체제에서 메모리 4G인식 시키는 방법 2014.02.27 7103
217 suPHP로 웹서버 보안을 강화하자 2014.02.27 8781
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 12 Next
/ 12

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved