2

I have a weird issue on my server in that if I use curl or lynx to try and access a URL that doesn't exist (say a non registered domain, or a domain that's not in DNS), I don't get an error, it instead delivers me to the default locally hosted website.

For example:

"lynx http://jksodf89s9df9sudfisdf.com" or "curl http://jksodf89s9df9sudfisdf.com"

Both of these should clearly return an error (404, "Can't resolve", or something similar I'm guessing) as they don't exist - but instead I get the Apache holding page that is currently set as my default website for Apache on the server.

I can only assume it's a DNS or Apache config issue, but I just can't see what would allow non existant domains to be redirected to localhost.

6
  • 1
    What does nslookup jksodf89s9df9sudfisdf.com say? I think that it's a DNS issue as Apache itself has absolutely nothing to do with what curl/lynx/wget/... do to resolve hosts. Commented Nov 19, 2012 at 17:01
  • 2
    And also getent hosts jksodf89s9df9sudfisdf.com to see what the libc resolver thinks. Commented Nov 19, 2012 at 17:02
  • @derobert:78.31.104.52 jksodf89s9df9sudfisdf.com.*****.co.uk - so it's appending my own domain name to the end of the non existant domain... I've got wildcard DNS set up, so that certainly explains why it's ending up on localhost. I've no idea how to prevent that though, other than removing the wildcard DNS... Commented Nov 19, 2012 at 17:23
  • @mreithub: ** server can't find jksodf89s9df9sudfisdf.com: NXDOMAIN Commented Nov 19, 2012 at 17:24
  • 1
    There might be a search *****.co.uk line in your /etc/resolv.conf that you might want to remove (unless you depend on the domain expansion) Commented Nov 19, 2012 at 17:26

1 Answer 1

5

I think you're having the same issue as posted here:

https://serverfault.com/questions/296602/dns-wildcard-and-etc-resolv-conf-problem

Appending a dot to your fqdn queries should work around the issue:
curl http://jksodf89s9df9sudfisdf.com.

Or, if you don't rely on the wildcard DNS entry, just replace it by specific DNS entries for your subdomains (that's the better solution imo).

4
  • Well done, that was it. I can't use a . in URL, but I can do without the wildcard DNS entry for that domain - I'll shift it to another. Many thanks. Commented Nov 19, 2012 at 20:05
  • @SteveAbraham You should be able to use dots in your URLs (e.g. curl http://checkip.dyndns.org./test.html). Commented Nov 19, 2012 at 20:31
  • Unfortunately the code is pulling the URLs from a database of user supplied URLs (it's a bookmarking service I'm building). I could regex the . in, but that's adding a fair bit of extra processing. This seems to be working though - thanks very much for the help. :) Commented Nov 19, 2012 at 20:45
  • @SteveAbraham: You can also add a search entry to your resolv.conf to override the default of search-current-domain. I suspect search . would work (but have not tested it). Commented Nov 19, 2012 at 21:59

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.