How to Block Ports in UFW Ubuntu Firewall
In the last tutorial we learn how to open ports in Ubuntu Firewall. In This tutorial we are going to learn how to block network ports in Ubuntu using UFW Firewall.
To block a port in UFW we use ufw deny command
ufw deny port/protocol
Examples
ufw deny 53
This rule will block the port 53 on Ubuntu for both TCP and UDP protocol (Since we didn't specify the protocol).
ufw deny 21/tcp
This Firewall rule will block the TCP port 21 from the Ubuntu Firewall.
Example : Block a port from specific IP Address
ufw deny from 192.168.1.50 to any port 22 proto tcp
This firewall rule will block the ssh port 22 to from IP ADDRESS 192.168.1.50.
The default behavior of the Ubuntu Firewall is to block all incoming traffic, So you do not want to block ports explicitly unless you set the default firewall policy to allow all incoming traffic.