CURLOPT_DNS_INTERFACE(3)

πŸ’… CURLOPT_DNS_INTERFACE(3) β€” the curl library functions manual, bestie edition πŸŽ€

okay so real talk, this page lives in the libcurl corner of the manual (the Library Functions Manual one), and it's about CURLOPT_DNS_INTERFACE(3). yes that's the whole title. slay. let's get into it ✨


πŸ¦‹ NAME

CURLOPT_DNS_INTERFACE β€” the interface to speak DNS over, periodt


🌸 SYNOPSIS

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DNS_INTERFACE, char *ifname);

that's it. that's the whole vibe check. handle is your curl handle, ifname is the interface name, and it comes back at you as a CURLcode. 🫢


πŸ’– DESCRIPTION

so you pass a char pointer as the parameter, and what it does is set the name of the network interface that the DNS resolver should bind to. key detail, bestie: it has to be an interface name, not an address. like "eth0" energy, not "192.168.1.5" energy. do not mix those up, i'm literally begging πŸ™ˆ

and if you set this option to NULL, it just goes back to the default setting, which is not binding to a specific interface at all. freedom. no cap.

also, good news: the application does not have to keep the string around after setting this option. you can let it go, she's fine, she's got her own copy πŸ’…

setting this option multiple times? the last string you set overrides all the previous ones. last one wins, main character energy only πŸ‘‘. and setting it to NULL disables its use again.


πŸ“ DEFAULT

NULL

(no interface bound, just vibes 🌈)


πŸ”₯ PROTOCOLS

this functionality affects all supported protocols. all of them. every single one. iconic ⭐


✨ EXAMPLE

here's the whole thing, copy it exactly, don't @ me:

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_INTERFACE, "eth0");
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

look at her go, binding DNS to eth0 and fetching https://example.com/foo.bin. we love a functional snippet 🧚


πŸ’€ NOTES

⚠️ okay this is the important caveat so listen up: 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.

so if you're not on c-ares, this option is giving nothing. literally nothing. check your build first bestie 😭


πŸŽ€ AVAILABILITY

Added in curl 7.33.0. vintage. a classic πŸ’œ


🌟 RETURN VALUE

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

CURLE_OK (0) means everything was OK. non-zero means an error occurred β€” go check libcurl-errors(3) for the tea 🍡.


πŸ¦‹ SEE ALSO


okay that's the whole page, you're officially educated πŸ’– this was libcurl, dated 2026-10-12, and the page was CURLOPT_DNS_INTERFACE(3) β€” go bind an interface, stay hydrated, and remember: interface name, not address. mwah 🫢✨

πŸ“¦ where this page comes from