⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 network-dhcp.html

📁 这是很好的学习嵌入式LINUX的文章
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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>Automatic Network Configuration (DHCP)</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD 使用手册" href="index.html" /><link rel="UP" title="Network Servers" href="network-servers.html" /><link rel="PREVIOUS" title="Network Information System (NIS/YP)"href="network-nis.html" /><link rel="NEXT" title="Domain Name System (DNS)" href="network-dns.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /></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 使用手册</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="network-nis.html"accesskey="P">后退</a></td><td width="80%" align="center" valign="bottom">章 23. Network Servers</td><td width="10%" align="right" valign="bottom"><a href="network-dns.html"accesskey="N">前进</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="NETWORK-DHCP" name="NETWORK-DHCP">23.5. Automatic NetworkConfiguration (DHCP)</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Written by</span> Greg Sutter.</i> <div class="SECT2"><h2 class="SECT2"><a id="AEN33901" name="AEN33901">23.5.1. What Is DHCP?</a></h2><p>DHCP, the Dynamic Host Configuration Protocol, describes the means by which a systemcan connect to a network and obtain the necessary information for communication upon thatnetwork. FreeBSD uses the ISC (Internet Software Consortium) DHCP implementation, so allimplementation-specific information here is for use with the ISC distribution.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN33909" name="AEN33909">23.5.2. What This SectionCovers</a></h2><p>This section describes both the client-side and server-side components of the ISC DHCPsystem. The client-side program, <tt class="COMMAND">dhclient</tt>, comes integratedwithin FreeBSD, and the server-side portion is available from the <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/net/isc-dhcp3-server/pkg-descr"><ttclass="FILENAME">net/isc-dhcp3-server</tt></a> port. The <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">dhclient</span>(8)</span>, <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">dhcp-options</span>(5)</span>, and <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">dhclient.conf</span>(5)</span> manual pages, in addition to thereferences below, are useful resources.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN33923" name="AEN33923">23.5.3. How It Works</a></h2><p>When <tt class="COMMAND">dhclient</tt>, the DHCP client, is executed on the clientmachine, it begins broadcasting requests for configuration information. By default, theserequests are on UDP port 68. The server replies on UDP 67, giving the client an IPaddress and other relevant network information such as netmask, router, and DNS servers.All of this information comes in the form of a DHCP ``lease'' and is only valid for acertain time (configured by the DHCP server maintainer). In this manner, stale IPaddresses for clients no longer connected to the network can be automaticallyreclaimed.</p><p>DHCP clients can obtain a great deal of information from the server. An exhaustivelist may be found in <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">dhcp-options</span>(5)</span>.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN33934" name="AEN33934">23.5.4. FreeBSD Integration</a></h2><p>FreeBSD fully integrates the ISC DHCP client, <tt class="COMMAND">dhclient</tt>. DHCPclient support is provided within both the installer and the base system, obviating theneed for detailed knowledge of network configurations on any network that runs a DHCPserver. <tt class="COMMAND">dhclient</tt> has been included in all FreeBSD distributionssince 3.2.</p><p>DHCP is supported by <b class="APPLICATION">sysinstall</b>. When configuring a networkinterface within <b class="APPLICATION">sysinstall</b>, the first question asked is: ``Doyou want to try DHCP configuration of this interface?''. Answering affirmatively willexecute <tt class="COMMAND">dhclient</tt>, and if successful, will fill in the networkconfiguration information automatically.</p><p>There are two things you must do to have your system use DHCP upon startup:</p><ul><li><p>Make sure that the <tt class="DEVICENAME">bpf</tt> device is compiled into yourkernel. To do this, add <var class="LITERAL">device bpf</var> (<varclass="LITERAL">pseudo-device bpf</var> under FreeBSD&nbsp;4.X) to your kernelconfiguration file, and rebuild the kernel. For more information about building kernels,see <a href="kernelconfig.html">&#181;&#218; 8 章</a>.</p><p>The <tt class="DEVICENAME">bpf</tt> device is already part of the <ttclass="FILENAME">GENERIC</tt> kernel that is supplied with FreeBSD, so if you do not havea custom kernel, you should not need to create one in order to get DHCP working.</p><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> For those who are particularly security conscious, you should be warnedthat <tt class="DEVICENAME">bpf</tt> is also the device that allows packet sniffers towork correctly (although they still have to be run as <tt class="USERNAME">root</tt>).<tt class="DEVICENAME">bpf</tt> <span class="emphasis"><i class="EMPHASIS">is</i></span>required to use DHCP, but if you are very sensitive about security, you probably shouldnot add <tt class="DEVICENAME">bpf</tt> to your kernel in the expectation that at somepoint in the future you will be using DHCP.</p></blockquote></div></li><li><p>Edit your <tt class="FILENAME">/etc/rc.conf</tt> to include the following:</p><pre class="PROGRAMLISTING">ifconfig_fxp0="DHCP"</pre><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> Be sure to replace <var class="LITERAL">fxp0</var> with the designation forthe interface that you wish to dynamically configure, as described in <ahref="config-network-setup.html">&#181;&#218; 11.8 节</a>.</p></blockquote></div><p>If you are using a different location for <tt class="COMMAND">dhclient</tt>, or if youwish to pass additional flags to <tt class="COMMAND">dhclient</tt>, also include thefollowing (editing as necessary):</p><pre class="PROGRAMLISTING">dhcp_program="/sbin/dhclient"dhcp_flags=""</pre></li></ul><p>The DHCP server, <b class="APPLICATION">dhcpd</b>, is included as part of the <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/net/isc-dhcp3-server/pkg-descr"><ttclass="FILENAME">net/isc-dhcp3-server</tt></a> port in the ports collection. This portcontains the ISC DHCP server and documentation.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN33986" name="AEN33986">23.5.5. Files</a></h2><ul><li><p><tt class="FILENAME">/etc/dhclient.conf</tt></p><p><tt class="COMMAND">dhclient</tt> requires a configuration file, <ttclass="FILENAME">/etc/dhclient.conf</tt>. Typically the file contains only comments, thedefaults being reasonably sane. This configuration file is described by the <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">dhclient.conf</span>(5)</span> manualpage.</p></li><li><p><tt class="FILENAME">/sbin/dhclient</tt></p><p><tt class="COMMAND">dhclient</tt> is statically linked and resides in <ttclass="FILENAME">/sbin</tt>. The <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">dhclient</span>(8)</span> manual page gives more information about<tt class="COMMAND">dhclient</tt>.</p></li><li><p><tt class="FILENAME">/sbin/dhclient-script</tt></p><p><tt class="COMMAND">dhclient-script</tt> is the FreeBSD-specific DHCP clientconfiguration script. It is described in <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">dhclient-script</span>(8)</span>, but should not need any usermodification to function properly.</p></li><li><p><tt class="FILENAME">/var/db/dhclient.leases</tt></p><p>The DHCP client keeps a database of valid leases in this file, which is written as alog. <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">dhclient.leases</span>(5)</span> gives a slightly longerdescription.</p></li></ul></div><div class="SECT2"><h2 class="SECT2"><a id="AEN34026" name="AEN34026">23.5.6. Further Reading</a></h2><p>The DHCP protocol is fully described in <ahref="http://www.freesoft.org/CIE/RFC/2131/" target="_top">RFC 2131</a>. An informationalresource has also been set up at <a href="http://www.dhcp.org/"target="_top">dhcp.org</a>.</p></div><div class="SECT2"><h2 class="SECT2"><a id="NETWORK-DHCP-SERVER" name="NETWORK-DHCP-SERVER">23.5.7.Installing and Configuring a DHCP Server</a></h2><div class="SECT3"><h3 class="SECT3"><a id="AEN34033" name="AEN34033">23.5.7.1. What This SectionCovers</a></h3><p>This section provides information on how to configure a FreeBSD system to act as aDHCP server using the ISC (Internet Software Consortium) implementation of the DHCPsuite.</p><p>The server portion of the suite is not provided as part of FreeBSD, and so you willneed to install the <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/net/isc-dhcp3-server/pkg-descr"><ttclass="FILENAME">net/isc-dhcp3-server</tt></a> port to provide this service. See <ahref="ports.html">&#181;&#218; 4 章</a> for more information on using the portscollection.</p></div><div class="SECT3">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -