📄 configtuning-virtual-hosts.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Virtual Hosts</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Configuration and Tuning" href="config-tuning.html" /><link rel="PREVIOUS" title="Setting Up Network Interface Cards"href="config-network-setup.html" /><link rel="NEXT" title="Configuration Files" href="configtuning-configfiles.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="config-network-setup.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 11 Configuration and Tuning</td><td width="10%" align="right" valign="bottom"><a href="configtuning-configfiles.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="CONFIGTUNING-VIRTUAL-HOSTS"name="CONFIGTUNING-VIRTUAL-HOSTS">11.9 Virtual Hosts</a></h1><p>A very common use of FreeBSD is virtual site hosting, where one server appears to thenetwork as many servers. This is achieved by assigning multiple network addresses to asingle interface.</p><p>A given network interface has one ``real'' address, and may have any number of``alias'' addresses. These aliases are normally added by placing alias entries in <ttclass="FILENAME">/etc/rc.conf</tt>.</p><p>An alias entry for the interface <tt class="DEVICENAME">fxp0</tt> looks like:</p><pre class="PROGRAMLISTING">ifconfig_fxp0_alias0="inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx"</pre><p>Note that alias entries must start with <var class="LITERAL">alias0</var> and proceedupwards in order, (for example, <var class="LITERAL">_alias1</var>, <varclass="LITERAL">_alias2</var>, and so on). The configuration process will stop at thefirst missing number.</p><p>The calculation of alias netmasks is important, but fortunately quite simple. For agiven interface, there must be one address which correctly represents the network'snetmask. Any other addresses which fall within this network must have a netmask of all<var class="LITERAL">1</var>s (expressed as either <ttclass="HOSTID">255.255.255.255</tt> or <tt class="HOSTID">0xffffffff</tt>).</p><p>For example, consider the case where the <tt class="DEVICENAME">fxp0</tt> interface isconnected to two networks, the <tt class="HOSTID">10.1.1.0</tt> network with a netmask of<tt class="HOSTID">255.255.255.0</tt> and the <tt class="HOSTID">202.0.75.16</tt> networkwith a netmask of <tt class="HOSTID">255.255.255.240</tt>. We want the system to appearat <tt class="HOSTID">10.1.1.1</tt> through <tt class="HOSTID">10.1.1.5</tt> and at <ttclass="HOSTID">202.0.75.17</tt> through <tt class="HOSTID">202.0.75.20</tt>. As notedabove, only the first address in a given network range (in this case, <ttclass="HOSTID">10.0.1.1</tt> and <tt class="HOSTID">202.0.75.17</tt>) should have a realnetmask; all the rest (<tt class="HOSTID">10.1.1.2</tt> through <ttclass="HOSTID">10.1.1.5</tt> and <tt class="HOSTID">202.0.75.18</tt> through <ttclass="HOSTID">202.0.75.20</tt>) must be configured with a netmask of <ttclass="HOSTID">255.255.255.255</tt>.</p><p>The following entries configure the adapter correctly for this arrangement:</p><pre class="PROGRAMLISTING"> ifconfig_fxp0="inet 10.1.1.1 netmask 255.255.255.0" ifconfig_fxp0_alias0="inet 10.1.1.2 netmask 255.255.255.255" ifconfig_fxp0_alias1="inet 10.1.1.3 netmask 255.255.255.255" ifconfig_fxp0_alias2="inet 10.1.1.4 netmask 255.255.255.255" ifconfig_fxp0_alias3="inet 10.1.1.5 netmask 255.255.255.255" ifconfig_fxp0_alias4="inet 202.0.75.17 netmask 255.255.255.240" ifconfig_fxp0_alias5="inet 202.0.75.18 netmask 255.255.255.255" ifconfig_fxp0_alias6="inet 202.0.75.19 netmask 255.255.255.255" ifconfig_fxp0_alias7="inet 202.0.75.20 netmask 255.255.255.255"</pre></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="config-network-setup.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="configtuning-configfiles.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Setting Up Network Interface Cards</td><td width="34%" align="center" valign="top"><a href="config-tuning.html"accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Configuration Files</td></tr></table></div><p align="center"><small>This, and other documents, can be downloaded from <ahref="ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/">ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/</a>.</small></p><p align="center"><small>For questions about FreeBSD, read the <ahref="http://www.FreeBSD.org/docs.html">documentation</a> before contacting <<ahref="mailto:questions@FreeBSD.org">questions@FreeBSD.org</a>>.<br />For questions about this documentation, e-mail <<ahref="mailto:doc@FreeBSD.org">doc@FreeBSD.org</a>>.</small></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -