CURLOPT_DNS_SERVERS(3)

πŸ’… CURLOPT_DNS_SERVERS πŸ’…

Okay bestie, welcome to the CURLOPT_DNS_SERVERS page from the libcurl Library Functions Manual β€” yes that's the whole vibe, we're in the curl docs now, and honestly? iconic.

✨ NAME ✨

CURLOPT_DNS_SERVERS β€” the DNS servers to use, aka you get to pick who resolves your stuff instead of letting the system decide. main character energy fr.

πŸŽ€ SYNOPSIS πŸŽ€

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DNS_SERVERS, char *servers);

🌸 DESCRIPTION 🌸

So you pass a char pointer that is literally the list of DNS servers to be used instead of the system default. Not vibing with whatever your system picked? Now you can hand-pick them. Obsessed.

The format of the dns servers option is:

host[:port][,host[:port]]...

For example:

192.168.1.100,192.168.1.101,3.4.5.6

And the bestie part? The application does not have to keep the string around after setting this option β€” like, you can let that string go, it's fine, curl's got it. 🫢

Using this option multiple times makes the last set string override the previous ones. Newest wins, always. And set it to NULL to disable its use again (bye bye custom servers πŸ’€).

πŸ‘‘ DEFAULT πŸ‘‘

NULL

πŸ¦‹ PROTOCOLS πŸ¦‹

This functionality affects all supported protocols β€” every single one, no cap.

πŸ”₯ EXAMPLE πŸ”₯

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
    curl_easy_setopt(curl, CURLOPT_DNS_SERVERS,
                     "192.168.1.100:53,192.168.1.101");
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

Look at that β€” one server with an explicit :53 port, one without. Slay.

⭐ NOTES ⭐

Heads up bestie, this one's a lil picky: this option requires that libcurl was built with a resolver backend that supports this operation. And the c-ares backend is the only such one. Like, the only one. Periodt. So if you're not on c-ares, this does nothing and that's just how it is 😭.

🌈 AVAILABILITY 🌈

Added in curl 7.24.0 β€” a classic, a legend.

πŸ’– RETURN VALUE πŸ’–

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK β€” we love to see it ✨. Non-zero means an error occurred, see libcurl-errors(3) for the whole tea.

🧚 SEE ALSO 🧚


That's the whole page, bestie β€” go forth and resolve responsibly πŸ’…βœ¨

This lil gem is from libcurl, dated 2026-10-12 β€” mwah, sign-off complete πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from