---
title: 'UFW firewall setup on Ubuntu 20.04  | Zomro'
description: 'In this article, we will look at configuring the UFW firewall in Ubuntu 20.04.'
image: 'https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/1_fE4ibSW.jpg'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * UFW firewall setup on Ubuntu 20.04 



# UFW firewall setup on Ubuntu 20.04

14-05-2023

Nowadays, Internet security is one of the most important topics for discussion, as the number of malware, hacks and other threats is only increasing over time. As a security measure, many users and network administrators choose to set up a firewall that allows them to control incoming and outgoing connections. In this article, we will look at configuring the UFW firewall in Ubuntu 20.04.

UFW (Uncomplicated Firewall) is a firewall configuration tool designed to simplify the process of configuring and managing firewall rules. UFW uses iptables for network security and traffic management. It allows you to set rules to control access to specific ports and IP addresses.

## 

## **UFW installation**

Before you can start using UFW, you need to make sure it is installed on your Ubuntu server. To do this, run the following command:
    
    
    sudo apt-get update
    sudo apt-get install ufw

![UFW firewall setup on Ubuntu 20.04 - 1](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/1_fE4ibSW.jpg)

After installing UFW, you need to configure the rules that will control access to the network.

## 

## **Setting up rules**

By default, all incoming connections are blocked and only outgoing connections are allowed. If you want the server to be able to accept connections on a specific port, you must add a rule that allows incoming connections to that port.

For example, to allow incoming connections on port 22 for the SSH protocol, run the following command:
    
    
    sudo ufw allow ssh
    

![UFW firewall setup on Ubuntu 20.04 - 2](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/2_fS1r7JU.jpg)

If you are using a different port for the SSH protocol, you must specify it in the command:
    
    
    sudo ufw allow <номер порта>/tcp
    

![UFW firewall setup on Ubuntu 20.04 - 3](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/3_20kRSuO.jpg)

You can also allow incoming connections for other protocols such as HTTP and HTTPS by running the following commands:
    
    
    sudo ufw allow http
    sudo ufw allow https

![UFW firewall setup on Ubuntu 20.04 - 4](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/4_3FRnfbW.jpg)

If you want to allow access to a specific IP address, run the following command:
    
    
    sudo ufw allow from <ip-адрес>
    

![UFW firewall setup on Ubuntu 20.04 - 5](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/5_qM1zqWZ.jpg)

To deny access to a port, run the following command:
    
    
    sudo ufw deny <номер порта>/tcp
    

To remove a rule, run the following command:
    
    
    sudo ufw status numbered
    
    
    
    sudo ufw delete <number rule>
    

![UFW firewall setup on Ubuntu 20.04 - 6](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/6_8GKDcRp.jpg)

Result:

![UFW firewall setup on Ubuntu 20.04 - 7](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/7_u0FXRCv.jpg)

## 

## **Enable and disable**

After you have configured the firewall rules, you can enable UFW. To do this, run the following command:
    
    
    sudo ufw enable
    

When enabled, UFW will be launched automatically when the system boots.

To check the status of UFW, run the following command:
    
    
    sudo ufw status
    

![UFW firewall setup on Ubuntu 20.04 - 8](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/9.jpg)

The output will indicate the current state of UFW and a list of rules.

To disable UFW, run the following command:
    
    
    sudo ufw disable
    

However, it is not recommended to disable the firewall unnecessarily, as this can lead to vulnerabilities and security risks.

## **UFW settings management**

**​​​​​​​**

UFW has several settings that can be changed by default. For example, you can enable or disable port forwarding, allow access to a specific port only for a specific IP address, and other settings.

To change UFW settings, edit the **/etc/ufw/ufw.conf** file using a text editor:
    
    
    sudo nano /etc/ufw/ufw.conf
    

In the file, you can change the settings, such as:

\- **DEFAULT_INPUT_POLICY** \- incoming connection policy. Can be "DROP" (block all incoming connections by default) or "ACCEPT" (allow all incoming connections by default).  
\- **DEFAULT_FORWARD_POLICY** \- forward policy. Can be "DROP" (block all redirects by default) or "ACCEPT" (allow all redirects by default).  
\- **DEFAULT_OUTPUT_POLICY** \- outgoing connection policy. Can be "DROP" (block all outgoing connections by default) or "ACCEPT" (allow all outgoing connections by default).  
\- **IPV6** \- enable or disable IPv6.  
\- **LOGLEVEL** \- UFW logging level.

After changing the settings, you must restart UFW by running the following command:
    
    
    sudo ufw reload
    

![UFW firewall setup on Ubuntu 20.04 - 9](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/11.jpg)

**Conclusion**

Setting up a UFW firewall is an important step in securing your network and server. UFW allows you to control access to certain ports and IP addresses, block malware and other threats.

There are a few important things to keep in mind when configuring UFW. First of all, you need to define rules for all services and applications that should have access to the network. You should also make sure that security rules are not violated, including blocking access to sensitive data and disabling unnecessary services and ports.

In this article, we covered the basics of configuring the UFW firewall in Ubuntu 20.04, including installation, configuring rules, enabling and disabling, and managing settings. We hope this information will help you secure your network and server.

We also suggest you other useful articles:

  * [Updating/Downgrading PHP Versions on Ubuntu](https://zomro.com/blog/faq/436-updatingdowngrading-php-versions-on-ubuntu)
  * [Configuring Firewall with IPTables Ubuntu 20.04](https://zomro.com/blog/faq/361-configuring-firewall-with-iptables-ubuntu-2004)
  * [Changing Priority from IPv6 to IPv4 in Ubuntu and CentOS: A Complete Guide](https://zomro.com/blog/faq/471-changing-priority-from-ipv6-to-ipv4-in-ubuntu-and-centos-a-complete-guide)



Similar articles:

[Backups with site transfer on VestaCP/HestiaCP servers via mount](https://zomro.com/blog/faq/385-backups-with-site-transfer-on-vestacphestiacp-servers-via-mount) [How to file a complaint about abuse](https://zomro.com/blog/faq/595-kak-podat-zhalobu-na-zlopolzovanie) [Basics of working with the screen utility](https://zomro.com/blog/faq/295-rabota-s-utilitoj-screen) [How to create and delete an additional domain in cPanel?](https://zomro.com/blog/faq/190-kak-sozdat-i-udalit-dopolnitelnyj-domen-v-cpanel) [How to connect to a Docker container via sFTP](https://zomro.com/blog/faq/306-how-to-connect-to-a-docker-container-via-sftp)

[ Forex Server from €7.95/mon ](/server-for-forex)
