How to Set Up Firewall with UFW on Ubuntu 20.04


Posted by Wes on 2020-11-12

UFW

UFW, or Uncomplicated Firewall, is a simplified firewall management interface that hides the complexity of lower-level packet filtering technologies such as iptables and nftables.

Enabling UFW

sudo ufw enable

You will be prompted to confirm the operation by pressing y, then ENTER.

Command may disrupt existing ssh connections. Proceed with operation (y|n)?

Allowing Connections

sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw allow mysql

or

sudo ufw allow 22
sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 3306

Checking UFW Status and Rules

sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW IN    Anywhere
22                         ALLOW IN    Anywhere
80/tcp                     ALLOW IN    Anywhere
443/tcp                    ALLOW IN    Anywhere
3306/tcp                   ALLOW IN    Anywhere
22/tcp (v6)                ALLOW IN    Anywhere (v6)
22 (v6)                    ALLOW IN    Anywhere (v6)
80/tcp (v6)                ALLOW IN    Anywhere (v6)
443/tcp (v6)               ALLOW IN    Anywhere (v6)
3306/tcp (v6)              ALLOW IN    Anywhere (v6)

or

sudo ufw status numbered
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 22/tcp                     ALLOW IN    Anywhere
[ 2] 22                         ALLOW IN    Anywhere
[ 3] 80/tcp                     ALLOW IN    Anywhere
[ 4] 443/tcp                    ALLOW IN    Anywhere
[ 5] 3306/tcp                   ALLOW IN    Anywhere
[ 6] 22/tcp (v6)                ALLOW IN    Anywhere (v6)
[ 7] 22 (v6)                    ALLOW IN    Anywhere (v6)
[ 8] 80/tcp (v6)                ALLOW IN    Anywhere (v6)
[ 9] 443/tcp (v6)               ALLOW IN    Anywhere (v6)
[10] 3306/tcp (v6)              ALLOW IN    Anywhere (v6)

References

  1. How To Set Up a Firewall with UFW on Ubuntu 20.04 | DigitalOcean
  2. UFW - Community Help Wiki - Official Ubuntu Documentation
  3. Uncomplicated Firewall (ufw) - Ubuntu Wiki
  4. Ubuntu Manpage: ufw - program for managing a netfilter firewall
  5. 如何遠端連接虛擬主機上的 mySQL 資料庫 ?

#UFW #Firewall #ubuntu







Related Posts

JavaScirpt - async/await

JavaScirpt - async/await

優化程式碼

優化程式碼

MTR04_1119

MTR04_1119


Comments