Skip to content Перейти до змісту


How to block DDOS attacks in Linux Як заблокувати DDOS атак в Linux

LinuxБезпека

We ran an article on Ми побігли на статтю How to block an IP address in iptables in Linux Як заблокувати адреса в Iptables в Linux a few days ago. Кілька днів тому. Here's a complimentary article that shows you how to detect the IP addresses of attackers in case of aa denial of service (or DOS) attack. Ось безкоштовний статтю, в якій показано, як визначити IP-адреси атакуючих у випадку А. А. відмова в обслуговуванні (або DOS) атаки.

To do this we will use free software called Для цього ми будемо використовувати безкоштовне програмне забезпечення під назвою psad PSAD . psad works in sync with iptables and monitors the iptables logs and checks for port scans and other suspicious traffic which are usually signs of someone trying to break into your Linux server. . PSAD працює синхронно з Iptables і контролює Iptables журнали і перевіряє, сканування портів і інших підозрілих трафік, який, як правило, ознаки, хто намагається проникнути у ваш сервер Linux.

To begin, install psad. Для початку встановіть PSAD. If you are running a flavor of Linux that has a fancy package management system like Ubuntu or Fedora you should be able to use either of the following commands to get psad on your system: Якщо ви працюєте з ароматом Linux, яка має фантазії система управління пакетами, як Ubuntu або Fedora ви зможете використовувати будь-який з наступних команд PSAD отримати у вашій системі:

# sudo apt-get install psad # Sudo APT-отримати установку PSAD
or або
# yum install psad Встановити PSAD # Yum

If this doesn't work for you head to the psad Якщо це не робота для тебе головою PSAD download page Сторінка завантаження and download the format that works for you. і викачати той формат, який працює на вас.

As I use an Ubuntu Linux server the rest of this tutorial will be Ubuntu specific. Як я використовую сервер Ubuntu Linux решту цього підручника буде Ubuntu конкретним. However, with some minor tweaking you should be able to make it work on other flavors of Linux. Однак, з деякими незначними налаштування ви зможете змусити її працювати на інші різновиди Linux. Open the syslog.conf file with your favorite text editor: Відкрите фото syslog.conf з вашим улюбленим текстовим редактором:

# vim /etc/syslog.conf # VIM / ETC / syslog.conf

Add the following line at the end of the of the file: Додайте наступний рядок в кінці цього файлу:

kern.info |/var/lib/psad/psadfifo kern.info | / VAR / LIB / PSAD / psadfifo

You can use the following command to accomplish the same thing: Ви можете використати таку команду, щоб виконати те ж саме:

# echo -e 'kern.info\t|/var/lib/psad/psadfifo' >> /etc/syslog.conf # Ехо-E 'kern.info \ T | / VAR / LIB / PSAD / psadfifo'>> / ETC / syslog.conf

Now restart the sysklogd and klog daemons: Тепер перезавантажте Sysklogd klog і демони:

/etc/init.d/sysklogd restart / І т.д. / init.d / Sysklogd перезавантаження
/etc/init.d/klogd restart / І т.д. / init.d / Klogd перезавантаження

The way psad works is that it will detect and instruct iptables to block any suspicious IPs. PSAD способом роботи є те, що вона буде виявляти і доручити Iptables, щоб блокувати будь-які підозрілі IP-адреси. Sometimes this might result in the blocking of an IP which you use. Іноді це може призвести до блокування IP який ви використовуєте. To overcome this issue you should create a file containing a list of safe IP addresses. Для подолання цієї проблеми ви повинні створити файл, що містить список безпечних адрес. Create a file like this one: Створіть файл типу цієї:

# vim /home/calvin/safeiplist.cfg # VIM / Головна / Calvin / safeiplist.cfg

Enter the IP addresses that you need psad to whitelist: Введіть IP адреси, які потрібно PSAD в білий список:

127.0.0.0/24 127.0.0.0/24
192.168.0.0/24 192.168.0.0/24
122.164.34.240 122.164.34.240

No use a script like following one to configure iptables with the necessary rules. Note that this script will remove all previous settings from your iptables setup. Не використовувати такий скрипт наступних один налаштувати Iptables необхідних правил. Зауважимо, що цей сценарій буде видалити всі попередні налаштування вашої установки Iptables. Copy and paste the following script on your Linux server, and replace the variables WORKDIR and SAFEIPLIST with the correct settings from your setup. Скопіюйте та вставте наступний скрипт на сервер Linux, а також заміни змінних WORKDIR і SAFEIPLIST з правильної настройки вашої установки.

WORKDIR="/home/calvin/" WORKDIR = "/ Головна / Calvin /"
INTERVAL="5" INTERVAL = "5"
HITCOUNT="5" HITCOUNT = "5"
SAFEIPLIST="safeiplist.cfg" SAFEIPLIST = "safeiplist.cfg"

cd $WORKDIR CD $ WORKDIR

iptables -F IPTABLES-F
if [ -f $SAFEIPLIST ]; then якщо [-F $ SAFEIPLIST], потім
IPS=$(grep -Ev “^#” $SAFEIPLIST) IPS = $ (Grep-Ev "^ #" $ SAFEIPLIST)
for i in $IPS я в $ IPS
do робити
iptables -A INPUT -s $i -j ACCEPT IPTABLES-A INPUT-S $ I-J ACCEPT
done готове
fi Fi

iptables -A INPUT -m state –state NEW -m recent –set IPTABLES-A INPUT-ою державою-штат Нью-м останній набір --
iptables -A INPUT -m state –state NEW -m recent –update –seconds $INTERVAL –hitcount $HITCOUNT -j LOG IPTABLES-A INPUT-ою державою-штат Нью-м останнього оновлення секунди $ INTERVAL-hitcount $ HITCOUNT-й реєстрації

What the script does is that it logs an IP address if it makes five or more attempts at making a connection in the span of five seconds. Що скрипт робить те, що вона реєструє IP адреса, якщо вона становить п'ять або більше спроби встановлення з'єднання протягом п'яти секунд. I would suggest you use the script as is unless you know what you are doing while modifying it. Я хотів би запропонувати використовувати сценарій як якщо ви не знаєте, що ви робите в той час як його змінити. One you are done, give it executable permissions and run it. Один все готово, дайте йому виконуваних дозволів і запустити його.

# chmod +x /home/calvin/ipblock.sh # CHMOD + X / Головна / Calvin / ipblock.sh

# /home/calvin/ipblock.sh # / Головна / Calvin / ipblock.sh

Now back to psad. Тепер повернемося до PSAD. Open the psad configuration file and edit it. Відкрийте PSAD конфігураційний файл і редагувати його. These are the changes I suggest you make. Ці зміни, які я пропоную вам зробити. Feel free to go through the psad documentation and make other changes: Ви можете пройти PSAD документацію і провести інші зміни:

EMAIL_ADDRESSES you@yourdomain.com; EMAIL_ADDRESSES you@yourdomain.com;

Set machine's hostname: Встановити машини хоста:

HOSTNAME yourdomain.com; HOSTNAME yourdomain.com;

If you have only one network interface on this server, set HOME_NET to: Якщо у вас тільки один мережевий інтерфейс, на цьому сервері, встановіть HOME_NET до:

HOME_NET NOT_USED; HOME_NET NOT_USED;

You can also need to adjust danger levels for psad, and define a set of ports to ignore, for example to ask psad ignore udp ports 80 and 8080, make the following change: Ви можете також необхідно налаштувати рівні небезпеки для PSAD, і визначити набір портів ігнорувати, наприклад, запитати PSAD ігнорувати UDP-порти 80 і 8080, внести наступні зміни:

IGNORE_PORTS udp/80, udp/8080; IGNORE_PORTS udp/80, udp/8080;

Save and close the file. Збережіть і закрийте файл. Then restart psad: Потім перезавантажте PSAD:

# /etc/init.d/psad restart # / І т.д. / init.d / PSAD перезавантаження

You are now good to go. Тепер ви добре йти. To monitor psad's reports run the following command: Щоб відстежувати повідомлення PSAD's запустіть наступну команду:

# psad -S # PSAD-S

To remove automatically clocked IPs run the following command: Щоб видалити автоматичний частоті IPs запустіть наступну команду:

# psad -F # PSAD-F

psad is a very versatile and powerful tool. PSAD є дуже гнучким і потужним інструментом. If you know how to use it it can do wonders for you, but if you don't you can really mess up your computer. Якщо ви знаєте, як використовувати його він може робити чудеса, але якщо ви не ви можете дійсно безлад комп'ютера. So please use psad with caution. Тому, будь ласка, PSAD використовувати з обережністю.

Posted in Опубліковано в Linux Linux , , Security Безпека . .

Related Posts: Схожі повідомлення:

How to block an IP address in IPTables in Linux Як заблокувати адреса в IPTables в Linux
Comcast: Another chapter of lies, misdirection and ps. Comcast: Ще один розділ брехні, неправильного і ПС. good luck using bittorrent удачі допомогою завантаження
How to use the OR operator in grep Як використовувати ЧИ оператор в Grep
How to determine where all your hard drive space has gone in Windows Як визначити, де весь простір жорсткого диска пройшла в Windows
Getting started with iptables in Linux Приступаючи до роботи з Iptables в Linux

One Response Один відповідь

Stay in touch with the conversation, subscribe to the Залишайтеся на зв'язку при розмові, підпишіться на RSS feed for comments on this post RSS-канал для коментарів на цю посаду . .

Continuing the Discussion Продовжуючи розмову

  1. RSS Week #51: letture per il weekend - Matteo Moro RSS Тиждень # 51: ил letture за вихідні - Маттео море linked to this post on June 14, 2009 пов'язані на цю посаду 14 червня 2009

    [...] How to block DDOS attacks in Linux [...] [...] Як заблокувати DDOS атак в Linux [...]



Some HTML is OK Деякі HTML нормально

or, reply to this post via або відповісти на цей пост через trackback Архів . .