Files
bird_list_ip/README.md
Александр 54e135a00a Обновить README.md
Добавлено описание установки модуля brotli для Python3
2025-12-01 18:18:57 +10:00

128 lines
5.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# bird_list_ip
Это скрипт написанный на Python3 для выгрузки пулов ip адресов, для bird2.
# Установка (Debian)
-- устанавливаем пакеты
> sudo apt install -y git bird2 m4
-- добавляем поддержку brotli в python3
> apt -y install python3-pip
> pip install brotli 2> /dev/null || pip install brotli --break-system-packages
-- клонируем репозиторий
> git clone https://git.alanbox.ru/alan/bird_list_ip.git /opt/bird_list_ip && chmod +x /opt/bird_list_ip/download.py
-- правим Unit Systemd bird2 для работы с m4
> nano /usr/lib/systemd/system/bird.service
> [Unit]\
> Description=BIRD Internet Routing Daemon\
> After=network.target\
>\
> [Service]\
> EnvironmentFile=/etc/bird/envvars\
> ExecStartPre=/bin/sh -c "/usr/bin/m4 /opt/bird > /etc/bird/bird.conf"\
> ExecStartPre=-/usr/lib/bird/prepare-environment\
> ExecStartPre=-/usr/sbin/bird -p\
> ExecReload=/bin/sh -c "/usr/bin/m4 /opt/bird > /etc/bird/bird.conf"\
> ExecReload=-/usr/sbin/birdc configure\
> ExecStart=/usr/sbin/bird -f -u $BIRD_RUN_USER -g $BIRD_RUN_GROUP $BIRD_ARGS\
> Restart=on-abort\
>\
> [Install]\
> WantedBy=multi-user.target\
-- пример конфигурации bird2 на m4, для работы со списками
> nano /opt/bird
> log syslog {error, fatal};\
> router id ~~**1.1.1.1**~~;\
>\
> protocol device {\
> }\
>\
> protocol direct {\
>     ipv4; # Connect to default IPv4 table\
>     #ipv6; # ... and to default IPv6 table\
> }\
>\
> protocol kernel {\
>     learn;\
>     merge paths on;\
>     ipv4 { # Connect protocol to IPv4 table by channel\
>         import none; # Import to table, default is import all\
>         export filter { if (net.len > 0 && source=RTS_BGP) then { accept; } reject; }; # Export to protocol. default is export none\
>     };\
> }\
>\
> \# SUB m4\
> define(\`LOCATION', \`~~**741**~~')\
> include(\`/opt/bird_list_ip/unloading/bird2_v4.m4')\
>\
> filter border_in {\
>     if (net ~ 0.0.0.0/32) then { reject; }\
>     if (net ~ 127.0.0.0/8) then { reject; }\
>     if (net ~ 169.254.0.0/16) then { reject; }\
>     if (net ~ 224.0.0.0/4) then { reject; }\
>     if (net ~ 240.0.0.0/4) then { reject; }\
>     if (net.len > 0) then { accept; }\
>     reject;\
> }\
>\
> filter border_out {\
>     if (net ~ 0.0.0.0/32) then { reject; }\
>     if (net ~ 127.0.0.0/8) then { reject; }\
>     if (net ~ 10.0.0.0/8) then { reject; }\
>     if (net ~ 172.16.0.0/12) then { reject; }\
>     if (net ~ 192.168.0.0/16) then { reject; }\
>     if (net ~ 169.254.0.0/16) then { reject; }\
>     if (net ~ 224.0.0.0/4) then { reject; }\
>     if (net ~ 240.0.0.0/4) then { reject; }\
>     accept;\
> }\
>\
> define(\`BGP_BORDER', \`\
> protocol bgp $1 {\
>     ipv4 {\
>         import filter border_in;\
>         export filter border_out;\
>         next hop self;\
>     };\
>     router id $2;\
>     source address $2;\
>     local $2 as ~~**65431**~~;\
>     neighbor $3 as ~~**65949**~~;\
>     hold time 90;\
>     keepalive time 60;\
>     passive off;\
>     multihop;\
>     bfd no;\
> }\
> ')\
>\
> BGP_BORDER(\`CLIENT1', \`~~**10.8.1.1**~~', \`~~**10.8.1.2**~~')\
> BGP_BORDER(\`CLIENT1', \`~~**10.8.2.1**~~', \`~~**10.8.2.2**~~')\
> ...\
> BGP_BORDER(\`CLIENT99', \`~~**10.8.99.1**~~', \`~~**10.8.99.2**~~')\
~~**Так**~~ - это требует вашего внимания, для вашей конфигурации bird2
-- добавляем задачу в cron, обновление раз в неделю в среду в 5 утра
> crontab -e
> 0 5 * * 3 /usr/bin/python3 /opt/bird_list_ip/download.py > /dev/null 2>&1 # обновление списков ip адресов
-- запуск загрузки в ручную
> python3 /opt/bird_list_ip/download.py # выгружаем все списки
> python3 /opt/bird_list_ip/download.py RU # выгружаем конкретный список
> python3 /opt/bird_list_ip/download.py RU JAPAN KOREA # выгружаем перечисленные списки
-- добавляем bird2 в автозагрузку и запускаем
> systemctl daemon-reload && systemctl enable bird.service && systemctl start bird.service
**#####################################################################**\
    Пример конфигурация списка выгрузки можно посмотреть в файле list в репозитории,\
    так же допускается указывать url ссылку на конфигурацию первой строкой в файле list