1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 5 6<html xmlns="http://www.w3.org/1999/xhtml"> 7 <head> 8 <meta name="generator" content="HTML Tidy, see www.w3.org" /> 9 10 <title>Issues Regarding DNS and Apache</title> 11 </head> 12 <!-- Background white, links blue (unvisited), navy (visited), red (active) --> 13 14 <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" 15 vlink="#000080" alink="#FF0000"> 16 <div align="CENTER"> 17 <img src="images/sub.gif" alt="[APACHE DOCUMENTATION]" /> 18 19 <h3>Apache HTTP Server</h3> 20 </div> 21 22 23 24 <h1 align="CENTER">Issues Regarding DNS and Apache</h1> 25 26 <p>This page could be summarized with the statement: <em>don't 27 require Apache to use DNS for any parsing of the configuration 28 files</em>. If Apache has to use DNS to parse the configuration 29 files then your server may be subject to reliability problems 30 (it might not boot), or denial and theft of service attacks 31 (including users able to steal hits from other users).</p> 32 33 <h3>A Simple Example</h3> 34 Consider this configuration snippet: 35 36 <blockquote> 37<pre> 38 <VirtualHost www.abc.dom> 39 ServerAdmin webgirl@abc.dom 40 DocumentRoot /www/abc 41 </VirtualHost> 42</pre> 43 </blockquote> 44 45 <p>In order for Apache to function properly it absolutely needs 46 to have two pieces of information about each virtual host: the 47 <a href="mod/core.html#servername"><code>ServerName</code></a> 48 and at least one IP address that the server responds to. This 49 example does not include the IP address, so Apache must use DNS 50 to find the address of <code>www.abc.dom</code>. If for some 51 reason DNS is not available at the time your server is parsing 52 its config file, then this virtual host <strong>will not be 53 configured</strong>. It won't be able to respond to any hits to 54 this virtual host (prior to Apache version 1.2 the server would 55 not even boot).</p> 56 57 <p>Suppose that <code>www.abc.dom</code> has address 10.0.0.1. 58 Then consider this configuration snippet:</p> 59 60 <blockquote> 61<pre> 62 <VirtualHost 10.0.0.1> 63 ServerAdmin webgirl@abc.dom 64 DocumentRoot /www/abc 65 </VirtualHost> 66</pre> 67 </blockquote> 68 69 <p>Now Apache needs to use reverse DNS to find the 70 <code>ServerName</code> for this virtualhost. If that reverse 71 lookup fails then it will partially disable the virtualhost 72 (prior to Apache version 1.2 the server would not even boot). 73 If the virtual host is name-based then it will effectively be 74 totally disabled, but if it is IP-based then it will mostly 75 work. However if Apache should ever have to generate a full URL 76 for the server which includes the server name then it will fail 77 to generate a valid URL.</p> 78 79 <p>Here is a snippet that avoids both of these problems.</p> 80 81 <blockquote> 82<pre> 83 <VirtualHost 10.0.0.1> 84 ServerName www.abc.dom 85 ServerAdmin webgirl@abc.dom 86 DocumentRoot /www/abc 87 </VirtualHost> 88</pre> 89 </blockquote> 90 91 <h3>Denial of Service</h3> 92 93 <p>There are (at least) two forms that denial of service can 94 come in. If you are running a version of Apache prior to 95 version 1.2 then your server will not even boot if one of the 96 two DNS lookups mentioned above fails for any of your virtual 97 hosts. In some cases this DNS lookup may not even be under your 98 control. For example, if <code>abc.dom</code> is one of your 99 customers and they control their own DNS then they can force 100 your (pre-1.2) server to fail while booting simply by deleting 101 the <code>www.abc.dom</code> record.</p> 102 103 <p>Another form is far more insidious. Consider this 104 configuration snippet:</p> 105 106 <blockquote> 107<pre> 108 <VirtualHost www.abc.dom> 109 ServerAdmin webgirl@abc.dom 110 DocumentRoot /www/abc 111 </VirtualHost> 112</pre> 113 </blockquote> 114 115 <blockquote> 116<pre> 117 <VirtualHost www.def.dom> 118 ServerAdmin webguy@def.dom 119 DocumentRoot /www/def 120 </VirtualHost> 121</pre> 122 </blockquote> 123 124 <p>Suppose that you've assigned 10.0.0.1 to 125 <code>www.abc.dom</code> and 10.0.0.2 to 126 <code>www.def.dom</code>. Furthermore, suppose that 127 <code>def.com</code> has control of their own DNS. With this 128 config you have put <code>def.com</code> into a position where 129 they can steal all traffic destined to <code>abc.com</code>. To 130 do so, all they have to do is set <code>www.def.dom</code> to 131 10.0.0.1. Since they control their own DNS you can't stop them 132 from pointing the <code>www.def.com</code> record wherever they 133 wish.</p> 134 135 <p>Requests coming in to 10.0.0.1 (including all those where 136 users typed in URLs of the form 137 <code>http://www.abc.dom/whatever</code>) will all be served by 138 the <code>def.com</code> virtual host. To better understand why 139 this happens requires a more in-depth discussion of how Apache 140 matches up incoming requests with the virtual host that will 141 serve it. A rough document describing this <a 142 href="vhosts/details.html">is available</a>.</p> 143 144 <h3>The "main server" Address</h3> 145 146 <p>The addition of <a href="vhosts/name-based.html">name-based 147 virtual host support</a> in Apache 1.1 requires Apache to know 148 the IP address(es) of the host that httpd is running on. To get 149 this address it uses either the global <code>ServerName</code> 150 (if present) or calls the C function <code>gethostname</code> 151 (which should return the same as typing "hostname" at the 152 command prompt). Then it performs a DNS lookup on this address. 153 At present there is no way to avoid this lookup.</p> 154 155 <p>If you fear that this lookup might fail because your DNS 156 server is down then you can insert the hostname in 157 <code>/etc/hosts</code> (where you probably already have it so 158 that the machine can boot properly). Then ensure that your 159 machine is configured to use <code>/etc/hosts</code> in the 160 event that DNS fails. Depending on what OS you are using this 161 might be accomplished by editing <code>/etc/resolv.conf</code>, 162 or maybe <code>/etc/nsswitch.conf</code>.</p> 163 164 <p>If your server doesn't have to perform DNS for any other 165 reason then you might be able to get away with running Apache 166 with the <code>HOSTRESORDER</code> environment variable set to 167 "local". This all depends on what OS and resolver libraries you 168 are using. It also affects CGIs unless you use <a 169 href="mod/mod_env.html"><code>mod_env</code></a> to control the 170 environment. It's best to consult the man pages or FAQs for 171 your OS.</p> 172 173 <h3><a id="tips" name="tips">Tips to Avoid these 174 problems</a></h3> 175 176 <ul> 177 <li>use IP addresses in <code><VirtualHost></code></li> 178 179 <li>use IP addresses in <code>Listen</code></li> 180 181 <li>use IP addresses in <code>BindAddress</code></li> 182 183 <li>ensure all virtual hosts have an explicit 184 <code>ServerName</code></li> 185 186 <li>create a <code><VirtualHost _default_:*></code> 187 server that has no pages to serve</li> 188 </ul> 189 190 <h3>Appendix: Future Directions</h3> 191 192 <p>The situation regarding DNS is highly undesirable. For 193 Apache 1.2 we've attempted to make the server at least continue 194 booting in the event of failed DNS, but it might not be the 195 best we can do. In any event requiring the use of explicit IP 196 addresses in configuration files is highly undesirable in 197 today's Internet where renumbering is a necessity.</p> 198 199 <p>A possible work around to the theft of service attack 200 described above would be to perform a reverse DNS lookup on the 201 IP address returned by the forward lookup and compare the two 202 names. In the event of a mismatch the virtualhost would be 203 disabled. This would require reverse DNS to be configured 204 properly (which is something that most admins are familiar with 205 because of the common use of "double-reverse" DNS lookups by 206 FTP servers and TCP wrappers).</p> 207 208 <p>In any event it doesn't seem possible to reliably boot a 209 virtual-hosted web server when DNS has failed unless IP 210 addresses are used. Partial solutions such as disabling 211 portions of the configuration might be worse than not booting 212 at all depending on what the webserver is supposed to 213 accomplish.</p> 214 215 <p>As HTTP/1.1 is deployed and browsers and proxies start 216 issuing the <code>Host</code> header it will become possible to 217 avoid the use of IP-based virtual hosts entirely. In this event 218 a webserver has no requirement to do DNS lookups during 219 configuration. But as of March 1997 these features have not 220 been deployed widely enough to be put into use on critical 221 webservers. <hr /> 222 223 <h3 align="CENTER">Apache HTTP Server</h3> 224 <a href="./"><img src="images/index.gif" alt="Index" /></a> 225 226 </p> 227 </body> 228</html> 229 230 231 232