Skip to content

Q&A · Answered

How to set up UFW firewall on Ubuntu

asked 9 months, 1 week ago 1079 views 1 answer
0

I want to secure my Ubuntu server with a firewall. How do I configure UFW to allow only SSH and HTTP/HTTPS?

1 Answer

One accepted
25

Accepted answer

Not confirmed since it was written, 9 months, 1 week ago

Enable UFW

# 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 web traffic

# 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 verbose

Your answer

Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.

Shown beside your answer and never checked, so it cannot be a name someone already has here.

No account needed to answer. Sign in instead and it carries your name and earns reputation.