@@ -9,11 +9,11 @@ A simple guide to setup fail2ban action for sending an alert message to discord
99
10102 . Create the Discord Notification Script
1111 - install ` jq ` :
12- ```
12+ ``` bash
1313 sudo apt install jq
1414 ```
1515 - Create the file /usr/local/bin/fail2ban-discord.sh:
16- ```
16+ ` ` ` bash
1717 #! /bin/bash
1818
1919 JAIL=" $1 "
@@ -39,12 +39,12 @@ A simple guide to setup fail2ban action for sending an alert message to discord
3939 " $WEBHOOK_URL "
4040 ` ` `
4141 - Make it executable:
42- ```
42+ ` ` ` bash
4343 sudo chmod +x /usr/local/bin/fail2ban-discord.sh
4444 ` ` `
45453. Create a Custom Fail2Ban Action
4646 - Create /etc/fail2ban/action.d/discord-ban.conf:
47- ```
47+ ` ` ` ini
4848 [Definition]
4949 actionstart =
5050 actionstop =
@@ -55,7 +55,7 @@ A simple guide to setup fail2ban action for sending an alert message to discord
5555
56564. Apply It in Jail Config
5757 - Edit /etc/fail2ban/jail.local or create if not existing:
58- ```
58+ ` ` ` ini
5959 [sshd]
6060 enabled = true
6161 port = ssh
@@ -66,14 +66,26 @@ A simple guide to setup fail2ban action for sending an alert message to discord
6666 action = discord-ban
6767 ` ` `
68685. Restart fail2ban
69- ```
69+ ` ` ` bash
7070 sudo systemctl restart fail2ban
7171 ` ` `
7272
73736. Test
74+
7475 To test, you can intentionally trigger a failed login from a different IP or use:
76+ ` ` ` bash
77+ sudo fail2ban-client set sshd banip 192.168.0.1
7578 ` ` `
76- sudo fail2ban-client set sshd banip 1.2.3.4
77- ```
7879
79- All are done!. You should receive an alert in your Discord channel.
80+ All are done! . You should receive an alert in your Discord channel like below.
81+
82+ ` ` ` text
83+ Fail2Ban Alert
84+ Server: srv627828
85+ Time: 2025-05-29 00:06:40
86+ Jail: sshd
87+ Banned IP: 191.7.190.74
88+ Reason: May 28 23:53:53 srv627828 sshd[52304]: Invalid user katarina from 191.7.190.74 port 44770
89+ May 28 23:53:53 srv627828 sshd[52304]: Failed password for invalid user katarina from 191.7.190.74 port 44770 ssh2
90+ May 29 00:06:39 srv627828 sshd[52915]: Failed password for postfix from 191.7.190.74 port 30736 ssh2
91+ ` ` `
0 commit comments