Linux培训教程之一DHCP的安装和配置.docx

上传人:b****5 文档编号:7880011 上传时间:2023-01-26 格式:DOCX 页数:4 大小:17.48KB
下载 相关 举报
Linux培训教程之一DHCP的安装和配置.docx_第1页
第1页 / 共4页
Linux培训教程之一DHCP的安装和配置.docx_第2页
第2页 / 共4页
Linux培训教程之一DHCP的安装和配置.docx_第3页
第3页 / 共4页
Linux培训教程之一DHCP的安装和配置.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

Linux培训教程之一DHCP的安装和配置.docx

《Linux培训教程之一DHCP的安装和配置.docx》由会员分享,可在线阅读,更多相关《Linux培训教程之一DHCP的安装和配置.docx(4页珍藏版)》请在冰豆网上搜索。

Linux培训教程之一DHCP的安装和配置.docx

Linux培训教程之一DHCP的安装和配置

Linux培训教程之一---DHCP的安装和配置

第一章DHCP的安装和配置

考虑大多数的情况,Linux作为DHCP服务器而windows95/98作为DHCP客户。

Linux也可以作为DHCP客户,即你要安装dhcpcdrpm软件包,Linux作为DHCP服务器,

只需要安装dhcpdrpm包(以Redhat6.1为例)

一.DHCP服务器工作的前提条件:

为了使DHCP服务器为windows机器服务,你可能需要创建一个到地址255.255.255.255

的路由,加这条路由命令到/etc/rc.d/rc.local使得每次启动后自动运行。

#routeadd-host255.255.255.255deveth0

如果报告错误消息:

255.255.255.255:

Unkownhost

试着加下面的入口到/etc/hosts文件

255.255.255.255dhcp,thentry:

#routeadd-hostdhcpdeveth0

二.DHCPd后台程序总是读取配置文件/etc/dhcpd.conf,下面给出一个DHCP配置文件的例子:

#Sample/etc/dhcpd.conf

default-lease-time1200;

max-lease-time9200;

optionsubnet-mask255.255.255.0;

optionbroadcast-address192.168.1.255;

optionrouters192.168.1.254;

optiondomain-name-servers192.168.1.1,192.168.1.2;

optiondomain-name"mydomain.org";

subnet192.168.1.0netmask255.255.255.0{

range192.168.1.10192.168.1.100;

range192.168.1.150192.168.1.200;

}

这将允许DHCP服务器分配两段地址范围给客户192.168.1.10-100或者192.168.1.150-200

如果客户不继续请求DHCP地址则1200秒后释放IP地址,否则最大允许租用的时间为9200秒。

服务器发送下面的参数给DHCP客户机:

用255.255.255.0作为子网掩码,用192.168.1.255作为广播地址,用192.168.1.254作为

默认网关,用192.168.1.1and192.168.1.2作为DNS服务器

如果你要为windows客户指定一个WINS服务器,你需要包括下面的选项到dhcpd.conf文件中:

optionnetbios-name-servers192.168.1.1;

三.你也能为某块网卡指定固定的IP地址,无论何时,这块网卡将总是从DHCP服务器获得

固定的IP地址:

加下面的语句到/etc/dhcpd.conf:

hosthaagen{

hardwareethernet08:

00:

2b:

4c:

59:

23;

fixed-address192.168.1.222;

}

也可连写为一行:

hostJephe{hardwareethernet00:

a0:

c9:

a6:

96:

33;fixed-address192.168.1.12;}

你也可为某台机器指定不同的网关地址,名服务器等:

hostJephe{hardwareethernet00:

a0:

c9:

a6:

96:

33;fixed-address192.168.1.12;option

routers192.168.11.5;}

四.大多数情况下,DHCP的安装不创建一个dhcpd.leases文件,在你启动DHCP服务器之前,

你必须创建空文件dhcpd.leases

#touch/var/state/dhcp/dhcpd.leases

为启动DHCP服务器,简单地打入/usr/sbin/dhcpd或者用#ntsysv把DHCP服务自动启动

这将启动dhcpd在eth0设备上,如果你想在eth1设备上启动dhcpd,则

#/usr/sbin/dhcpdeth1

如果为了调试DHCP,则用#/usr/sbin/dhcpd-d-f

五.两块网卡的情况:

有时你需要在一台安装了两块网卡(作防火墙或网关)的机器上安装DHCP服务,下面的例子

指出一台防火墙机器上的一种DHCP设置,因为对外的网卡(internet)不需要提供DHCP服务:

因此这样设置如下:

subnet192.168.1.0netmask255.255.255.0{

range192.168.1.2192.168.1.4;

default-lease-time86400;

max-lease-time259200;

optionsubnet-mask255.255.255.0;

optionbroadcast-address192.168.1.255;

optionrouters192.168.1.254;

optiondomain-name-servers192.168.1.254;

}

subnet202.102.34.102netmask255.255.255.255{

}

六.FAQ

a.为MAC机器固定IP地址?

当设置MAC机用DHCP功能获得IP地址后,如不知得到何地址,可在MAC机上发送一邮件出去,

收信者可通过mailheader检查发送者IP地址,而后ping该IP地址再利用arp命令检查arp

缓存中的该IP地址的对应物理地址。

b.若LAN上有windows机器装上了某DHCP功能的软件,如sygate,wingate之类,则可能

其他windows客户会优先去寻找windowsDHCP服务器,而不是LinuxDHCP服务器

参考材料:

附录:

在Redhat5.2中的DHCP配置()

ConfiguringDHCPAndDNSServices

SetupLinuxtoallocateIPaddressandactasanameserver

SettingupDHCPonRedHat

Ifyournetworkhasalargenumberofclients,manuallyconfiguringeverymachine

withastaticIPaddressisatoughjob.TheDynamicHostConfigurationProtocol

(DHCP)letsyouautomaticallyassignanIPaddresstoamachineonthenetwork

fromapoolorrangeofIPaddressesithas.

ToconfigureaDHCPserveronyourLinuxmachine,youneedtocreateafilecalled

dhcpd.confinthe/etcdirectory.Thisfilecontainsalltheinformationthatthe

daemonneedswhilestartingup.Thisfileisinthefollowingformat(theline

numbersarenotpartofthefile,they'refortheexplanationthatfollows):

subnet192.168.1.0netmask255.255.255.0{

range192.168.1.10192.168.1.250;

default-lease-time86400;

max-lease-time259200;

optionsubnet-mask255.255.255.0;

optionbroadcast-address192.168.1.255;

optionrouters192.168.1.1;

optiondomain-name-servers192.168.1.1;

optiondomain-name"";

}

Letslookattheselinesabitmoreclosely.Thefirstlinespecifiesthe(sub)

networkthattheDHCPserveristomanageormaintain.Withinthisnetwork,we

havetoconfiguredifferentparameters(writtenwithinthecurlybraces).

ThenextlinecontainstherangefromwhichtheserverpicksupIPaddressesto

allocate.ThestartingandendingIPaddressesareenteredhere.Line3contains

thedefaultleasetime.Aleaseistheamountoftimethataparticularmachine

canholdanIPaddressbeforehavingtorenewtheleasewiththeserver.Thevalue

isgiveninnumberofseconds,so86400standsforoneday.Thenextline,

max-lease-time,specifiesthemaximumamountoftimethatamachinecanholdonto

aspecificIPaddress.

Thencomeotheroptionsthatwillalsobetransmittedtothemachine.Theseinclude

thesubnetmask,therouter,thedomainnameserver,andthedomainname.

Oncethisisdone,youneedtocreateafilecalleddhcpd.leases,alsointhe

/etc/directory,whichwillcontaininformationaboutwhichIPaddresshasbeen

allocatedtowhichmachine.Sinceallthiswillbedonebytheserver,allyouneed

todoiscreatea0bytefilewiththecommand,touch/etc/dhcpd.leases.

Thenextsteprequiresyoutoaddabroadcastroute.Dothisbyappendingtheline

/sbin/routeadd-host255.255.255.255deveth0to/etc/rc.d/rc.local.

Finally,makesureDHCPisstartedatbootup.YoucandothisbyrunningSetup,

choosingntsysv,andenablingdhcpd.Restartthemachine,bygivingthecommandsync,

followedbyreboot.

YourDHCPserverwillbeupandrunningafterthemachinestartsup.Anymachine

thatlogsonthenetworkwillreceiveanIPaddressandallotherparameters

automatically.Ifit'saWin95client,youcancheckallthesettingsbyrunning

winipcfgintheRundialogbox.

TheremaybecaseswhenyouneedtoassignaparticularmachinethesameIPaddress

always.Youcaneitherhardwiretheinformationinthecomputeroraddthefollowing

linestothedhcpd.conffile.

hostmynotebook{

hardwareethernet00:

80:

C8:

85:

B5:

D2;

fixed-address192.168.1.20;

optionhost-name"mynotebook";

}

Thisspecifiestheethernetaddress,whichwillbeunique,theIPaddressthatwillalways

beallocatedtothatmachine,andahostname.

WithDHCP,thenetworkadministrator'snightmareofcorrectlysettingupIPaddresses

onmachinessimplyvanishes.You'llneverneedtomanuallyconfigureanothermachine

everagain.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 工学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1