Skip to main content

Protect your Linux server with UFW

·296 words·2 mins·
Linux Security Ufw
Dillon King
Author
Dillon King

What is UFW?
#

UFW(Uncomplicated Firewall) is a front end for the tool iptables, UFW makes setting up a firewall much easier.

Installing it
#

First make sure your Linux server is up to date.

sudo apt update && sudo apt upgrade

Install it

sudo apt install ufw

setting it up
#

Lets set it up

good starting point
#

For most servers you want to be default deny incoming traffic and then just expose the ports you need and allow all outgoing traffic

sudo ufw default deny incoming
sudo ufw default allow outgoing ```
# Important

Before we enable ufw we want to allow the port that you use for ssh or you will lose connection and you won't be able to access it.
you can do this with the command
```bash
sudo ufw allow ssh

This is the same as typing

sudo ufw allow 22

So If you use ssh on a port other than the default which is 22. By the way I think everyone should run it on different port. then you will want to type

sudo ufw allow <insert ssh port here>

Enable it
#

now we should be ready to enable it, to do this type

sudo ufw enable

To make it startup after being rebooted type

sudo systemctl enable ufw.service --now

For webservers
#

If you run a webserver you are going to want to enable port 80 and 443. 80 is http and 443 is https. to do this type

sudo ufw allow 80
sudo ufw allow 443

Conclusion
#

Every Linux server in my opinion should have a firewall setup as it is so easy to do as you can see in this guide. Check out some of my other posts for other linux and IT stuff.

Related

Raid Explained
·394 words·2 mins
Linux Storage Raid
Change Your Grub Theme
·373 words·2 mins
Grub Linux Boot
UEFI Not BIOS
·149 words·1 min
Computers Linux Uefi