LINUX.ORG.RU
ФорумAdmin

GEOIP + Iptables, проблема с сборкой базы

 , ,


0

1

Подскажите как собрать базу под iptables geoip

Linux 4.9.154-xxxx-std-ipv6-64 #569310 SMP Thu Jan 31 08:31:31 UTC 2019 x86_64 GNU/Linux
Distributor ID: Debian
Description:    Debian GNU/Linux 8.11 (jessie)
Release:        8
Codename:       jessie
dpkg -l | grep xtables
ii  libxtables10                                                1.4.21-2+b1                            amd64        netfilter xtables library
ii  xtables-addons-common                                       2.6-1                                  amd64        Extensions targets and matches for iptables [tools, libs]
ii  xtables-addons-dkms                                         2.6-1                                  all          Extensions targets and matches for iptables

iptables -I INPUT ! -i lo -m geoip ! --src-cc UA,RU -j DROP
Could not open /usr/share/xt_geoip/LE/UA.iv4: No such file or directory
iptables v1.4.21: Could not read geoip database

Делал по вот этому манулу https://vds-admin.ru/security/iptables-geoip Но ссылки на базы битые, есть только GeoLite2, но как их собрать?

xtables-addons-dkms

Не собралось походу. Переустанови и почитай выхлоп.

Deleted
()
Ответ на: комментарий от afanasiy
root@ ~/geo/xtables-addons-3.3/geoip # ./xt_geoip_dl
root@ ~/geo/xtables-addons-3.3/geoip # ./xt_geoip_build -D /usr/share/xt_geoip *.csv
Can't locate Net/CIDR/Lite.pm in @INC (you may need to install the Net::CIDR::Lite module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.20.2 /usr/local/share/perl/5.20.2 /usr/lib/x86_64-linux-gnu/perl5/5.20 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.20 /usr/share/perl/5.20 /usr/local/lib/site_perl .) at ./xt_geoip_build line 8.
BEGIN failed--compilation aborted at ./xt_geoip_build line 8.

Что не так делаю? В xtables-addons-3.3 указаны пути уже к актуальным версиям geolite2 (линки рабочие)

linkin2
() автор топика

-m geoip ! --src-cc UA,RU -j DROP

Мож проще поглядеть online списки и добавить простые правила без всяких несобирающихся (и возможно устаревших) баз geoip?

Deleted
()
Ответ на: комментарий от afanasiy

Отлично, эта ошибка решена. Но теперь, не может найти список имен.

root@ ~/geo/xtables-addons-3.3/geoip # ./xt_geoip_build -D /usr/share/xt_geoip *.csv
Couldn't open list country names

root@ns3038134 ~/geo/xtables-addons-3.3/geoip # ls -la
итого 68
drwxr-xr-x 4 root root  4096 апр  3 14:48 .
drwx------ 9 root root  4096 апр  3 14:53 ..
drwxr-xr-x 2 root root  4096 апр  3 14:48 GeoLite2-Country-CSV_20190402
-rwxr-xr-x 1 root root    81 мар  7 12:24 .gitignore
-rwxr-xr-x 1 root root   112 мар  7 12:24 Makefile.am
-rwxr-xr-x 1 root root 17141 мар  7 12:24 Makefile.in
drwxr-xr-x 2 root root  4096 апр  3 14:40 PaxHeaders.24996
-rwxr-xr-x 1 root root  6168 мар  7 12:24 xt_geoip_build
-rwxr-xr-x 1 root root  1520 мар  7 12:24 xt_geoip_build.1
-rwxr-xr-x 1 root root   191 мар  7 12:24 xt_geoip_dl
-rwxr-xr-x 1 root root   582 мар  7 12:24 xt_geoip_dl.1
-rwxr-xr-x 1 root root  2024 мар  7 12:24 xt_geoip_fetch

root@ns3038134 ~/geo/xtables-addons-3.3/geoip/GeoLite2-Country-CSV_20190402 # ls -la
итого 15228
drwxr-xr-x 2 root root     4096 апр  3 14:48 .
drwxr-xr-x 4 root root     4096 апр  3 14:48 ..
-rw-r--r-- 1 root root       55 апр  2 18:32 COPYRIGHT.txt
-rw-r--r-- 1 root root 11893184 апр  2 18:32 GeoLite2-Country-Blocks-IPv4.csv
-rw-r--r-- 1 root root  3570579 апр  2 18:32 GeoLite2-Country-Blocks-IPv6.csv
-rw-r--r-- 1 root root     9864 апр  2 18:32 GeoLite2-Country-Locations-de.csv
-rw-r--r-- 1 root root     9937 апр  2 18:32 GeoLite2-Country-Locations-en.csv
-rw-r--r-- 1 root root     9992 апр  2 18:32 GeoLite2-Country-Locations-es.csv
-rw-r--r-- 1 root root    10230 апр  2 18:32 GeoLite2-Country-Locations-fr.csv
-rw-r--r-- 1 root root    14998 апр  2 18:32 GeoLite2-Country-Locations-ja.csv
-rw-r--r-- 1 root root    11422 апр  2 18:32 GeoLite2-Country-Locations-pt-BR.csv
-rw-r--r-- 1 root root    14932 апр  2 18:32 GeoLite2-Country-Locations-ru.csv
-rw-r--r-- 1 root root    11732 апр  2 18:32 GeoLite2-Country-Locations-zh-CN.csv
-rw-r--r-- 1 root root      433 апр  2 18:32 LICENSE.txt
-rw-r--r-- 1 root root      116 апр  2 18:32 README.txt


linkin2
() автор топика
Ответ на: комментарий от linkin2

У тебя в /usr/share/xt_geoip нет файла GeoIP-legacy.cs потому, что ты видимо НЕ сделал всё инструкции:

cd /usr/local/src/GeoLite2xtables/
./00_download_geolite2
./10_download_countryinfo
cat /tmp/GeoLite2-Country-Blocks-IPv{4,6}.csv |
	./20_convert_geolite2 /tmp/CountryInfo.txt > /usr/share/xt_geoip/GeoIP-legacy.csv
/usr/lib/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip /usr/share/xt_geoip/GeoIP-legacy.csv
afanasiy ★★★★
()
Ответ на: комментарий от afanasiy

Сделал следующие:


mkdir /usr/share/xt_geoip
cd /usr/share/xt_geoip
git clone https://github.com/mschmitt/GeoLite2xtables.git
GeoLite2xtables/00_download_geolite2
GeoLite2xtables/10_download_countryinfo
cat /tmp/GeoLite2-Country-Blocks-IPv{4,6}.csv |
 GeoLite2xtables/20_convert_geolite2 /tmp/CountryInfo.txt > /tmp/GeoIP-legacy.csv
/usr/lib/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip /tmp/GeoIP-legacy.csv

но что дальше?

linkin2
() автор топика
Ответ на: комментарий от linkin2

В каталоге /usr/share/xt_geoip должны появиться каталоги BE и LE

Твое правило:

 iptables -I INPUT ! -i lo -m geoip ! --src-cc UA,RU -j DROP
должно заработать.

afanasiy ★★★★
()
Ответ на: комментарий от afanasiy

Еще одна ошибка.

Сделал следующие:

root@ /usr/share/xt_geoip/GeoLite2xtables # ./00_download_geolite2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1809k  100 1809k    0     0  6711k      0 --:--:-- --:--:-- --:--:-- 6934k
Archive:  /tmp/tmp.W9uSgRNbu3
  inflating: /tmp/GeoLite2-Country-Blocks-IPv6.csv
  inflating: /tmp/GeoLite2-Country-Blocks-IPv4.csv

Далее:


root@ /usr/share/xt_geoip/GeoLite2xtables # ./10_download_countryinfo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 31642  100 31642    0     0   678k      0 --:--:-- --:--:-- --:--:--  686k

Далее вывел список из tmp cat /tmp/GeoLite2-Country-Blocks-IPv{4,6}.csv

Показало огромный список айпшников. Но, при выполнении

./20_convert_geolite2 /tmp/CountryInfo.txt > /usr/share/xt_geoip/GeoIP-legacy.csv

Я получаю следующие:

root@ /usr/share/xt_geoip/GeoLite2xtables # ./20_convert_geolite2 /tmp/CountryInfo.txt > /usr/share/xt_geoip/GeoIP-legacy.csv
Can't locate NetAddr/IP.pm in @INC (you may need to install the NetAddr::IP module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.20.2 /usr/local/share/perl/5.20.2 /usr/lib/x86_64-linux-gnu/perl5/5.20 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.20 /usr/share/perl/5.20 /usr/local/lib/site_perl .) at ./20_convert_geolite2 line 4.
BEGIN failed--compilation aborted at ./20_convert_geolite2 line 4 (#1)
    (F) You said to do (or require, or use) a file that couldn't be found.
    Perl looks for the file in all the locations mentioned in @INC, unless
    the file name included the full path to the file.  Perhaps you need
    to set the PERL5LIB or PERL5OPT environment variable to say where the
    extra library is, or maybe the script needs to add the library name
    to @INC.  Or maybe you just misspelled the name of the file.  See
    "require" in perlfunc and lib.

Uncaught exception from user code:
        Can't locate NetAddr/IP.pm in @INC (you may need to install the NetAddr::IP module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.20.2 /usr/local/share/perl/5.20.2 /usr/lib/x86_64-linux-gnu/perl5/5.20 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.20 /usr/share/perl/5.20 /usr/local/lib/site_perl .) at ./20_convert_geolite2 line 4.
        BEGIN failed--compilation aborted at ./20_convert_geolite2 line 4.
linkin2
() автор топика
Ответ на: комментарий от afanasiy

Да, я его уже ставил, и не смотря на это, все равно ругается.


root@ ~ # install libnet-cidr-lite-perl
Чтение списков пакетов… Готово
Построение дерева зависимостей
Чтение информации о состоянии… Готово
Уже установлена самая новая версия libnet-cidr-lite-perl.
обновлено 0, установлено 0 новых пакетов, для удаления отмечено 0 пакетов, и 0 пакетов не обновлено.


linkin2
() автор топика
Ответ на: комментарий от linkin2
 cat /tmp/GeoLite2-Country-Blocks-IPv{4,6}.csv |
 GeoLite2xtables/20_convert_geolite2 /tmp/CountryInfo.txt > /tmp/GeoIP-legacy.csv

Это одна команда! Символ | - это конвеер, а не разделитель. Т.е. скрипт 20_convert_geolite2 должен получить на вход тот самый «огромный список айпшников

afanasiy ★★★★
()
Ответ на: комментарий от linkin2

Эту ошибку решил установкой пакета libnetaddr-ip-perl

linkin2
() автор топика
Ответ на: комментарий от afanasiy

Базу собрал, все отлично, спасибо тебе большое! Но опять вопрос, при попытке

[CODE ]iptables -I INPUT ! -i lo -m geoip ! --src-cc UA,RU -j DROP Я получаю такой ответ

iptables: No chain/target/match by that name.
linkin2
() автор топика
Ответ на: комментарий от afanasiy

=((

root@ ~ # modprobe xt_geoip
modprobe: ERROR: ../libkmod/libkmod.c:557 kmod_search_moddep() could not open moddep file '/lib/modules/4.9.154-xxxx-std-ipv6-64/modules.dep.bin'

linkin2
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.