Nextcloud CardDAV and CalDAV discovery with DNS records
Posted on 2022-02-17 in Software
I use a self-hosted Nextcloud instance to hold a lot of my personal data, and that includes my contacts and calendars. Recently I had to reinstall DAVx5 on my phone, and I was surprised that the Nextcloud account was failing to be added.
The DAVx5 error logs showed that it was making requests to the
/.well-known/carddav URLs, as described in RFC
6764. Nextcloud was returning
proper 301 HTTP responses, checked in a web browser, that redirected to the actual WebDAV
endpoint, so it looks like the problem was that DAVx5 wasn't properly following them.
Browsing the DAVx5 documentation on service discovery they mention that the DAV standard also supports using SRV and TXT DNS records pointing to the endpoints to be used for CardDAV and CalDAV, and I decide to give it a go as it sounded easier than further debugging DAVx5 or digging into Nextcloud's and/or the webserver's configuration.
I added the following DNS records to
_caldavs._tcp 10800 IN SRV 0 1 443 cloud.fidelramos.net. _caldavs._tcp 10800 IN TXT "path=/remote.php/dav/" _carddavs._tcp 10800 IN SRV 0 1 443 cloud.fidelramos.net. _carddavs._tcp 10800 IN TXT "path=/remote.php/dav/"
path I find by following
/.well-known/carddav URLs in my
Once the DNS records were in place DAVx5 connected successfully, but I had to use
fidelramos.net as the base URL, instead of
cloud.fidelramos.net as before.