0
I want to secure my Ubuntu server with a firewall. How do I configure UFW to allow only SSH and HTTP/HTTPS?
Loading...
Q&A · Answered
I want to secure my Ubuntu server with a firewall. How do I configure UFW to allow only SSH and HTTP/HTTPS?
Accepted answer
# Check status
sudo ufw status
# Set default policies
sudo ufw default deny incoming
sudo ufw default allow outgoing
# Allow SSH (important - do this before enabling!)
sudo ufw allow ssh
# or specific port
sudo ufw allow 22/tcp
# Allow HTTP and HTTPS
sudo ufw allow http
sudo ufw allow https
# or
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# Enable firewall
sudo ufw enable
# Check rules
sudo ufw status verboseSay what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.