why bind9 gives connection refused for permission denied error when it is 777
You have the error right there in your output:
Feb 8 09:37:24 aname kernel: [1984823.682079] type=1400 audit(1454924244.439:45): apparmor="DENIED" operation="open" profile="/usr/sbin/named" name="/var/log/bind9/query.log" pid=27279 comm="named" requested_mask="c" denied_mask="c" fsuid=109 ouid=0
Add a
/var/log/bind9/query.log rw,
Stanza to /etc/apparmor.d/usr.sbin.named
, restart apparmor and bind services, and you're good to go.
And do restore file system permissions to the log file.