Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ipset=/sbin/ipset
- iptables=/sbin/iptables
- route=/etc/acl
- zone=zones
- wgetd="wget -q -c --retry-connrefused -t 0"
- if [ ! -d $zone ]; then mkdir -p $zone; fi
- echo "Downloading country ip ranges..."
- $wgetd http://www.ipdeny.com/ipblocks/data/countries/all-zones.tar.gz && tar -C $zone -zxvf all-zones.tar.gz >/dev/null 2>&1 && rm -f all-zones.tar.gz >/dev/null 2>&1
- # Какой порт защищать
- port=25565
- # Блокировать линукс подключения? true/false. Оно будет блокировать большинство атак (с использованием прокси).
- block_linux_connections=true
- limit_global_connections=true
- limit_global_connections_max=300
- # Limit new connections per second. This is highly useful when Лимит новых подключений в секунду, это опция очень полезна
- # когда кто то начинает подрубать атаку, потому что это просто делает его атаку буквально бесполезной.
- # Не полагайтесь только на эту настройку, так как это не исправит проблему полностью,
- # просто будет отсекать подозрительные IP-адресов.
- burstconns=15
- Запланированная функция: Белый список плагинов
- timeout=900
- # Эта настройка позволяет сделать белый список стран игроков, которые всегда смогут подключиться к вашему серверу.
- # А люди из других стран будут иметь ограниченную возможность подключиться.
- #
- # Полезные команды:
- # Очистить белый список: sudo ipset flush whitelist
- # Очистить прокси: sudo ipset flush proxies
- #
- # Создание белого списка в пакете IPSET (установить apt-get install ipset или yum -y install ipset)
- echo "Preparing ipset configuration"
- $ipset -F
- $ipset -N -! proxies hash:net maxelem 150000 timeout $timeout
- $ipset -N -! whitelist hash:net maxelem 1000000
- # This is where you select which countries you want whitelisted. It's really important.
- for ip in $(cat $zone/{ro,md,fr,de,ie,gb,it,at,tr,bg,es}.zone); do
- $ipset -A whitelist $ip
- done
- # Подготовка системы BotManager
- # Шаг 1. Создаём и очищаем новую таблицу "BotManager"
- $iptables -N BotManager
- $iptables -F BotManager
- # Шаг 2. Проверка максимального количества подключений, чтобы ослабить атаку.
- $iptables -A BotManager -p tcp --dport $port -m set --match-set proxies src -j DROP
- $iptables -A BotManager -p tcp --dport $port -m set --match-set whitelist src -j ACCEPT
- $iptables -A BotManager -p tcp --dport $port --syn -m limit --limit $burstconns/s -j ACCEPT
- $iptables -A BotManager -p tcp --dport $port --syn -j DROP
- # Добавление таблицы BotManager в iptables и на всякий случай удаление (если таблица уже добавлена).
- $iptables -D INPUT -p tcp -j BotManager
- $iptables -A INPUT -p tcp -j BotManager
- if $block_linux_connections ; then
- $iptables -A INPUT -p tcp -m tcp --syn --tcp-option 8 --dport $port -j REJECT
- echo 'Blocked linux connections!'
- fi
- if $limit_global_connections ; then
- $iptables -I INPUT -p tcp --dport $port -m state --state NEW -m limit --limit $limit_global_connections_max/s -j ACCEPT
- echo 'Limited global connections!'
- fi
- echo "Firewall applied successfully."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement