RHEL5_DHCP简单配置

ceaAfPcKetosc

首先服务器自身需要一个静态IP地址,这里设为192.168.1.99/24.如果没有DHCP环境还得安装一下.
先看一下配置文件,居然是空的…不急,里面写了有一个示例文件,拷贝过来覆盖即可~XD

[root@localhost /]# cat /etc/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
[root@localhost /]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf 
cp:是否覆盖“/etc/dhcpd.conf”? y
[root@localhost /]# ll /etc/dhcpd.conf 
-rw-r--r-- 1 root root 852 08-16 17:38 /etc/dhcpd.conf

编辑该配置文件,以下为文件的默认状态:

[root@localhost /]# vim /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 {

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

        option nis-domain               "domain.org";
        option domain-name              "domain.org";
        option domain-name-servers      192.168.1.1;

        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.0.128 192.168.0.254;
        default-lease-time 21600;
        max-lease-time 43200;

        # we want the nameserver to appear at a fixed address
        host ns {
                next-server marvin.redhat.com;
                hardware ethernet 12:34:56:78:AB:CD;
                fixed-address 207.175.42.254;
        }
}

这里地址段使用192.168.1.0/24,地址池设为192.168.1.100 – 192.168.1.253,网关192.168.1.254,DNS 8.8.8.8,租期不管,使用默认.最后针对测试机的MAC地址做一个保留[00:0C:29:9D:AA:AE 192.168.1.214],或者说绑定.切记这里做多个条目时host后的字符不要相同.

ddns-update-style interim;
ignore client-updates;

subnet 192.168.1.0 netmask 255.255.255.0 {

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

        option nis-domain               "domain.org";
        option domain-name              "domain.org";
        option domain-name-servers      8.8.8.8;

        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.253;
        default-lease-time 21600;
        max-lease-time 43200;

        # we want the nameserver to appear at a fixed address
        host xp {
                hardware ethernet 00:0C:29:9D:AA:AE;
                fixed-address 192.168.1.214;
        }
}

完成后:wq保存退出文件,之后可以通过dhcpd命令来检查配置是否有误,无误即如下输出:

[root@localhost /]# dhcpd 
Internet Systems Consortium DHCP Server V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
WARNING: Host declarations are global.  They are not limited to the scope you declared them in.
Wrote 0 deleted host decls to leases file.
Wrote 0 new dynamic host decls to leases file.
Wrote 0 leases to leases file.
Listening on LPF/eth0/00:0c:29:70:65:b3/192.168.1/24
Sending on   LPF/eth0/00:0c:29:70:65:b3/192.168.1/24
Sending on   Socket/fallback/fallback-net

最后启动dhcp服务.

[root@localhost /]# service dhcpd start

OK,测试机成功拿到保留IP地址.

20140816175446
另外还可以通过dhcpd.leases这个文件来查看地址的分发情况:
[root@localhost /]# cat /var/lib/dhcpd/dhcpd.leases
# 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.5-RedHat

lease 192.168.1.214 {
  starts 6 2014/08/16 09:58:55;
  ends 6 2014/08/16 15:58:55;
  binding state active;
  next binding state free;
  hardware ethernet 00:0c:29:9d:aa:ae;
  uid "\001\000\014)\235\252\256";
  client-hostname "fox-6f0fa2fdd92";
}

完.

发表评论

您的电子邮箱地址不会被公开。

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :-| :-x :-o :-P :-D :) :( 8-O 8)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据