1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_DNS_SERVERS
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_DNS_CACHE_TIMEOUT (3)
9  - CURLOPT_DNS_LOCAL_IP4 (3)
10  - CURLOPT_DNS_LOCAL_IP6 (3)
11Protocol:
12  - All
13Added-in: 7.24.0
14---
15
16# NAME
17
18CURLOPT_DNS_SERVERS - DNS servers to use
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DNS_SERVERS, char *servers);
26~~~
27
28# DESCRIPTION
29
30Pass a char pointer that is the list of DNS servers to be used instead of the
31system default. The format of the dns servers option is:
32
33    host[:port][,host[:port]]...
34
35For example:
36
37    192.168.1.100,192.168.1.101,3.4.5.6
38
39The application does not have to keep the string around after setting this
40option.
41
42Using this option multiple times makes the last set string override the
43previous ones. Set it to NULL to disable its use again.
44
45# DEFAULT
46
47NULL
48
49# %PROTOCOLS%
50
51# EXAMPLE
52
53~~~c
54int main(void)
55{
56  CURL *curl = curl_easy_init();
57  if(curl) {
58    CURLcode res;
59    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
60    curl_easy_setopt(curl, CURLOPT_DNS_SERVERS,
61                     "192.168.1.100:53,192.168.1.101");
62    res = curl_easy_perform(curl);
63    curl_easy_cleanup(curl);
64  }
65}
66~~~
67
68# NOTES
69
70This option requires that libcurl was built with a resolver backend that
71supports this operation. The c-ares backend is the only such one.
72
73# %AVAILABILITY%
74
75# RETURN VALUE
76
77Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not,
78CURLE_NOT_BUILT_IN if support was disabled at compile-time,
79CURLE_BAD_FUNCTION_ARGUMENT when given an invalid server list, or
80CURLE_OUT_OF_MEMORY if there was insufficient heap space.
81