Enable the Built-in Ubuntu Firewall:
sudo ufw enable
Allow Port 22:
sudo ufw allow 22/tcp
Allow SSH:
sudo ufw allow SSH
Allow traffic from IP 12.34.56.78 to all ports:
sudo ufw allow from 12.34.56.78
Allow traffic from IP 12.34.56.78 to port 22:
sudo ufw allow from 12.34.56.78 to any port 22
Deny outbound SSH:
sudo ufw reject out ssh
Deny TCP traffic from the IP 12.34.56.78 to port 22 on the local system:
sudo ufw deny proto tcp from 12.34.56.78 to any port 22
View the ufw status:
sudo ufw status
View the ufw status numbered:
sudo ufw status numbered
View the ufw status verbose:
sudo ufw status verbose
Delete a rule:
sudo ufw delete reject out ssh
Delete a rule by number:
sudo ufw delete 6
Reset ufw:
sudo ufw reset
Some applications requiring open ports come with ufw profiles to make this even easier. To see the application profiles available on your local system, run the following command:
sudo ufw app list
View information about a profile and its included rules with the following command:
sudo ufw app info ApplicationName
Allow an application profile with the allow command:
sudo ufw allow ApplicationName
Logging is disabled by default, but you can also enable logging to print firewall messages to the system log:
sudo ufw logging on
GUFW is a graphical interface for ufw. Ubuntu doesn’t come with a graphical interface, but gufw is included in Ubuntu’s software repositories. You can install it with the following command:
sudo apt-get install gufw
Source: https://www.howtogeek.com/115116/how-to-configure-ubuntus-built-in-firewall/
Source: https://fedingo.com/how-to-check-open-ports-in-ufw/