Skip to content

Instantly share code, notes, and snippets.

@aweijnitz
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aweijnitz/5d3e6620cfd05f20a3b2 to your computer and use it in GitHub Desktop.
Save aweijnitz/5d3e6620cfd05f20a3b2 to your computer and use it in GitHub Desktop.
Basic firewall and connection autobanning on Debian
#!/bin/bash
#
# ____ Install Uncomplicated Firewall (frontend to iptables)
#
sudo apt-get install -y ufw
# Be paranoid
sudo ufw disable
# Deny all connections
sudo ufw default deny incoming
# Allow ssh
# Note: If ssh is on another port,
# use 'sudo ufw allow 2222/tcp' for port 2222
sudo ufw allow ssh
# Allow web traffic
# (same as sudo ufw allow 80/tcp)
sudo ufw allow www
# Activate firewall
# Manual status check: sudo ufw status, or sudo ufw status verbose
# Turn firewall off: sudo ufw disable
sudo ufw --force enable
#
# ____ Install fail2ban - limit connection attemps, then block
#
sudo apt-get install -y fail2ban
# Local config
sudo cat /etc/fail2ban/jail.conf | sed 's/root@localhost/my@email.com/g' > /tmp/jail.local
sudo cp /tmp/jail.local /etc/fail2ban/jail.local
# Start fail2ban
sudo service fail2ban restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment