Firewall with iptables

Quick notes into firewall

Basic command definition
iptables -A -i < interface > -p < protocol (tcp/udp) > -s < source > --dport < port no. > -j < target >

Check current iptables rulles
iptables -L -v

Enable localhost
iptables -A INPUT -i lo -j ACCEPT

Accept http / append rule into INPUT chain
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

After creating rulles for every traffic we want to accept, drop everything else
iptables -A INPUT -j DROP

Save iptables
iptables-save > /etc/iptables.up.rules
Restore iptables
iptables-restore < /etc/iptables.test.rules

Create in order to survive reboot
editor /etc/network/if-pre-up.d/iptables
- add following lines
/sbin/iptables-restore < /etc/iptables.up.rules

- make it executable
chmod +x /etc/network/if-pre-up.d/iptables