*
First, ufw needs to be enabled. From a terminal prompt enter:
sudo ufw enable
*
To open a port (ssh in this example):
sudo ufw allow 22
*
Similarly, to close an opened port:
sudo ufw deny 22
*
To remove a rule, use delete followed by the rule:
sudo ufw delete deny 22
*
It is also possible to allow access from specific hosts or networks to a port. The following example allows ssh access from host 192.168.0.2 to any ip address on this host:
sudo ufw allow proto tcp from 192.168.0.2 to any port 22
Replace 192.168.0.2 with 192.168.0.0/24 to allow ssh access from the entire subnet.
*
ufw can be disabled by:
sudo ufw disable