Skip to content

Commit

Permalink
add experimental automatic dns ddos mitigation
Browse files Browse the repository at this point in the history
  • Loading branch information
cozybear-dev committed Jun 28, 2023
1 parent e02482f commit 80c732f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions roles/setup-dns/tasks/files/dns-ddos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /bin/bash
(( usage = $(top -b -n 10 -d 1 -p $(pgrep -x unbound) | tail -1 | awk '{print $9}') ))
if (( usage > 35 )); then
service unbound restart
fi
20 changes: 20 additions & 0 deletions roles/setup-dns/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@
when:
- ipv6_enabled | bool

- name: Create dns-ddos.sh DNS (unbound) DDOS mitigation
become: yes
ansible.builtin.copy:
src: ../files/dns-ddos.sh
dest: /bin/dns-ddos.sh
owner: root
group: root
mode: '0555'
when:
- ipv6_enabled | bool

- name: Create cronjob DNS (unbound) DDOS mitigation
become: yes
ansible.builtin.cron:
name: "Restart Unbound in case of DDOS"
minute: "1"
job: "/bin/dns-ddos.sh"
when:
- ipv6_enabled | bool

- name: Configure systemd-resolved
become: yes
ansible.builtin.copy:
Expand Down

0 comments on commit 80c732f

Please sign in to comment.