What you are talking about might be handled in one of two ways:

  1. a web proxy, that intercepts the web request and makes it on your behalf, returning either the working page or the search results. As McDarren noted earlier, this could be accomplished via a Squid proxy, among other methods.
  2. a DNS proxy, that intercepted the DNS query and made it on your behalf, returning the appropriate data if it existed, or the DNS information for the preferred search engine if such a site did not exist. Such a method would likely start with a look at the Net::DNS::Nameserver module.

Of the two options, option 1 seems the more accurate, as it can handle the situation of a missing page, whereas option 2 can only handle the case of a site that does not exist or is not responding. Consider the scenario in which you send requests to sites that do not exist over to a search engine found at a site called "www.mypreferredsearchengine.net", and a user attempting to go to a site called "www.mymissingsite.org", which does not exist.

Using option 1 (a web proxy), the following steps are likely to occur:

  1. User enters in the location bar of the browser the following address: http://www.mymissingsite.org:someport/some/path/to/some/page
  2. Browser parses the URL, determining that it needs to use the HTTP protocol, that the site to contact is "www.mymissingsite.org", and that the absolute path to request is "/some/path/to/some/page"
  3. Browser opens a TCP connection to the proxy server on port number "someport" (80 for HTTP, if not otherwise specified).
  4. Browser (supporting HTTP/1.0 and above) then transmits the following information:
    GET /some/path/to/some/page HTTP/1.0 Host: www.mymissingsite.org
  5. The proxy looks at those pages it currently has cached, and returns the data if found and the data has not expired yet. If not cached, it makes a request in a similar manner to the actual site.
  6. Because the proxy receives back an error (either in connecting, or in retrieving the page) and is configured to send the user to the search page on "www.mypreferredsearchengine.net" when an error is encountered, it assembles and makes an appropriate request to "www.mypreferredsearchengine.net" using the information from the URL as keywords.
  7. The proxy returns what data it receives to the browser, and closes the connection.
  8. Browser displays the data returned to it.

Using option 2 (a DNS proxy), the following steps are likely to occur:

  1. User enters in the location bar of the browser the following address: http://www.mymissingsite.org:someport/some/path/to/some/page
  2. Browser parses the URL, determining that it needs to use the HTTP protocol, that the site to contact is "www.mymissingsite.org", and that the absolute path to request is "/some/path/to/some/page"
  3. Browser asks the resolver for the address for "www.mymissingserver.org"
  4. Hypothetically, we have a program running (either locally, or on another machine) that is acting as a DNS resolver, and we are pointed to it. In such a case, the system's resolver makes the request to said program.
  5. Our DNS resolver replacement may check a local cache it maintains, other DNS servers it is aware of, or the root servers, attempting to locate a record for "www.mymissingsite.org", returning the actual data if found.
  6. On not finding information for "www.mymissingsite.org", our DNS resolver replacement instead returns (likely as a CNAME record) the value "www.mypreferredsearchengine.net".
  7. The browser then requests the IP address information for "www.mypreferredsearchengine.net" from the resolver.
  8. Process is repeated for "www.mypreferredsearchengine.net", which returns information (since our preferred search engine does exist).
  9. Browser opens a TCP connection to port number "someport" (80 for HTTP, if not otherwise specified).
  10. Browser (supporting HTTP/1.0 and above) then transmits the following information:
    GET /some/path/to/some/page HTTP/1.0 Host: www.mymissingsite.org
  11. The server www.mypreferredsearchengine.net may then do one of several different things before closing the connection:
    • It may return an error, because it is not configured to respond to a site called "www.mymissingsite.org".
    • It may attempt to use the default site for the server, but respond with an error because there is nothing that matches the path "some/path/to/some/page" in the default site.
    • It may return you to the default page for the default site, because it doesn't understand the request being made of it.
    • It could do something else not defined herein.
  12. Browser displays the data returned to it.

I hope that helps clear up the difference in the scenarios. For further reading (and where I obtained some of the data I adapted for the examples above-although any errors in the scenario's adaptation are my own),

Update: 18 Jan 2006: Added readmore tags around process descriptions because of length.


In reply to Re: DNS modification by atcroft
in thread DNS modification by Wils

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.