As a general rule, it's best to set a firewall to default deny, then add rules allowing traffic through. I would do something more like this:
Code:
iptables -F
iptables -F -t nat
iptables -A INPUT -p tcp --dport 22 -s 1.2.3.4 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -s 1.2.3.5 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -P INPUT DROP
The ESTABLISHED,RELATED line is critical. If you leave it out, then traffic related to existing connections will be blocked. Assuming that you don't want to forward any traffic, add this line:
Code:
iptables -P FORWARD DROP
Adding a startup script to Ubuntu is accomplished by adding the script to /etc/init.d/ then running update-rc.d.