1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <manualpage metafile="dns-caveats.xml.meta">
25 <title>Issues Regarding DNS and Apache HTTP Server</title>
28 <p>This page could be summarized with the statement: don't
29 configure Apache HTTP Server in such a way that it relies on DNS resolution
30 for parsing of the configuration files. If httpd requires DNS
31 resolution to parse the configuration files then your server
32 may be subject to reliability problems (ie. it might not start up),
33 or denial and theft of service attacks (including virtual hosts able
34 to steal hits from other virtual hosts).</p>
37 <section id="example">
38 <title>A Simple Example</title>
40 <highlight language="config">
41 # This is a misconfiguration example, do not use on your server
42 <VirtualHost www.example.dom>
43 ServerAdmin webgirl@example.dom
44 DocumentRoot "/www/example"
48 <p>In order for the server to function properly, it absolutely needs
49 to have two pieces of information about each virtual host: the
50 <directive module="core">ServerName</directive> and at least one
51 IP address that the server will bind and respond to. The above
52 example does not include the IP address, so httpd must use DNS
53 to find the address of <code>www.example.dom</code>. If for some
54 reason DNS is not available at the time your server is parsing
55 its config file, then this virtual host <strong>will not be
56 configured</strong>. It won't be able to respond to any hits
57 to this virtual host.</p>
59 <p>Suppose that <code>www.example.dom</code> has address 192.0.2.1.
60 Then consider this configuration snippet:</p>
62 <highlight language="config">
63 # This is a misconfiguration example, do not use on your server
64 <VirtualHost 192.0.2.1>
65 ServerAdmin webgirl@example.dom
66 DocumentRoot "/www/example"
70 <p>This time httpd needs to use reverse DNS to find the
71 <code>ServerName</code> for this virtualhost. If that reverse
72 lookup fails then it will partially disable the virtualhost.
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 httpd should ever have to generate a full
76 URL for the server which includes the server name (such as when a
77 Redirect is issued), then it will fail to generate a valid URL.</p>
79 <p>Here is a snippet that avoids both of these problems:</p>
81 <highlight language="config">
82 <VirtualHost 192.0.2.1>
83 ServerName www.example.dom
84 ServerAdmin webgirl@example.dom
85 DocumentRoot "/www/example"
91 <title>Denial of Service</title>
93 <p>Consider this configuration snippet:</p>
95 <highlight language="config">
96 <VirtualHost www.example1.dom>
97 ServerAdmin webgirl@example1.dom
98 DocumentRoot "/www/example1"
100 <VirtualHost www.example2.dom>
101 ServerAdmin webguy@example2.dom
102 DocumentRoot "/www/example2"
106 <p>Suppose that you've assigned 192.0.2.1 to
107 <code>www.example1.dom</code> and 192.0.2.2 to
108 <code>www.example2.dom</code>. Furthermore, suppose that
109 <code>example1.dom</code> has control of their own DNS. With this
110 config you have put <code>example1.dom</code> into a position where
111 they can steal all traffic destined to <code>example2.dom</code>. To
112 do so, all they have to do is set <code>www.example1.dom</code> to
113 192.0.2.2. Since they control their own DNS you can't stop them
114 from pointing the <code>www.example1.dom</code> record wherever they
117 <p>Requests coming in to 192.0.2.2 (including all those where
118 users typed in URLs of the form
119 <code>http://www.example2.dom/whatever</code>) will all be served by
120 the <code>example1.dom</code> virtual host. To better understand why
121 this happens requires a more in-depth discussion of how httpd
122 matches up incoming requests with the virtual host that will
123 serve it. A rough document describing this <a
124 href="vhosts/details.html">is available</a>.</p>
128 <title>The "main server" Address</title>
130 <p><a href="vhosts/name-based.html">Name-based
131 virtual host support</a> requires httpd to know
132 the IP address(es) of the host that <program>httpd</program>
133 is running on. To get this address it uses either the global
134 <directive module="core">ServerName</directive>
135 (if present) or calls the C function <code>gethostname</code>
136 (which should return the same as typing "hostname" at the
137 command prompt). Then it performs a DNS lookup on this address.
138 At present there is no way to avoid this lookup.</p>
140 <p>If you fear that this lookup might fail because your DNS
141 server is down then you can insert the hostname in
142 <code>/etc/hosts</code> (where you probably already have it so
143 that the machine can boot properly). Then ensure that your
144 machine is configured to use <code>/etc/hosts</code> in the
145 event that DNS fails. Depending on what OS you are using this
146 might be accomplished by editing <code>/etc/resolv.conf</code>,
147 or maybe <code>/etc/nsswitch.conf</code>.</p>
149 <p>If your server doesn't have to perform DNS for any other
150 reason then you might be able to get away with running httpd
151 with the <code>HOSTRESORDER</code> environment variable set to
152 "local". This all depends on what OS and resolver libraries you
153 are using. It also affects CGIs unless you use
154 <module>mod_env</module> to control the environment. It's best
155 to consult the man pages or FAQs for your OS.</p>
159 <title>Tips to Avoid These Problems</title>
164 <directive module="core">VirtualHost</directive>
169 <directive module="mpm_common">Listen</directive>
173 ensure all virtual hosts have an explicit
174 <directive module="core">ServerName</directive>
177 <li>create a <code><VirtualHost _default_:*></code>
178 server that has no pages to serve</li>