OS

2024.08.30 15:53

Rocky Linux 9 iptables geoip(db-ip.com) 연동

  • 비아웹 오래 전 2024.08.30 15:53 인기
  • 119
    0

안녕하세요

호스팅 전문기업 비아웹입니다.

Rocky Linux 9 환경에서 iptables 에 GeoIP 연동 하는 부분에 대해 정리합니다.

해당 geoip 데이터 베이스는 db-ip.com(https://db-ip.com/) 데이터를 사용합니다.

1.사전 준비

Rocky Linux 9 최소 설치

Selinux disable

firewalld 서비스 stop / disable

# firewalld 중지
systemctl disable firewalld --now
 

2. iptables / xtables-addons 설치

dnf install https://download1.rpmfusion.org/free/el/rpmfusion-free-release-9.noarch.rpm
dnf install iptables-services iptables-devel xtables-addons perl-Text-CSV_XS perl-App-cpanminus

3. perl module 설치

cpanm Net::CIDR::Lite
cpanm Text::CSV_XS
 

4. 스크립트 작성

 
  • geo-update.sh 스크립트

  • #!/bin/bash
    
    MON=$(date +"%m")
    YR=$(date +"%Y")
    
    wget https://download.db-ip.com/free/dbip-country-lite-${YR}-${MON}.csv.gz -O /usr/share/xt_geoip/dbip-country-lite.csv.gz
    gunzip /usr/share/xt_geoip/dbip-country-lite.csv.gz
    cd /usr/share/xt_geoip/
    /usr/libexec/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip/ *.csv
    rm /usr/share/xt_geoip/dbip-country-lite.csv
    
  • chmod 700 /usr/local/bin/geo-update.sh
    /usr/local/bin/geo-update.sh
    
 
 

5. xt_geoip 모듈 추가

modprobe xt_geoip
 

6. 테스트

iptables -A OUTPUT -m state --state NEW -m geoip --dst-cc CH -j DROP
 

이상과 같이 Rocky Linux 9 환경에서 iptables 사용시 geoip 연동하는 부분에 대해 정리하였습니다.

db-ip.com 의 geoip 데이터의 경우 인증 부분이 없고, maxmind 대비 간략하게 설치 가능합니다.

iptables 작업시 서버 접속이 차단되는 경우가 발생할 수 있으니, 테스트와 고려사항 체크를 진행 후 작업하시기 바랍니다.

해당 스크립트를 매주 cron 등록시 주기적인 자동 업데이트 가능합니다.

감사합니다.

호스팅 전문기업 비아웹

 

 

  • 공유링크 복사