Skip to content

Instantly share code, notes, and snippets.

@hannesbe
Last active January 12, 2016 15:34
Show Gist options
  • Save hannesbe/719c03d85134f8e9df5c to your computer and use it in GitHub Desktop.
Save hannesbe/719c03d85134f8e9df5c to your computer and use it in GitHub Desktop.
Install script fail2ban with action to firewalld | CentOS/EL 7
#!/bin/sh
#
# Shell script to install & configure fail2ban with firewalld actions
# Just one command to install & configure in a few seconds.
# CentOS/EL7+ required.
#
# Run this command to execute the script in one go
# curl -sSL https://gist.github.com/hannesbe/719c03d85134f8e9df5c/raw/fail2ban-firewalld-install.sh | bash -s
#
set -e
N=$(tput sgr0) ; BD=$(tput bold) ; GR=$(tput setaf 2; tput bold) ; YE=$(tput setaf 3) ; R=$(tput setaf 1)
OK="[$GR OK $N]\n" ; FL="[$R FAILED $N]\n"
[[ $EUID -eq 0 ]] ||
( printf "You must be a root user $FL\n" 2>&1 ; exit 1 )
printf ""$BD"\nInstalling & configuring "$YE"fail2ban for firewalld with sshd filter enabled$N\n"
printf ""$BD"\nDownloading & installing packages$N\n" &&
yum install epel-release fail2ban fail2ban-firewalld fail2ban-systemd -y -q &&
printf " $OK" || ( printf " $FL" ; exit 2 )
printf ""$BD"\nDownloading config$N\n"
CONFIG=/etc/fail2ban/jail.local
[[ -f "$CONFIG" ]] &&
( printf "$YE$CONFIG$N already exists, renaming yours to $YE$CONFIG.save$N " ;
mv $CONFIG $CONFIG.save && printf " $OK" || ( printf " $FL" ; exit 3 ) )
curl -fsSL https://gist.github.com/hannesbe/52e080c0b25f24959fc7/raw/jail.local -o $CONFIG &&
printf "Saved config to $YE$CONFIG$N $OK" || ( printf " $FL" ; exit 3 )
printf ""$BD"\nEnabling & starting daemon$N\n" &&
systemctl start fail2ban &&
systemctl enable fail2ban &&
printf " $OK" || ( printf " $FL" ; exit 4 )
@hannesbe
Copy link
Author

Run this command to execute the script in one go :
curl -sSL https://gist.github.com/hannesbe/719c03d85134f8e9df5c/raw/fail2ban-firewalld-install.sh | bash -s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment