Thank you @d19dotca @nebulon @robi for your replies. I use adguard on the same server which allows for DNS rewrites. I guess I was trying to achieve what Resilio sync does (e.g. connect to peers using LAN when in LAN).
In this case, I wanted to try by pointing the DNS name of nextcloud installation to local server IP:port. I am not sure if this will be possible (probably not right? unless I change the server itself in my nextcloud client?). If it's not possible, it is OK I guess.