Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cURL: Selecting a custom DNS server to resolve domain names
#!/usr/bin/env bash
# this can be useful when developing against a custom DNS server, or
# for example, if you made a change to the DNS settings of a domain, and you
# know the authoritative nameserver IP address for a domain, you could use this
# to bypass the intermediate DNS cache, and apply an HTTP request using the new
# DNS settings supplied by your specified (authoritative) nameserver
curl --dns-servers <dns.ip,dns.ip> url.com
# acquire the nameserver using
dig url.com NS
# then ping the NS to get its IP address
@LouWii

This comment has been minimized.

Copy link

@LouWii LouWii commented Mar 23, 2017

Ugh, it might not work depending on your libcurl curl: (4) A requested feature, protocol or option was not found built-in in this libcurl due to a build-time decision.

@icasimpan

This comment has been minimized.

Copy link

@icasimpan icasimpan commented Dec 21, 2017

I am also hitting this limitation which is quite common and I found an alternative which is to use --resolve:
curl --resolve domain:port:ip url.com

Example, for https://www.google.com:

curl --resolve www.google.com:443:172.217.10.132 www.google.com

@matthayter

This comment has been minimized.

Copy link

@matthayter matthayter commented Jan 31, 2018

For Mac and homebrew users: you can have brew compile curl for you with the --dns-servers option enabled via:

brew install curl --with-c-ares

@patrick-webs

This comment has been minimized.

Copy link

@patrick-webs patrick-webs commented Aug 31, 2018

For MacPorts users,

sudo port install curl +ares

to get this feature.

@SalimF

This comment has been minimized.

Copy link

@SalimF SalimF commented Dec 17, 2018

I got this error
A requested feature, protocol or option was not found built-in in this libcurl due to a build-time decision.

@mufid

This comment has been minimized.

Copy link

@mufid mufid commented May 27, 2020

I got this error
A requested feature, protocol or option was not found built-in in this libcurl due to a build-time decision.

@SalimF do you happen to find any solution?

@jacktan1991

This comment has been minimized.

Copy link

@jacktan1991 jacktan1991 commented Jul 27, 2020

For Mac and homebrew users: you can have brew compile curl for you with the --dns-servers option enabled via:

brew install curl --with-c-ares

I got:

Error: invalid option: --with-c-ares

@felipesere

This comment has been minimized.

Copy link

@felipesere felipesere commented Oct 21, 2020

I think by now its brew install curl-openssl

@AlphaWong

This comment has been minimized.

Copy link

@AlphaWong AlphaWong commented Feb 10, 2021

I think by now its brew install curl-openssl

upvote

@SalimF

This comment has been minimized.

Copy link

@SalimF SalimF commented Feb 12, 2021

@SalimF do you happen to find any solution?

I solve it by installing latest version my distro repository offers .

$ curl --version 
curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1i zlib/1.2.11 libidn2/2.3.0 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment