Category Archives: curl

If you’ve ever encountered this, you probably spent a fair amount of time scratching your head over it before it got resolved. Recently, I’ve seen this issue arise twice with clients, so I figured it was time to document it so that perhaps a google search might hit this record and help others.

If you’re currently finding that your curl requests resolve to your server rather than giving you a “Couldn’t resolve host” error, I’m betting the following details are true:

1) You have a wildcard DNS entry for your domain
2) That domain with the wildcard entry is your “search” line in /etc/resolv.conf

What this looks like:

First, we pick a domain we know doesn’t exist:

(~) # dig thisdontexistanywhereatall.com +short
(~) #

Then we curl it:

(~) # curl -I thisdontexistanywhereatall.com
HTTP/1.1 301 Moved Permanently
Date: Sun, 21 Feb 2016 19:44:33 GMT
Server: Apache/2.2.15 (CentOS)
Location: http://alex.darke.net/
Connection: close
Content-Type: text/html; charset=iso-8859-1

What? Why is a non-existent domain being responded to by MY server?

What’s happening is this:

A) The curl request looks up the domain and finds no record for it
B) the DNS libraries called then assume that it might be a subdomain and so it checks the search domain defined in /etc/resolv.cnf
C) because there is a wildcard DNS entry for my domain, it results in a match for thisdontexistanywhereatall.com.darke.net

To fix this, you can simply append a . to the end of the domain you are curling. This keeps step B and C from happening:

(~) # curl thisdontexistanywhereatall.com.
curl: (6) Couldn't resolve host 'thisdontexistanywhereatall.com.'

To prevent having to append that . each and every time, you can also elect to put a domain without a wildcard DNS entry in the /etc/resolv.conf.

Hopefully this helps the next guy.


Category: curl, dns, linux

Categories


gives good tech

tech.superhappykittymeow.com
Kale is one of the smartest people I know

Racker Hacker
Major is always good for leet deetz