How to install and enable UFW firewall on Ubuntu

Ubuntu UFW

If you need to install easy to use firewall to your ubuntu server, you can easily use UFW. And here’s how.

It’s somewhat tricky to use IPTABLES. So ufw is more easy to use in micro services and basic web servers.

Ufw usually comes installed in ubuntu servers. If not, you can always easily install it from apt.

sudo apt install ufw

To check if ufw running:

sudo ufw status

Then if you need to see previous rules set, then you can try:

sudo ufw show added

Now, you need to make sure not to block your SSH connection after enabling ufw. You could lock yourself out by mistake. Let’s add ssh to allowed rules.

sudo ufw allow ssh

If you have changed your SSH PORT, or just need to allow other ports, you can always allow ports by numbers.

sudo ufw allow 22/tcp

If you are running a web server, then you need to allow http and https ports.

sudo ufw allow http
sudo ufw allow https

You can check the configuration with status verbose.

sudo ufw status verbose

If you are sure your configuration is right. Then you can enable UFW.

sudo ufw enable

Ufw is going to be active even when you restart your server.

I hope these commands help you in your work.

Thank you.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *