The default firewall configuration tool for Ubuntu is ufw. ufw allows users to easily configure firewall rules.
To see the manual
Allow
syntax
1
| sudo ufw allow <port>/<optional: protocol>
|
Example to allow ssh traffic
Example to allow tcp traffic on port 53
allow from subnet networks
1 2 3
| ufw allow from 10.0.0.0/8 ufw allow from 172.16.0.0/12 ufw allow from 192.168.0.0/16
|
Deny
Example to deny a port
Enable and Disable ufw
Reload
Check status
sample output
1 2 3 4 5 6 7 8 9 10
| Status: active
To Action From -- ------ ---- 22:tcp DENY 192.168.0.1 22:udp DENY 192.168.0.1 22:tcp DENY 192.168.0.7 22:udp DENY 192.168.0.7 22:tcp ALLOW 192.168.0.0/24 22:udp ALLOW 192.168.0.0/24
|
check status and show rule number
Delete Rule by Number
To delete a rule, you need to fire use ufw status numbered
command to get the rule number and then delete using ufw delete
command.
Reference