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
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms