EOX GitLab Instance

Skip to content
Snippets Groups Projects
Commit 9f086668 authored by Nicolas Baudoin's avatar Nicolas Baudoin
Browse files

Added the unban function for fail2ban to work with nftables through a script

parent bb4865be
No related branches found
No related tags found
1 merge request!1Repositionning of the fail2ban configuration with nftables from wireguard to...
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
---
# The unban script will allow fail2ban to delete rules from nftables by finding their handles
- name: Create an unban script for Fail2Ban to work with nftables
template:
src: nftables_unban.j2
dest: /usr/local/bin/nftables_unban
mode: '0755'
# The date script will generate the correct path for the log
- name: Create date script for Fail2Ban logpath
template:
......
......@@ -8,7 +8,7 @@ actionstart =
actionstop =
actioncheck =
actionban = /usr/sbin/nft insert rule inet filter input ip saddr <ip> drop
actionunban = /usr/sbin/nft delete rule inet filter input ip saddr <ip>
actionunban = /usr/local/bin/nftables_unban <ip>
[Init]
table = filter
......
#!/bin/bash
IP_TO_UNBAN="$1"
# Fetch the handle for the rule with the given IP
HANDLE=$(/usr/sbin/nft -a list table inet filter | grep "ip saddr $IP_TO_UNBAN drop" | awk '{print $NF}')
# If a handle was found, delete the rule
if [ ! -z "$HANDLE" ]; then
/usr/sbin/nft delete rule inet filter input handle $HANDLE
else
echo "No handle found for IP $IP_TO_UNBAN"
fi
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment