First let's backup :)
sudo iptables-save > ./mybackup
If you lost connect and want KVM you can easy back to your start of backup
sudo iptables-restore < ./mybackup
Then you can start adding rules
sudo iptables -A INPUT -d YOURIPPUBLIC -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -d YOURIPPUBLIC -p tcp -m tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -d YOURIPPUBLIC -p tcp -m tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -d YOURIPPUBLIC -p tcp -m tcp --dport 22 -j DROP
sudo iptables -A INPUT -d YOURIPPUBLIC -j DROP
this above if you want make firewall for ip another than your instance, YOURIPPUBLIC : 33.33.33.33 or with netmask 33.33.33.33/32
RELATED,ESTABLISHED - If got before connect just skip all firewall next rules, To get connect this follow next rules :)
if you want whole network
sudo iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp -m tcp --dport 22 -j DROP
sudo iptables -A INPUT -j DROP
You can save for later to edit:
iptables-save > /.mynew.iptables.list.txt