Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
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. –  mreithub Nov 19 '12 at 17:01
2  
And also getent hosts jksodf89s9df9sudfisdf.com to see what the libc resolver thinks. –  derobert Nov 19 '12 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... –  Steve Abraham Nov 19 '12 at 17:23
    
@mreithub: ** server can't find jksodf89s9df9sudfisdf.com: NXDOMAIN –  Steve Abraham Nov 19 '12 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) –  mreithub Nov 19 '12 at 17:26

1 Answer 1

up vote 4 down vote accepted

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

http://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).

share|improve this answer
    
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. –  Steve Abraham Nov 19 '12 at 20:05
    
@SteveAbraham You should be able to use dots in your URLs (e.g. curl http://checkip.dyndns.org./test.html). –  mreithub Nov 19 '12 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. :) –  Steve Abraham Nov 19 '12 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). –  derobert Nov 19 '12 at 21:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.