일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- proxmox
- Rocky
- mysql
- nginx
- 티스토리
- 복현오거리
- OpenWrt
- jQuery
- 알리익스프레스
- 리눅스
- SKT
- PHP-FPM
- 자바스크립트
- KB증권
- ConoHa
- 킹북이초월
- 윈도우10
- 보르비스초월
- 소비전력
- 램가스초월
- 알뜰폰
- 시놀로지
- php
- KB국민카드
- 아파치
- 스톤에이지
- 가상서버호스팅
- Apache
- centos
- iptime
- Today
- Total
맛집 여행 캠핑 일상 생활
[Linux] CentOS 7.x xtables-addons 설치 방법 본문
CentOS 7.x 버전에서는 Rocky 리눅스와 달리 yum install 로 설치를 지원하는 않는군요~
yum install make gcc iptables-devel perl-Text-CSV_XS perl-App-cpanminus
cpanm NetAddr::IP
cpanm Getopt::Long
wget mirror.koreaidc.com/iptables/xtables-addons-2.10.tar.gz
tar xvfz xtables-addons-2.10.tar.gz
cd xtables-addons-2.10
sed -i '/build_TARPIT=m/ s/^/#/' mconfig
./configure
make && make install
mkdir /usr/share/xt_geoip
cd geoip
./00_download_geolite2
# https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip 다운로드가 안됩니다.
# 가입을 하면 될것 같은데 그냥 패스합니다.
./10_download_countryinfo
# countryinfo 파일이라도 다운로드 합니다.
cat /tmp/GeoLite2-Country-Blocks-IPv{4,6}.csv | ./20_convert_geolite2 /tmp/CountryInfo.txt > GeoIP-legacy.csv
# 위의 00_download_geolite2 에 다운로드가 되어야 위 명령어가 실행이 됩니다. 다른 방법으로 시도하겠습니다.
# Rocky 9 리눅스에서 사용하는 방법인 db-ip.com 에서 csv 파일을 다운로드 받습니다.
cd /usr/share/xt_geoip/
wget -O dbip-country-lite.csv.gz https://download.db-ip.com/free/dbip-country-lite-$(date '+%Y-%m').csv.gz
gzip -d dbip-country-lite.csv.gz
maxmind 와 db-ip csv 파일이 포맷이 달라서 원하는 포맷으로 변환해야 합니다.
# vi /root/xtables-addons-2.10/geoip/dbip_convert_geolite2 (아래 코드를 저장합니다.)
# chmod 700 dbip_convert_geolite2
#!/usr/bin/perl -w
use strict;
use diagnostics;
use NetAddr::IP;
use Getopt::Long;
my $quiet = 0;
GetOptions(
'quiet' => \$quiet,
) or die("bad args");
unless(-s "$ARGV[0]"){
print STDERR "Specify Country DB to use on the command line.\n";
exit 1;
}
my $countryinfo;
$countryinfo->{'ZZ'}->{'code'} = 'ZZ';
$countryinfo->{'ZZ'}->{'name'} = 'ZZ private';
# Read the countryinfo file
open my $fh_in, "<", "$ARGV[0]" or die "Can't open $ARGV[0]: $!\n";
foreach my $line (<$fh_in>){
chomp $line;
next if ($line =~ /^#/);
my @fields = (split "\t", $line);
my $code = $fields[0];
my $name = $fields[4];
my $id = $fields[0];
$countryinfo->{$id}->{'code'} = $code;
$countryinfo->{$id}->{'name'} = $name;
}
close $fh_in;
# Convert actual GeoLite2 data from STDIN
my $counter;
foreach my $line (<STDIN>){
next unless ($line =~ /^\d/);
chomp $line;
$counter++;
my @fields = (split ",", $line);
my $country_id = $fields[2];
my $start_ip = $fields[0];
my $end_ip = $fields[1];
my $start_int = NetAddr::IP->new($fields[0])->bigint();
my $end_int = NetAddr::IP->new($fields[1])->bigint();
my $code;
my $name;
if($countryinfo->{$country_id}){
$code = $countryinfo->{$country_id}->{'code'};
$name = $countryinfo->{$country_id}->{'name'};
}else{
print STDERR "ID: $country_id\n";
exit 1;
}
printf "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n",
$start_ip, $end_ip, $start_int, $end_int, $code, $name;
if (!$quiet && $counter % 10000 == 0) {
print STDERR "$counter\n";
}
}
# csv 파일이 포맷이 달라 20_convert_geolite2 가 안먹히기 때문에 응용해서 변환코드를 만들어봤습니다.
cat dbip-country-lite.csv | /root/xtables-addons-2.10/geoip/dbip_convert_geolite2 /tmp/CountryInfo.txt > Geoip-dbip-legacy.csv
/root/xtables-addons-2.10/geoip/xt_geoip_build -D /usr/share/xt_geoip/ Geoip-dbip-legacy.csv
이제 변환이 잘 될겁니다.
위 변환코드 파일을 다운로드 받아도 됩니다.
'LINUX' 카테고리의 다른 글
[Linux] CentOS 7.x 지원 종료로 인한 yum update 에러 (0) | 2025.04.11 |
---|---|
[Linux] Rocky 9 리눅스 xtables-addons 설치 방법 (0) | 2025.04.04 |
[Linux] sendmail no local interface found for ::1 (0) | 2025.03.31 |
[LINUX] IPTABLES CensysInspect 차단 (0) | 2024.10.31 |
[CentOS] mrtg snmpd 안되는 경우 (0) | 2024.10.22 |