Firewall & Security (Ubuntu) Print

  • 0

Ubuntu Tools – Firewall & Security

Basic firewall and security configuration for Ubuntu servers.

UFW (Uncomplicated Firewall)

# enable UFW
sudo ufw enable

# allow SSH (default port 22 or your custom port)
sudo ufw allow 22/tcp

# allow HTTP/HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# check status
sudo ufw status verbose

Iptables (example rule)

sudo iptables -I INPUT -p tcp --dport 2222 -j ACCEPT

Fail2ban

sudo apt install fail2ban -y

Edit jail configuration:

sudo nano /etc/fail2ban/jail.local

Example:

[sshd]
enabled = true
port    = 2222
filter  = sshd
logpath = /var/log/auth.log
maxretry = 5

Best Practices

  • Always back up configuration files before changes.
  • Use SSH keys instead of passwords.
  • Keep your system updated: sudo apt update && sudo apt upgrade -y

Was this answer helpful?

« Back