Skip to content

Instantly share code, notes, and snippets.

@arnaudrenaud
Last active April 20, 2024 12:41
Show Gist options
  • Save arnaudrenaud/1f953cc238884e1db94e3d0479f2e7dc to your computer and use it in GitHub Desktop.
Save arnaudrenaud/1f953cc238884e1db94e3d0479f2e7dc to your computer and use it in GitHub Desktop.
Cheatsheet: Set up UFW firewall on a Linux web server

Set up UFW firewall on a Linux web server

For reference: https://www.webservertalk.com/ubuntu-firewall-how-to-configure-ufw/.

Run the following:

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22 # ⚠️ Replace by your actual SSH port (22 by default) — otherwise, SSH access will be lost after reboot!
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
sudo ufw status
sudo reboot

As of April 2024, Docker containers still overrides UFW rules, which means a container exposed to the host will be publicly exposed on the same port. Make sure UFW is enabled (sudo ufw enable) and follow this guide. Then reboot system and check if UFW is enabled (sudo ufw status).

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