安装

yum install -y dhcp

配置文件

默认配置为/etc/dhcpd.conf

[root@samba ~]#
[root@samba ~]# rpm -ql dhcp | grep conf.sample
/usr/share/doc/dhcp-/dhcpd.conf.sample
[root@samba ~]#

使用此示例配置文件覆盖/etc/dhcpd.conf

根据具体情况配置此文件

[root@samba ~]# cat /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;

subnet 100.1.1.0 netmask 255.255.255.0 {

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

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

    option ; # 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 ;

    range dynamic-bootp 100.1.1.128 100.1.1.254;
    default-lease-;
    max-lease-;

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

关于配置文件内容跟参数选项意义参考一下:

/etc/dhcpd.conf通常包括三部分:parameters、declarations 、option。

  1.DHCP配置文件中的parameters(参数):表明如何执行任务,是否要执行任务,或将哪些网络配置选项发送给客户。主要内容见表1

2. DHCP配置文件中的declarations (声明):用来描述网络布局、提供客户的IP地址等。主要内容见表2:

3. DHCP配置文件中的option(选项):用来配置DHCP可选参数,全部用option关键字作为开始,主要内容包括见表3:


注意:如果客户端使用的是视窗操作系统,不要选择"host-name"选项,即不要为其指定主机名称。

启动服务

service dhcpd start

或者

dhcpd -p  -cf /etc/dhcpd.conf

查看端口是否监听

netstat -an | 

启动脚本,可以查看很多相关记录文件信息

#!/bin/sh
#
### BEGIN INIT INFO
# Provides: dhcpd
# Default-Start:
# Default-Stop:
# Should-Start:
# Required-Start: $network
# Required-Stop:
# Short-Description: Start and stop the DHCP server
# Description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP)
#              server.
### END INIT INFO
#
# The fields below are left around for legacy tools (will remove later).
#
# chkconfig: -
# description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP) \
#              server
# processname: dhcpd
# config: /etc/dhcpd.conf
# config: /var/lib/dhcpd/dhcpd.leases
# pidfile: /var/run/dhcpd.pid

. /etc/rc.d/init.d/functions

RETVAL=

prog=dhcpd
exec=/usr/sbin/dhcpd
lockfile=/var/lock/subsys/dhcpd
pidfile=/var/run/dhcpd.pid
statedir=/var/lib/dhcpd

[ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd

# if the user specified a different config file, make sure we reference it
findConfig() {
    for arg in $DHCPDARGS ; do
         ]; then
            [ -f "$arg" ] && echo "$arg"
            return
        fi
        if [ "$arg" = "-cf" ]; then
            found=
            continue
        fi
    done
    echo "/etc/dhcpd.conf"
}

config="$(findConfig "$DHCPDARGS")"

if [ ! -f $statedir/dhcpd.leases ] ; then
    mkdir -p $statedir
    touch $statedir/dhcpd.leases
    [ -x /sbin/restorecon ] && [ -d /selinux ] && /sbin/restorecon $statedir/dhcpd.leases >/dev/>&
fi

configtest() {
    [ -x $exec ] || return
    [ -f $config ] || return
    $exec -q -t -cf $config
    RETVAL=$?
     ]; then
        $exec -t -cf $config
    else

    fi
    return $RETVAL
}

rh_status() {
    status -p $pidfile $exec
}

rh_status_q() {
    rh_status >/dev/>&
}

start() {
    [ ` ] || return
    [ -x $exec ] || return
    [ -f $config ] || return 

    rh_status_q && return 

    echo -n $"Starting $prog: "
    daemon --pidfile=$pidfile $exec $DHCPDARGS >/dev/null
    RETVAL=$?

    echo
    [ $RETVAL -eq  ] && touch $lockfile
    return $RETVAL
}

stop() {
    [ ` ] || return 

    rh_status_q || return 

    echo -n $"Shutting down $prog: "
    killproc -p $pidfile $prog
    RETVAL=$?

    echo
    [ $RETVAL -eq  ] && rm -f $lockfile
    return $RETVAL
}

