Setup Firewall in Ubuntu 20.04 Server

Firewall is important in any server setup. It helps to allow required network traffic and restricts rest. Most importantly if firewall is not set correctly then it would open doors for the hackers. Following tutorial on setting up firewall in Ubuntu 20.04 Server is helpful to set it right.

Login with your user name and password that has super user privileges.(If you have not created user with super user privileges then follow previous chapter. All the chapter list is present below.)

OpenSSH

OpenSSH is the default firewall configuration tool in Ubuntu operating system.

Because we are going to access Ubuntu server through ssh connection, so must allow network traffic through this firewall.

test@tester:~$ sudo ufw allow OpenSSH

The above command would allow all network traffic through openssh. If the above command is successfully executed then it will print ‘Rules updated’

Then its time to enable the firewall rule.

test@tester:~$ sudo ufw enable

Now, lets check the firewall rule status. Use following command.

test@tester:~$ sudo ufw status

Result
Status: active

To                          Action                   From
—                            ——                      —-
OpenSSH            ALLOW            Anywhere
OpenSSH (v6)   ALLOW          Anywhere (v6)