1、预分配网络参数如下:
linux服务器:eth0 IP为192.168.8.250  做为局域网DHCP服务器
局域网网段设置为192.168.8.0/24;
内部计算机的router为192.168.8.254;
DNS主机为联通的202.102.224.68和202.102.227.68
每个用户默认租约为3天(3*24*60*60=259200秒),最长为6天
要分配的IP范围只有192.168.8.101至192.168.8.199,其他IP则保留

2、根据网络参数,编辑DHCP服务配置文件/etc/dhcp/dhcpd.conf如下:

#整体环境设置

ddns-update-style  none;
ignore client-update ;
default-lease-time  259200;
max-lease-time     518400;
option routers  192.168.8.254;
option domain-name    "centos.me"
option  domain-name-servers  202.102.224.68,202.102.227.68;

#IP分配

subnet  192.168.8.0 netmask 255.255.255.0 {
    range  192.168.8.101   192.168.8.199;
    }

3、dhcp服务器的启动与观察

3.1 启动前要注意
    1、linux服务器的网络环境已经设置好
    2、防火墙规则已经处理好

如果以上都设置好了那么现在开始启动dhcp
[root@NMS dhcp]# /etc/init.d/dhcpd start
正在启动 dhcpd:                                           [失败]

很不幸!失败了~那么为什么会失败呢?我们来查看下启动日志/var/log/messages
这里面记录了dhcp的启动过程,都发生了什么!

[root@NMS dhcp]# tail  -n 30 /var/log/messages
Aug 31 12:25:00 NMS rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="1214" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
Aug 31 15:40:48 NMS dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1
Aug 31 15:40:48 NMS dhcpd: Copyright 2004-2010 Internet Systems Consortium.
Aug 31 15:40:48 NMS dhcpd: All rights reserved.
Aug 31 15:40:48 NMS dhcpd: For info, please visit https://www.isc.org/software/dhcp/
Aug 31 15:40:48 NMS dhcpd: /etc/dhcp/dhcpd.conf line 4: expecting allow/deny key
Aug 31 15:40:48 NMS dhcpd: ignore client-update
Aug 31 15:40:48 NMS dhcpd:         ^
Aug 31 15:40:48 NMS dhcpd: /etc/dhcp/dhcpd.conf line 4: expecting a parameter or declaration
Aug 31 15:40:48 NMS dhcpd: ignore client-update ;
Aug 31 15:40:48 NMS dhcpd:                       ^
Aug 31 15:40:48 NMS dhcpd: /etc/dhcp/dhcpd.conf line 9: semicolon expected.
Aug 31 15:40:48 NMS dhcpd: option
Aug 31 15:40:48 NMS dhcpd:  ^
Aug 31 15:40:48 NMS dhcpd: Configuration file errors encountered -- exiting
Aug 31 15:40:48 NMS dhcpd:
Aug 31 15:40:48 NMS dhcpd: This version of ISC DHCP is based on the release available
Aug 31 15:40:48 NMS dhcpd: on ftp.isc.org.  Features have been added and other changes
Aug 31 15:40:48 NMS dhcpd: have been made to the base software release in order to make
Aug 31 15:40:48 NMS dhcpd: it work better with this distribution.
Aug 31 15:40:48 NMS dhcpd:
Aug 31 15:40:48 NMS dhcpd: Please report for this software via the CentOS Bugs Database:
Aug 31 15:40:48 NMS dhcpd:     http://bugs.centos.org/
Aug 31 15:40:48 NMS dhcpd:
Aug 31 15:40:48 NMS dhcpd: exiting.

由日志我们看出来配置文件错误造成dhcp启动失败,“Configuration file errors encountered -- exiting”
那么我来看配置文件,根据提示找出其中的错误;

[root@NMS dhcp]# cat  -n  /etc/dhcp/dhcpd.conf
     1    #整体环境设置
     2    
     3    ddns-update-style  none;
     4    ignore client-update ;
     5    default-lease-time  259200;
     6    max-lease-time     518400;
     7    option routers  192.168.8.254;
     8    option domain-name    "centos.me"
     9    option  domain-name-servers  202.102.224.68,202.102.227.68;
    10    
    11    #IP分配
    12    
    13    subnet  192.168.8.0 netmask 255.255.255.0 {
    14        range  192.168.8.101   192.168.8.199;
    15        }
    16        
第一个错误信息表示配置文件第4行有错误,是关键字错误!仔细看是update少了个s应该是updates
Aug 31 15:40:48 NMS dhcpd: /etc/dhcp/dhcpd.conf line 4: expecting allow/deny key
Aug 31 15:40:48 NMS dhcpd: ignore client-update
第二个错误也是在第4行,根据指数符号(^)标注的位置,原来配置项结束后要紧接";",我不小多了个空格,所以报错
Aug 31 15:40:48 NMS dhcpd: /etc/dhcp/dhcpd.conf line 4: expecting a parameter or declaration
Aug 31 15:40:48 NMS dhcpd: ignore client-update ;
第三个错误指出错误在第9行,可以看出我们在最后没有加";"所以报错,semicolon是分号的意思;
Aug 31 15:40:48 NMS dhcpd: /etc/dhcp/dhcpd.conf line 9: semicolon expected.
Aug 31 15:40:48 NMS dhcpd: option

按照日志信息更改后的配置文件如下:
[root@NMS etc]# cat /etc/dhcp/dhcpd.conf  -n
     1    #整体环境设置
     2    
     3    ddns-update-style  none;
     4    ignore client-updates;
     5    default-lease-time  259200;
     6    max-lease-time     518400;
     7    option routers  192.168.8.254;
     8    option domain-name    "centos.me";
     9    option  domain-name-servers  202.102.224.68,202.102.227.68;
    10    
    11    #IP分配
    12    
    13    subnet  192.168.8.0 netmask 255.255.255.0 {
    14        range  192.168.8.101   192.168.8.199;
    15        }
    16        
 
接下来再次启动DHCP,

[root@NMS etc]# /etc/init.d/dhcpd start
正在启动 dhcpd:                                           [确定]

可以看到这次能启动了。

DHCP使用的端口是port 67,查看端口是否监听;
[root@NMS etc]# netstat -tlunp |grep dhcp
udp        0      0 0.0.0.0:67                  0.0.0.0:*                               17017/dhcpd

再次查看日志文件输出信息

[root@NMS etc]# tail -n  10 /var/log/messages
Aug 31 16:09:16 NMS dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1
Aug 31 16:09:16 NMS dhcpd: Copyright 2004-2010 Internet Systems Consortium.
Aug 31 16:09:16 NMS dhcpd: All rights reserved.
Aug 31 16:09:16 NMS dhcpd: For info, please visit https://www.isc.org/software/dhcp/
Aug 31 16:09:16 NMS dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Aug 31 16:09:16 NMS dhcpd: Wrote 0 leases to leases file.
Aug 31 16:09:16 NMS dhcpd: Listening on LPF/eth0/00:0c:29:23:fe:20/192.168.8.0/24
Aug 31 16:09:16 NMS dhcpd: Sending on   LPF/eth0/00:0c:29:23:fe:20/192.168.8.0/24
Aug 31 16:09:16 NMS dhcpd: Sending on   Socket/fallback/fallback-net

看到这些信息说明成功了!没有报错!

4、服务器端已经准备好,万事俱备只欠东风了就等给客户端服务了!接下来看下客户端的设置
4.1客户端是linux

客户端环境
[root@nmserver-7 ~]# uname -a
Linux nmserver-7.test.com 3.10.0-514.el7.centos.plus.i686 #1 SMP Wed Jan 25 12:55:04 UTC 2017 i686 i686 i386 GNU/Linux
[root@nmserver-7 ~]# cat /etc/redhat-release
CentOS release 7.3.1611 (AltArch)

在客户端修改网卡配置文件,让主机自动取得网络参数;
[root@nmserver-7 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33

TYPE=Ethernet
DEVICE=ens33
ONBOOT=yes
BOOTPROTO=dhcp

~                                                                                                                                                
                                                                                                                                            
~                                                                                                                                                
"/etc/sysconfig/network-scripts/ifcfg-ens33" 5L, 54C

注意:重点是将BOOTPROTO由原来的静态“static“,改为”dhcp“就可通过dhcp服务器来获取网络参数了!

修改配置文件后重启客户端网络
[root@nmserver-7 ~]# systemctl restart network

查看IP,可以看到客户端已经获取到的IP是192.168.8.101/24
[root@nmserver-7 ~]# ifconfig
bridge0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b6:83:d4:66:3a:4c  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.101  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::20c:29ff:fe56:bccf  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:56:bc:cf  txqueuelen 1000  (Ethernet)
        RX packets 29323  bytes 2119863 (2.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 29052  bytes 2256533 (2.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 2212  bytes 150063 (146.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2212  bytes 150063 (146.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

查看一下客户端路由
[root@nmserver-7 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.8.254   0.0.0.0         UG    100    0        0 ens33
192.168.8.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33

查看客户端DHCP连接状态,
[root@nmserver-7 ~]# netstat -tunlp |grep dhc
udp        0      0 0.0.0.0:68              0.0.0.0:*                           4195/dhclient       
udp        0      0 0.0.0.0:22424           0.0.0.0:*                           4195/dhclient       
udp6       0      0 :::56121                :::*                                4195/dhclient       
查看客户端DNS设置
[root@nmserver-7 dhclient]# cat /etc/resolv.conf
# Generated by NetworkManager
search centos.me test.com
nameserver 202.102.224.68
nameserver 202.102.227.68

通过以上信息可以看到客户端获取的网络参数与之前DHCP服务器上设置的一致!!

那么在客户端网络重启的过程中,DHCP服务器都做了什么呢?我们来看下DHCP服务器的日志信息,可以清楚看到
DHCP协议工作的4个过程:

[root@NMS etc]# tail -n  10 /var/log/messages
Aug 31 16:09:16 NMS dhcpd: Listening on LPF/eth0/00:0c:29:23:fe:20/192.168.8.0/24
Aug 31 16:09:16 NMS dhcpd: Sending on   LPF/eth0/00:0c:29:23:fe:20/192.168.8.0/24
Aug 31 16:09:16 NMS dhcpd: Sending on   Socket/fallback/fallback-net
Aug 31 16:52:21 NMS dhcpd: DHCPDISCOVER from 00:0c:29:56:bc:cf via eth0                             #IP租用请求
Aug 31 16:52:22 NMS dhcpd: DHCPOFFER on 192.168.8.101 to 00:0c:29:56:bc:cf (nmserver-7) via eth0  #IP租用提供
Aug 31 16:52:22 NMS dhcpd: DHCPREQUEST for 192.168.8.101 (192.168.8.6) from 00:0c:29:56:bc:cf (nmserver-7) via eth0 #IP租用选择
Aug 31 16:52:22 NMS dhcpd: DHCPACK on 192.168.8.101 to 00:0c:29:56:bc:cf (nmserver-7) via eth0  #IP租用确认

查看DHCP服务器与客户端的租约信息,

[root@NMS etc]# cat /var/lib/dhcpd/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.1.1-P1

lease 192.168.8.101 {
  starts 4 2017/08/31 09:22:42;
  ends 0 2017/09/03 09:22:42;
  cltt 4 2017/08/31 09:22:42;
  binding state active;
  next binding state free;
  hardware ethernet 00:0c:29:56:bc:cf;
  client-hostname "nmserver-7";
}
server-duid "\000\001\000\001!:\200\254\000\014)#\376 ";

从这个文件里面我们就知道有多少个客户端已经向DHCP申请IP了。目前只有一个客户端:
客户端主机名:nmserver-7
MAC地址:00:0c:29:56:bc:cf
客户端IP:192.168.8.101

CentOS6下DHCP服务(二)简单配置案例及故障排查的更多相关文章

  1. CentOS6下DHCP服务(一)工作原理及安装配置说明

    1.DHCP服务用途 DHCP是Dynamic Host Configuration Protocol的简写,DHCP服务器最主要的工作就是自动地将网络参数分配给网络中的每台计算机,让客户端的计算机在 ...

  2. 【linux下dhcp服务的简单搭建及优化部署】

    dhcp server: 1::vim /etc/sysconfig/network-scripts/ifcfg-scfg:配置 server的 static IP: 2:vim /etc/dhcpd ...

  3. Linux系统下DHCP服务安装部署和使用详解

    一.概述 DHCP :动态主机设置协议(英语:Dynamic Host Configuration Protocol,DHCP)是一个局域网的网络协议,使用UDP协议工作,主要有两个用途:用于内部网或 ...

  4. Linux中DHCP服务器的简单配置

    我安装了两台linux系统,一个作为服务器,一个客户端 两个都有3个网卡, 后两个网卡聚合为zhi一个网卡:Linux 网卡聚合 两台电脑都一样. 那么如何为这个聚合网卡进行DHCP的分配呢? 1.由 ...

  5. Linux中DHCP服务器的简单配置(转)

    我安装了两台linux系统,一个作为服务器,一个客户端 两个都有3个网卡, 后两个网卡聚合为zhi一个网卡:Linux 网卡聚合 两台电脑都一样. 那么如何为这个聚合网卡进行DHCP的分配呢? 1.由 ...

  6. CentOS7下NFS服务安装及配置固定端口

    CentOS7下NFS服务安装及配置 系统环境:CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64 软件版本:nfs-utils-1. ...

  7. memcached的安装和linux下memcached服务自启动的配置

    关于memcached在windows和linux环境的安装,以及在Linux系统系memcached服务自启动的配置,可以参考我在csdn上下的博客, windows和linux环境下memcach ...

  8. 5、SAMBA服务二:配置实例

    ①:SAMBA服务一:参数详解 ②:SAMBA服务二:配置实例 5.2.3.Samba共享目录配置实例 1.允许匿名用户读取/it共享目录,修改/etc/samba/smb.conf,在最后添加以下内 ...

  9. Linux下DHCP服务安装配置

    简介 安装配置 一.简介 DHCP (Dynamic Host Configuration Protocol,动态主机管理协议)是一种基于UDP协议且仅限用于局域网的网络协议,主要用途是为局域网内部设 ...

随机推荐

  1. pytorch 检测图片中是否有人

    照搬pytorch官方代码,只是将数据集换成了INRIAPerson数据集中的train和test文件夹. 贴下代码和效果,代码是官方的,就不详细解释了. # License: BSD # Autho ...

  2. 树莓派安装开源智能家居系统 Domoticz

    前言 最近闲来无事开始折腾自己的智能家居系统,对比了几种比较流行的开源智能家居系统,觉得 Domoticz 更适合,Domoticz的官方中文文档,虽然不是很完善但还是可以参考一下.需要注意的是下文用 ...

  3. O - 听说下面都是裸题 (最小生成树模板题)

    Economic times these days are tough, even in Byteland. To reduce the operating costs, the government ...

  4. hdu3038判断区间谎言(带权并查集)

    题目传送门 题目描述:给你n,m,n代表从1到n这么大的数组,m组v,u,val,代表v到u这个区间的总和是val,然后让你判断m组关系中有几组是错误的. 思路:带权并查集,这道题其实算是让我知道什么 ...

  5. C#工具类之字典扩展类

    using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...

  6. 基于python检测端口是否在使用

    开发中,需要开启Modbus Slave服务,但是,modbus_tk 并没有提供一个端口检测的方法,导致 modbus_tcp.TcpServer(port=502) 时候会提示端口被占用 于是需要 ...

  7. Postman如何做接口测试

    Postman 之前是作为Chrome 的一个插件,现在要下载应用才能使用. 以下是postman 的界面: 各个功能区的使用如下: 快捷区: 快捷区提供常用的操作入口,包括运行收藏夹的一组测试数据, ...

  8. Turn.js 实现翻书效果

    Turn.js的官方网址: http://www.turnjs.com/ 官网上运行demo如下,大家主要关注是 属性使用: <!DOCTYPE html> <html> &l ...

  9. 性能测试工具LoadRunner08-LR之Virtual User Generator 检查点

    步骤: 1.点击Vuser--->Run-Time Settings 2.点击Preferences--->Enable Image and text check 3.点击Content ...

  10. 几种常见的排序算法Java实现总结

    public class MySort { final int MAX=20; int num[]=new int[MAX]; { System.out.print("生成的随机数组是:&q ...