I solved the problem by using Cloudflare's DNS in my Ubuntu desktop. I followed the steps mentioned in this article, under "Change DNS Nameserver via Network Settings" section. After this, the connection timeout issues disappeared.