您的位置:首页 > 运维架构 > Linux

linux搭建dhcp服务

2010-03-12 17:56 567 查看
实验环境:[/b]AS4[/b]最小化安装[/b][/b]
实验目标:架设[/b]DHCP[/b]服务器[/b][/b]
编辑:[/b] crazylinux 2007.03.28[/b]
联系方式:[/b]http://crazylinux.cublog.cn [/b]
大家好!
这次我们来学习Linux系统中的DHCP服务器的配置。主要目标有两个:
1,配置DHCP服务器给客户端计算机分配IP地址,网络地址,DNS和网关地址
2,为某台客户机保留IP地址
下面我们开始了!首先我们检查是否已经安装了DHCP服务器端的软件
[root@localhost ~]# rpm -qa | grep dhcp -----à查询DHCP没有安装
dhcpv6_client-0.10-8
[root@localhost ~]# mount /media/cdrom/ -----à挂载AS4第4张盘
我们服务器上要安装的是dhcp-3.0.1-12_EL.i386.rpm,那么下面我们来安装。
[root@localhost ~]# rpm -ivh /media/cdrom/RedHat/RPMS/dhcp-3.0.1-12_EL.i386.rpm
DHCP服务器的配置文件为/etc/dhcpd.conf,默认情况下此文件不存在,不过当DHCP软件包安装之后会提供一个配置模板:/usr/share/doc/dhcp-3.0.1/dhcpd.conf.sample
[root@localhost RPMS]# rpm -ql dhcp
/usr/share/doc/dhcp-3.0.1/dhcpd.conf.sample (模版配置文件)
[root@localhost RPMS]# cp /usr/share/doc/dhcp-3.0.1/dhcpd.conf.sample /etc/dhcpd.conf
将模板拷贝到/etc/目录下命名为dhcpd.conf,然后在该文件上进行相关的配置即可。

到现在为止,我们的准备工作已经OK,下面我们就正式开始架设DHCP服务器
实例:
目前我的内部网段设定为 192.168.1.0/24 这一段,且默认网关为 192.168.1.1 ,此外,DNS主机的IP为192.168.1.10,所分配的网段内的子网掩码是255.255.255.0我想要让每个使用者默认租约时间为21600s,最大租约时间为43200s;局域网内所有主机的域名为“abc.com” 我只想要分配的 IP 只有 192.168.1.100 到 192.168.1.200 这几个,其它的 IP 则保留下来; 我的主机的 MAC 是 00:0C:29:F7:DB:70 ,我要给主机名称为crazylinux IP 为 192.168.1.10 这个。 [/b]
以下为修改之后的dhcpd.conf文件的内容:
[root@localhost RPMS]# cat /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;

subnet 192.168.1.0 netmask 255.255.255.0 {

# --- default gateway
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;

option nis-domain "domain.org";
option domain-name "abc.com";
option domain-name-servers 192.168.1.10;

option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
# option netbios-node-type 2;

range dynamic-bootp 192.168.1.100 192.168.1.200;
default-lease-time 21600;
max-lease-time 43200;

# we want the nameserver to appear at a fixed address
host crazylinux {
hardware ethernet 00:0C:29:F7:DB:70;
fixed-address 192.168.1.10;
}
}
完成之后重启服务:service dhcpd restart,若服务启动成功则可以使用一台客户机进行测试。这样一台最简单的DHCP服务器就架设完毕。
在DHCP服务器上,/var/lib/dhcp/dhcpd.leases文件中存放着DHCP客户租期数据库。只要DHCP服务器能够成功启动,该数据库就可以自动创建。并且,所有通过该DHCP服务器分配到地址的客户机的地址信息都会存储于该文件中。
该租期数据库文件经常被重建,但是不应该手工修改。
另外如果主机上安装了两个网卡,但是只想让DHCP服务在其中的一个网卡上监听,则需要配置DHCP服务器只在那个设备上启动。在/etc/sysconfig/dhcpd中,把网卡接口的名称添加到DHCPDARGS列表中。
#Command line options here
最后在客户端上使用netconfig命令设置客户端自动获取地址,完成后重启服务即可。
[root@localhost RPMS]# cat /var/lib/dhcp/dhcpd.leases 在服务器上查看已经分配出去的IP
# All times in this file are in UTC (GMT), not your local timezone. This is
# not a bug, so please don't ask about it. There is no portable way to
# store leases in the local timezone, so please don't request this as a
# feature. If this is inconvenient or confusing to you, we sincerely
# apologize. Seriously, though - don't ask.
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-V3.0.1

lease 192.168.1.200 {
starts 6 2007/03/17 04:36:31;
ends 6 2007/03/17 10:36:31;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:67:57:c1;
}
lease 192.168.1.199 {
starts 6 2007/03/17 04:37:13;
ends 6 2007/03/17 10:37:13;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:ef:cc:aa;
uid "\001\000\014)\357\314\252";
client-hostname "cheshi-eeb7e489";
}

嘿嘿 成功。。。本文出自 “相濡以沫” 博客,请务必保留此出处http://xiaoyao51.blog.51cto.com/1341841/283206
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: