← Tous les guides
UFW firewall setup on Ubuntu
Lock down an Ubuntu server to only the ports it actually needs, using UFW (Uncomplicated Firewall) -- a friendly frontend for iptables that ships with Ubuntu.
Ce guide est élaboré à partir de la documentation officielle de UFW firewall setup on Ubuntu, dont le lien figure ci-dessus — vérifiez toujours les noms exacts des paquets/versions avant d'exécuter ces commandes sur un serveur de production, car les versions de la distribution et du projet évoluent avec le temps.
1Set default policies
Deny everything inbound by default, then explicitly allow only what you need in the next steps.
sudo ufw default deny incomingsudo ufw default allow outgoing2Allow SSH before enabling the firewall
sudo ufw allow OpenSSHSkipping this step locks you out of a remote server the moment UFW is enabled -- always allow SSH (or your custom SSH port) FIRST.
3Allow any other services you're running
Add a rule per port/service actually in use -- e.g. 80/443 for a web server, or a specific app port.
sudo ufw allow 80/tcpsudo ufw allow 443/tcp4Enable the firewall
sudo ufw enable5Check the active rules
sudo ufw status verbose