1<?xml version="1.0" encoding="ISO-8859-1"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!-- 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5 This file is generated from xml source: DO NOT EDIT 6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 7 --> 8<title>Issues Regarding DNS and Apache - Apache HTTP Server</title> 9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> 10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> 11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" /> 12<script src="/style/scripts/prettify.js" type="text/javascript"> 13</script> 14 15<link href="/images/favicon.ico" rel="shortcut icon" /></head> 16<body id="manual-page"><div id="page-header"> 17<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p> 18<p class="apache">Apache HTTP Server Version 2.2</p> 19<img alt="" src="/images/feather.gif" /></div> 20<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 21<div id="path"> 22<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="./">Version 2.2</a></div><div id="page-content"><div id="preamble"><h1>Issues Regarding DNS and Apache</h1> 23<div class="toplang"> 24<p><span>Available Languages: </span><a href="/en/dns-caveats.html" title="English"> en </a> | 25<a href="/ja/dns-caveats.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 26<a href="/ko/dns-caveats.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 27<a href="/tr/dns-caveats.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 28</div> 29 30 <p>This page could be summarized with the statement: don't 31 configure Apache in such a way that it relies on DNS resolution 32 for parsing of the configuration files. If Apache requires DNS 33 resolution to parse the configuration files then your server 34 may be subject to reliability problems (ie. it might not boot), 35 or denial and theft of service attacks (including users able 36 to steal hits from other users).</p> 37 </div> 38<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#example">A Simple Example</a></li> 39<li><img alt="" src="/images/down.gif" /> <a href="#denial">Denial of Service</a></li> 40<li><img alt="" src="/images/down.gif" /> <a href="#main">The "main server" Address</a></li> 41<li><img alt="" src="/images/down.gif" /> <a href="#tips">Tips to Avoid These Problems</a></li> 42<li><img alt="" src="/images/down.gif" /> <a href="#appendix">Appendix: Future Directions</a></li> 43</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 44<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 45<div class="section"> 46<h2><a name="example" id="example">A Simple Example</a></h2> 47 48 49 <div class="example"><p><code> 50 <VirtualHost www.abc.dom> <br /> 51 ServerAdmin webgirl@abc.dom <br /> 52 DocumentRoot /www/abc <br /> 53 </VirtualHost> 54 </code></p></div> 55 56 <p>In order for Apache to function properly, it absolutely needs 57 to have two pieces of information about each virtual host: the 58 <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> and at least one 59 IP address that the server will bind and respond to. The above 60 example does not include the IP address, so Apache must use DNS 61 to find the address of <code>www.abc.dom</code>. If for some 62 reason DNS is not available at the time your server is parsing 63 its config file, then this virtual host <strong>will not be 64 configured</strong>. It won't be able to respond to any hits 65 to this virtual host (prior to Apache version 1.2 the server 66 would not even boot).</p> 67 68 <p>Suppose that <code>www.abc.dom</code> has address 192.0.2.1. 69 Then consider this configuration snippet:</p> 70 71 <div class="example"><p><code> 72 <VirtualHost 192.0.2.1> <br /> 73 ServerAdmin webgirl@abc.dom <br /> 74 DocumentRoot /www/abc <br /> 75 </VirtualHost> 76 </code></p></div> 77 78 <p>This time Apache needs to use reverse DNS to find the 79 <code>ServerName</code> for this virtualhost. If that reverse 80 lookup fails then it will partially disable the virtualhost 81 (prior to Apache version 1.2 the server would not even boot). 82 If the virtual host is name-based then it will effectively be 83 totally disabled, but if it is IP-based then it will mostly 84 work. However, if Apache should ever have to generate a full 85 URL for the server which includes the server name, then it will 86 fail to generate a valid URL.</p> 87 88 <p>Here is a snippet that avoids both of these problems:</p> 89 90 <div class="example"><p><code> 91 <VirtualHost 192.0.2.1> <br /> 92 ServerName www.abc.dom <br /> 93 ServerAdmin webgirl@abc.dom <br /> 94 DocumentRoot /www/abc <br /> 95 </VirtualHost> 96 </code></p></div> 97 </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 98<div class="section"> 99<h2><a name="denial" id="denial">Denial of Service</a></h2> 100 101 102 <p>There are (at least) two forms that denial of service 103 can come in. If you are running a version of Apache prior to 104 version 1.2 then your server will not even boot if one of the 105 two DNS lookups mentioned above fails for any of your virtual 106 hosts. In some cases this DNS lookup may not even be under your 107 control; for example, if <code>abc.dom</code> is one of your 108 customers and they control their own DNS, they can force your 109 (pre-1.2) server to fail while booting simply by deleting the 110 <code>www.abc.dom</code> record.</p> 111 112 <p>Another form is far more insidious. Consider this 113 configuration snippet:</p> 114 115 <div class="example"><p><code> 116 <VirtualHost www.abc.dom><br /> 117 <span class="indent"> 118 ServerAdmin webgirl@abc.dom<br /> 119 DocumentRoot /www/abc<br /> 120 </span> 121 </VirtualHost><br /> 122 <br /> 123 <VirtualHost www.def.dom><br /> 124 <span class="indent"> 125 ServerAdmin webguy@def.dom<br /> 126 DocumentRoot /www/def<br /> 127 </span> 128 </VirtualHost> 129 </code></p></div> 130 131 <p>Suppose that you've assigned 192.0.2.1 to 132 <code>www.abc.dom</code> and 192.0.2.2 to 133 <code>www.def.dom</code>. Furthermore, suppose that 134 <code>abc.dom</code> has control of their own DNS. With this 135 config you have put <code>abc.dom</code> into a position where 136 they can steal all traffic destined to <code>def.dom</code>. To 137 do so, all they have to do is set <code>www.abc.dom</code> to 138 192.0.2.2. Since they control their own DNS you can't stop them 139 from pointing the <code>www.abc.dom</code> record wherever they 140 wish.</p> 141 142 <p>Requests coming in to 192.0.2.2 (including all those where 143 users typed in URLs of the form 144 <code>http://www.def.dom/whatever</code>) will all be served by 145 the <code>abc.dom</code> virtual host. To better understand why 146 this happens requires a more in-depth discussion of how Apache 147 matches up incoming requests with the virtual host that will 148 serve it. A rough document describing this <a href="vhosts/details.html">is available</a>.</p> 149 </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 150<div class="section"> 151<h2><a name="main" id="main">The "main server" Address</a></h2> 152 153 154 <p>The addition of <a href="vhosts/name-based.html">name-based 155 virtual host support</a> in Apache 1.1 requires Apache to know 156 the IP address(es) of the host that <code class="program"><a href="/programs/httpd.html">httpd</a></code> 157 is running on. To get this address it uses either the global 158 <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> 159 (if present) or calls the C function <code>gethostname</code> 160 (which should return the same as typing "hostname" at the 161 command prompt). Then it performs a DNS lookup on this address. 162 At present there is no way to avoid this lookup.</p> 163 164 <p>If you fear that this lookup might fail because your DNS 165 server is down then you can insert the hostname in 166 <code>/etc/hosts</code> (where you probably already have it so 167 that the machine can boot properly). Then ensure that your 168 machine is configured to use <code>/etc/hosts</code> in the 169 event that DNS fails. Depending on what OS you are using this 170 might be accomplished by editing <code>/etc/resolv.conf</code>, 171 or maybe <code>/etc/nsswitch.conf</code>.</p> 172 173 <p>If your server doesn't have to perform DNS for any other 174 reason then you might be able to get away with running Apache 175 with the <code>HOSTRESORDER</code> environment variable set to 176 "local". This all depends on what OS and resolver libraries you 177 are using. It also affects CGIs unless you use 178 <code class="module"><a href="/mod/mod_env.html">mod_env</a></code> to control the environment. It's best 179 to consult the man pages or FAQs for your OS.</p> 180 </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 181<div class="section"> 182<h2><a name="tips" id="tips">Tips to Avoid These Problems</a></h2> 183 184 185 <ul> 186 <li> 187 use IP addresses in 188 <code class="directive"><a href="/mod/core.html#virtualhost">VirtualHost</a></code> 189 </li> 190 191 <li> 192 use IP addresses in 193 <code class="directive"><a href="/mod/mpm_common.html#listen">Listen</a></code> 194 </li> 195 196 <li> 197 ensure all virtual hosts have an explicit 198 <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> 199 </li> 200 201 <li>create a <code><VirtualHost _default_:*></code> 202 server that has no pages to serve</li> 203 </ul> 204 </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 205<div class="section"> 206<h2><a name="appendix" id="appendix">Appendix: Future Directions</a></h2> 207 208 209 <p>The situation regarding DNS is highly undesirable. For 210 Apache 1.2 we've attempted to make the server at least continue 211 booting in the event of failed DNS, but it might not be the 212 best we can do. In any event, requiring the use of explicit IP 213 addresses in configuration files is highly undesirable in 214 today's Internet where renumbering is a necessity.</p> 215 216 <p>A possible work around to the theft of service attack 217 described above would be to perform a reverse DNS lookup on the 218 IP address returned by the forward lookup and compare the two 219 names -- in the event of a mismatch, the virtualhost would be 220 disabled. This would require reverse DNS to be configured 221 properly (which is something that most admins are familiar with 222 because of the common use of "double-reverse" DNS lookups by 223 FTP servers and TCP wrappers).</p> 224 225 <p>In any event, it doesn't seem possible to reliably boot a 226 virtual-hosted web server when DNS has failed unless IP 227 addresses are used. Partial solutions such as disabling 228 portions of the configuration might be worse than not booting 229 at all depending on what the webserver is supposed to 230 accomplish.</p> 231 232 <p>As HTTP/1.1 is deployed and browsers and proxies start 233 issuing the <code>Host</code> header it will become possible to 234 avoid the use of IP-based virtual hosts entirely. In this case, 235 a webserver has no requirement to do DNS lookups during 236 configuration. But as of March 1997 these features have not 237 been deployed widely enough to be put into use on critical 238 webservers.</p> 239 </div></div> 240<div class="bottomlang"> 241<p><span>Available Languages: </span><a href="/en/dns-caveats.html" title="English"> en </a> | 242<a href="/ja/dns-caveats.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 243<a href="/ko/dns-caveats.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 244<a href="/tr/dns-caveats.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 245</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div> 246<script type="text/javascript"><!--//--><![CDATA[//><!-- 247var comments_shortname = 'httpd'; 248var comments_identifier = 'http://httpd.apache.org/docs/2.2/dns-caveats.html'; 249(function(w, d) { 250 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 251 d.write('<div id="comments_thread"><\/div>'); 252 var s = d.createElement('script'); 253 s.type = 'text/javascript'; 254 s.async = true; 255 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 256 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 257 } 258 else { 259 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 260 } 261})(window, document); 262//--><!]]></script></div><div id="footer"> 263<p class="apache">Copyright 2013 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p> 264<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!-- 265if (typeof(prettyPrint) !== 'undefined') { 266 prettyPrint(); 267} 268//--><!]]></script> 269</body></html>