Ubuntu Core 16

Hello,
I want to allow some specific connection in Ubuntu Core 16.
allow SSH connection
allow MQTT specific broker address
allow REST client ip address.

I have problem in MQTT connection it will block if I m DENY INPUT
here some code for MQTT -

This will connect MQTT but rest of client also connect it. so here create problem
iptables -A OUTPUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT

This below IP address I want to allow rest of all DENY but not work properly
iptables -A INPUT -p tcp -s $ip(xx.xx.xx.x) --dport $port -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s $ip --dport $port -m state --state NEW,ESTABLISHED -j ACCEPT

Thanks.