UFW is blocking DNS

The full correct syntax should be

sudo ufw allow out to any port 53

I solved this problem. I allowed the outgoing for port 53 that is DNS service port. Thanks.

sudo ufw allow out 53

Firstly ufw allow dns allows ingoing DNS requests, which is not what you want.

Secondly you can follow all commands mentioned in other answers (most easily ufw allow out 53), but order matters. So if you have a deny statement, which would also deny DNS requests when used solely, put it last!

So first allow port 53 to your DNS server and later potentially disallow/deny some requests.