CentOS6下DHCP服务(二)简单配置案例及故障排查
【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-stylenone;
ignore client-update ;
default-lease-time259200;
max-lease-time518400;
option routers192.168.8.254;
option domain-name"centos.me"
optiondomain-name-servers202.102.224.68,202.102.227.68;
#IP分配
subnet192.168.8.0 netmask 255.255.255.0 {
range192.168.8.101192.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
3ddns-update-stylenone;
4ignore client-update ;
5default-lease-time259200;
6max-lease-time518400;
7option routers192.168.8.254;
8option domain-name"centos.me"
9optiondomain-name-servers202.102.224.68,202.102.227.68;
10
11#IP分配
12
13subnet192.168.8.0 netmask 255.255.255.0 {
14range192.168.8.101192.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
3ddns-update-stylenone;
4ignore client-updates;
5default-lease-time259200;
6max-lease-time518400;
7option routers192.168.8.254;
8option domain-name"centos.me";
9optiondomain-name-servers202.102.224.68,202.102.227.68;
10
11#IP分配
12
13subnet192.168.8.0 netmask 255.255.255.0 {
14range192.168.8.101192.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
udp00 0.0.0.0:670.0.0.0:*17017/dhcpd
再次查看日志文件输出信息
[root@NMS etc]# tail -n10 /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 onLPF/eth0/00:0c:29:23:fe:20/192.168.8.0/24
Aug 31 16:09:16 NMS dhcpd: Sending onSocket/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
ether b6:83:d4:66:3a:4ctxqueuelen 1000(Ethernet)
RX packets 0bytes 0 (0.0 B)
RX errors 0dropped 0overruns 0frame 0
TX packets 0bytes 0 (0.0 B)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
ens33: flags=4163
inet 192.168.8.101netmask 255.255.255.0broadcast 192.168.8.255
inet6 fe80::20c:29ff:fe56:bccfprefixlen 64scopeid 0x20
ether 00:0c:29:56:bc:cftxqueuelen 1000(Ethernet)
RX packets 29323bytes 2119863 (2.0 MiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 29052bytes 2256533 (2.1 MiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
lo: flags=73
inet 127.0.0.1netmask 255.0.0.0
inet6 ::1prefixlen 128scopeid 0x10
looptxqueuelen 1(Local Loopback)
RX packets 2212bytes 150063 (146.5 KiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 2212bytes 150063 (146.5 KiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
查看一下客户端路由
[root@nmserver-7 ~]# route -n
Kernel IP routing table
DestinationGatewayGenmaskFlags Metric RefUse Iface
0.0.0.0192.168.8.2540.0.0.0UG10000 ens33
192.168.8.00.0.0.0255.255.255.0U10000 ens33
查看客户端DHCP连接状态,
[root@nmserver-7 ~]# netstat -tunlp |grep dhc
udp00 0.0.0.0:680.0.0.0:*4195/dhclient
udp00 0.0.0.0:224240.0.0.0:*4195/dhclient
udp600 :::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 -n10 /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 onLPF/eth0/00:0c:29:23:fe:20/192.168.8.0/24
Aug 31 16:09:16 NMS dhcpd: Sending onSocket/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
转载于:https://www.cnblogs.com/me80/p/7459595.html
推荐阅读
- 开学第一天(下)
- 【故障公告】周五下午的一次突发故障
- 生活随笔|好天气下的意外之喜
- MongoDB,Wondows下免安装版|MongoDB,Wondows下免安装版 (简化版操作)
- 汇讲-勇于突破
- Android中的AES加密-下
- 说的真好
- 放下心中的偶像包袱吧
- Linux下面如何查看tomcat已经使用多少线程
- 【1057快报】深入机关,走下田间,交通普法,共创文明