linux搭建dhcp服务

实验环境: AS4 最小化安装
实验目标:架设 DHCP 服务器
编辑: crazylinux 2007.03.28
联系方式: http://crazylinux.cublog.cn
大家好!
这次我们来学习 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主机的IP192.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 这个。
以下为修改之后的 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-V 3.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";
}
 
 
嘿嘿 成功。。。

你可能感兴趣的:(linux,职场,服务,DHCP,休闲)