ufw

ufw, or uncomplicated firewall, is a command-line application that ships with Ubuntu to setup iptables.

Once you enable ufw with ufw enable, it will add the firewall to the startup services.

Examples

ufw allow proto tcp to any port 22
ufw allow proto tcp to any port 80
ufw allow proto tcp to any port 222
ufw allow proto tcp to any port 443
ufw allow proto tcp to any port 10000
ufw enable

Allow connections from local subnet, and specific outside IP address:

ufw allow from 192.168.12.0/24
ufw allow from 1.2.3.4

Start firewall

ufw enable #interactive
yes y | ufw enable # batch

Show firewall status

ufw status

Stop firewall

ufw disable

Display existing rules:

ufw status numbered

Delete existing rule:

ufw delete <rule number>

Save iptables rules

iptables-save > foo