CentOS6下DHCP服务(二)简单配置案例及故障排查

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
[[email protected] dhcp]# /etc/init.d/dhcpd start
正在启动 dhcpd:                                           [失败]

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

[[email protected] 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”
那么我来看配置文件,根据提示找出其中的错误;

[[email protected] 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

按照日志信息更改后的配置文件如下:
[[email protected] 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,

[[email protected] etc]# /etc/init.d/dhcpd start
正在启动 dhcpd:                                           [确定]

可以看到这次能启动了。

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

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

[[email protected] 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

客户端环境
[[email protected] ~]# 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
[[email protected] ~]# cat /etc/redhat-release
CentOS release 7.3.1611 (AltArch)

在客户端修改网卡配置文件,让主机自动取得网络参数;
[[email protected] ~]# 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服务器来获取网络参数了!

修改配置文件后重启客户端网络
[[email protected] ~]# systemctl restart network

查看IP,可以看到客户端已经获取到的IP是192.168.8.101/24
[[email protected] ~]# 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

查看一下客户端路由
[[email protected] ~]# 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连接状态,
[[email protected] ~]# 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设置
[[email protected] 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个过程:

[[email protected] 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服务器与客户端的租约信息,

[[email protected] 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

时间: 2024-09-30 05:11:48

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

DHCP服务介绍及Linux下DHCP服务的管理配置

1. DHCP服务简介 DHCP是Dynamic Host Configuration Protocol,动态主机配置协议,是用来在物理网络给主机分配ip地址的一种方式,区别于bootp,一次分配终身使用的缺点. DHCP提出的租约的概念,使得可以根据需要动态确定主机需要的IP地址,并且IP地址可以循环使用. 2. DHCP结构 DHCP是典型的C/S结构,需要服务端启动守护进程来保证来自client段的请求能被响应,DHCP的工作原理如下: 可以通过DORA来记忆: Client: DHCP

【初学菜鸟作--邮件服务的简单配置案例】

邮件服务器的配置以及使用 实验一:                    实验目的:简单搭建出邮件服务器并测试其可用性                    实验环境:DNS服务器一台,安装有Portfix的邮件服务器一台 实验步骤: 一.邮件的发送(SMTP) 1.在邮件服务器配置主机名,ip,并安装portfix并启动 [[email protected]~]# tail -2 /etc/sysconfig/network HOSTNAME=mail.tarena.com   [[email

linux下DHCP服务搭建

实验环境 RHEL5.9 dhcp服务器 RHEL5.9 LINUX客户端 win7    windows客户端 实验前提: 1,服务器与客户机需要在同一个网段 2,dhcp需要有固定IP 实验步骤: 服务端操作步骤: 1,设置IP cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0    //设备名 BOOTPROTO=static    //静态IP HWADDR=00:0C:29:DB:02:CE ONBOOT=yes  //

DNS服务器之简单配置(一)

名词解释: 域名: 域名是域名系统名字空间中,从当前节点到根节点的路径上所有节点标记的点分顺序连接. 域: 域是指域名系统名字空间中的一个子集,也就是树形结构名字空间中的一颗子树.这个子树根节点的域名就是该域的名字, 域的级别: 顶级域(TLD, Top Level Domain)是指域名系统名字空间中根节点下最顶层的域.顶级域也称一级域,顶级域的下级就是二级域,二级域的下级就是三级域,以此类推.每个域都是其上级域的子域.最早的顶级域名,也是现在说的国际域名,按照用途分为的7个大类: .com:

5、SAMBA服务二:配置实例

①:SAMBA服务一:参数详解 ②:SAMBA服务二:配置实例 5.2.3.Samba共享目录配置实例 原文地址:https://www.cnblogs.com/-xuan/p/10542392.html

Linux下 DHCP 服务的配置

DHCP Server 实验需求: 公司要求将闲置的一台Linux主机配置为DHCP服务器,以便为局域网内员工的办公用机提供自动分配IP地址的服务,提高网络管理和维护的效率. 需要满足的基本要求如下所述: 1.为192.168.10.0/24网段的客户机自动配置网络参数. 用来给客户机自动分配的IP地址范围是:192.168.10.50-192.168.10.100 192.168.10.120-192.168.10.200. 客户机的默认网关地址设为192.168.10.1 客户机所使用的DN

Linux下DHCP服务安装配置

简介 安装配置 简介 DHCP (Dynamic Host Configuration Protocol,动态主机管理协议)是一种基于UDP协议且仅限用于局域网的网络协议,主要用途是为局域网内部设备或网络供应商自动分配IP地址,通常会应用在大型的局域网环境中或局域网内存在比较多的移动办公设备,DHCP协议能够实现集中的管理.分配IP地址. DHCP服务程序能够使局域网内的主机自动且动态的获取IP地址.子网掩码.网关地址以及DNS服务器地址等信息,且能够有效的提升地址使用率,提高配置效率,减少管理

Linux 下DHCP服务器rpm安装配置及其测试

一.了解DHCP DHCP服务提供动态指定IP地址和配置参数的机制.有动态和静态两种方式. 二.rpm安装 因为配过Samba,所以感觉挺简单. 首先找到主程序和几个附属程序的rpm的安装包.应该都是在media的DVD的Server包里的.用find找到文件位置然后rpm -ivh安装就可以了.[好像不能直接命令进入DVD...于是选择窗口进入...]安装完之后,rpm -qa|grep dhcp可以查看是否安装成功. 三.配置 主配置文件是/etc目录下的dhcpd.conf文件,但是这个文

Linux服务的简单配置(homework)

Linux服务也学习一个礼拜啦,趁这闲暇之际,归纳一下这周所学的服务. 应用环境:Redhat 5.9 一.DHCP DHCP是动态主机配置协议,可自动分配入网参数,实现各客户机IP的自动获取 1.为服务器配置一个固定的Ip地址如192.168.4.2 2.确认已安装dhcp软件包 3.建立dhcpd.conf配置文件. [[email protected] ~]# vim/etc/dhcpd.conf subnet 192.168.4.0 netmask 255.255.255.0 { opt