usage() {
    echo $"Usage: $0 {start|stop|restart|force-reload|condrestart|try-restart|configtest|status}"
}

 ]; then
    exit
fi

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|force-reload)
        stop ; start
        ;;
    condrestart|try-restart)
        rh_status_q || exit
        stop ; start
        ;;
    reload)
        usage
        # unimplemented feature
        exit
        ;;
    configtest)
        configtest
        ;;
    status)
        rh_status
        ;;
    *)
        usage
        exit
        ;;
esac

exit $?

服务端查看已分配的IP地址

客户端的重新获取都会得到记录

[root@samba ~]#
[root@samba ~]#
[root@samba ~]# 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 ) manual page.
# This lease file was written by isc-dhcp-V3.0.5-RedHat

lease 100.1.1.254 {
  starts  // ::;
  ends  // ::;
  binding state active;
  next binding state free;
  hardware ethernet :0c:::b2:b3;
}
lease 100.1.1.254 {
  starts  // ::;
  ends  // ::;
  binding state active;
  next binding state free;
  hardware ethernet :0c:::b2:b3;
}

客户端查看相关信息

客户端上获取到IP地址后,dhclient 可以查看下相关信息,比如dhcp server等

[root@localhost ~]#
[root@localhost ~]# pkill dhclient
[root@localhost ~]# dhclient
Internet Systems Consortium DHCP Client V3.0.5-RedHat
Copyright - Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/

Listening on LPF/eth0/:0c:::b2:b3
Sending on   LPF/eth0/:0c:::b2:b3
Sending on   Socket/fallback
DHCPREQUEST on eth0 to  (xid=0x6656d649)
DHCPACK from 100.1.1.100 (xid=0x6656d649)
bound to  seconds.
[root@localhost ~]#
[root@localhost ~]#

如果想查看更详细的信息,例如租期等等,可查看相关文件

[root@localhost ~]# ls /var/lib/dhclient/
dhclient-eth0.leases  dhclient.leases
[root@localhost ~]#
[root@localhost ~]# cat /var/lib/dhclient/dhclient.leases
lease {
  interface "eth0";
  fixed-address 100.1.1.254;
  option subnet-mask 255.255.255.0;
  option ;
  option dhcp-lease-;
  option routers 100.1.1.1;
  option dhcp-message-type ;
  option dhcp-server-identifier 100.1.1.100;
  option domain-name-servers 114.114.114.114;
  option nis-domain "domain.org";
  option domain-name "domain.org";
  renew  // ::;
  rebind  // ::;
  expire  // ::;
}
lease {
  interface "eth0";
  fixed-address 100.1.1.254;
  option subnet-mask 255.255.255.0;
  option ;
  option routers 100.1.1.1;
  option dhcp-lease-;
  option dhcp-message-type ;
  option domain-name-servers 114.114.114.114;
  option dhcp-server-identifier 100.1.1.100;
  option nis-domain "domain.org";
  option domain-name "domain.org";
  renew  // ::;
  rebind  // ::;
  expire  // ::;
}

DHCP的更多相关文章

  1. 协议森林16 小美的桌号(DHCP协议)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 转载请先与我联系. DHCP协议用于动态的配置电脑的网络相关参数,如主机的IP地址,路由器出口地址.DNS域名服务器地 ...

  2. 获取 dhcp IP 过程分析 - 每天5分钟玩转 OpenStack(91)

    前面我们已经讨论了 DHCP agent 的配置以及 namespace 如何隔离 dnsmasq 服务,本节将以 cirros-vm1 为例分析获取 DHCP IP 的详细过程. 在创建 insta ...

  3. dhcp协议交互报文

    DHCP共有八种报文,分别为DHCP Discover.DHCP Offer.DHCP Request.DHCP ACK.DHCP NAK.DHCP Release.DHCP Decline.DHCP ...

  4. 7、二种 为二个不同的子网配置DHCP服务器(中继代理服务器)

    环境如下:        (参考之前,保证二个子网可以互相ping通) 虚拟机vm1        192.168.170.3                    VMnet8 (NAT模式) 虚拟 ...

  5. PXE+Kickstart+DHCP+TFTP实现无人值守安装操作系统

    PXE+Kickstart+DHCP+TFTP实现无人值守安装操作系统 PXE + Kickstart PXE的工作流程及配置文件 Kickstart的配置文件 Linux安装大致可以分为2个阶段 第 ...

  6. 思科交换机配置DHCP的四个方面

    这里我们主要讲解了思科交换机配置DHCP的相关内容.我们对网络拓扑先进行一下了解,然后对于其在进行一下说明,之后对于配置的代码和命令再进行一下解析. 思科交换机配置DHCP一.网络拓扑 思科交换机配置 ...

  7. 协议分析 - DHCP协议解码详解

    协议分析 - DHCP协议解码详解 [DHCP协议简介]         DHCP,全称是 Dynamic Host Configuration Protocol﹐中文名为动态主机配置协议,它的前身是 ...

  8. 用 namspace 隔离 DHCP 服务 - 每天5分钟玩转 OpenStack(90)

    Neutron 通过 dnsmasq 提供 DHCP 服务,而 dnsmasq 如何独立的为每个 network 服务呢? 答案是通过 Linux Network Namespace 隔离,本节将详细 ...

  9. 配置 DHCP 服务 - 每天5分钟玩转 OpenStack(89)

    前面章节我们看到 instance 在启动过程中能够从 Neutron 的 DHCP 服务获得 IP,本节将详细讨论其内部实现机制. Neutron 提供 DHCP 服务的组件是 DHCP agent ...

随机推荐

  1. mssqlserver数据导出到另外一个数据库

    mssqlserver数据导出到另外一个数据库 准备源数据库,找到想要导出的数据库,右键选择"任务"再选择"导出数据" 设置源数据库信息 3.设置目标数据库,导 ...

  2. 常用MySQL图形化管理工具

    MySQL的管理维护工具非常多,除了系统自带的命令行管理工具之外,还有许多其他的图形化管理工具,这里我介绍几个经常使用的MySQL图形化管理工具,供大家参考. MySQL是一个非常流行的小型关系型数据 ...

  3. Oracle学习笔记十一 游标

    游标的简介 游标的概念 游标是从数据表中提取出来的数据,以临时表的形式存放在内存中,在游标中有一个数据指针,在初始状态下指向的是首记录,利用fetch语句可以移动该指针,从而对游标中的数据进行各种操作 ...

  4. 萌新笔记——linux下(ubuntu)反删除(误删恢复)与回收站制作

    刚刚有个小伙伴不小心删了他写了好几的天代码,为他心疼之余帮他找回了文件. 想到我之前也常常误删一些文件,就干脆分享一下我的反删除方法,并说说我做的回收站(好low的,求大神指点) 首先是反删除软件ex ...

  5. Struts2中的Ognl

    OGNL(Object-Graph Navigation Language)全称为对象图导航语言,是一种功能强大的表达式语言,它通过简单一致的语法,可以任意存取对象的属性或者调用对象的方法,能够遍历整 ...

  6. 【IDEA】intellij idea 插件推荐

    CSDN 2016博客之星评选结果公布    [系列直播]零基础学习微信小程序!      "我的2016"主题征文活动   博客的神秘功能 [IDEA]intellij idea ...

  7. [bzoj3224][tyvj1728][普通平衡树] (pb_ds库自带红黑树)

    Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 1. 插入x数 2. 删除x数(若有多个相同的数,因只删除一个) 3. 查询x数的排名(若有多个相 ...

  8. [LeetCode] Bulb Switcher 灯泡开关

    There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...

  9. Gulp 常用插件

    插件使用注意事项: 插件需要先 npm/cnpm install xx --save-dev gulp taskname,如果 task 已经设置成 default 的依赖,直接 gulp 即可 ta ...

  10. Codeforces Round #382(div 2)

    A.= = B. 题意:给出n个数和n1和n2,从n个数中分别选出n1,n2个数来,得到n1个数和n2个数的平均值,求这两个平均值的最大和 分析:排个序从后面抽,注意先从末尾抽个数小的,再抽个数大的 ...