The basic firewall in Ubuntu is UFW. So here’s how to use the basic UFW..
sudo ufw enable sudo ufw disable
Displays a warning that the firewall will be blocked on activation.
Allow and block UFW
- Port base, Service base:
sudo ufw allow <port>/<optional: protocol>
sudo ufw allow 80 sudo ufw allow 80/tcp sudo ufw allow http sudo ufw deny http
IP base:sudo ufw allow from <ip address>
sudo ufw allow from 192.168.0.1 sudo ufw allow from 192.168.0.0/24
UFW Advanced used
sudo ufw allow from <ip address> to <protocol> port <port number> proto <protocol name>
Allow 192.168.0.100 address and tcp protocol port 80
sudo ufw allow from 192.168.0.1 to any port 80
Delete UFW rule
When deleting a rule in UFW, insert the delete classification and the same rule as the Allow rule. At this time, you can check the rule through state and numbered.
sudo ufw allow from 192.168.0.1
sudo ufw delete from 192.168.0.1
UFW numbered rules
You can see the UFW rules with numbers attached. Rules are applied sequentially from top to bottom. You can use this to modify, delete, or add rules.
sudo ufw status numbered
sudo ufw delete 1
sudo ufw insert 1 allow http