Configure UFW on Ubuntu
Installation of UFW
UFW is already installed on Ubuntu 18.04. You can verify it from here
which ufw
Output:
root@vps:~# which ufw /usr/sbin/ufw
Enable/Disable/Reload UFW
Enable UFW
ufw enable
Disable UFW
ufw disable
Reload UFW
ufw reload
If you don’t receive output, you need to install UFW. Please refer the following commands.
sudo apt-get install ufw
Allow/Deny port
Allow port
ufw allow 80/tcp
Change the port which you want to open.
Deny port
ufw deny 80
Change the port which you want to deny
Check Status of UFW
ufw status
Listing Rules
To list the rules which we have in UFW, run the following command.
ufw status numbered
Output:
root@vps:~# ufw status numbered Status: active
To Action From
[ 1] 80/tcp ALLOW IN Anywhere [ 2] 80 DENY IN Anywhere [ 3] 80/tcp (v6) ALLOW IN Anywhere (v6) [ 4] 80 (v6) DENY IN Anywhere (v6)
Removing rules
First, check the status of UFW using the following command.
ufw status numbered
Output:
root@vps:~# ufw status numbered Status: active
To Action From
[ 1] 80/tcp ALLOW IN Anywhere [ 2] 80 DENY IN Anywhere [ 3] 80/tcp (v6) ALLOW IN Anywhere (v6) [ 4] 80 (v6) DENY IN Anywhere (v6)
This command will show the rules with numbers
Now remove the rule using the following command(Replace the 1 with the rule number which you want to remove)
ufw delete 1
Output:
root@vps:~# ufw delete 1 Deleting: allow 80/tcp Proceed with operation (y|n)? y Rule deleted root@vps:~#
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS