红联Linux门户
Linux帮助

CentOS 7部署DHCP服务

发布时间:2015-03-31 11:27:05来源:linux网站作者:chenzhou312

CentOS 7 DHCP服务器部署

背景:

某单位需要配置一台DHCP服务器给桌面PC机分配IP地址。 这些PC机分配到二个VLAN中,为便于ip管理和降低公司管理成本搭建公司内部的DHCP服务器。

IP地址规划与配置
网络  IP地址范围  网关  备份
VLAN1  

192.168.188.100-192.168.188.253/24
排除 192.168.188.160到192.168.188.169  192.168.188.2  
VLAN2  192.168.189.100-192.168.189.253/24  192.168.189.2

DHCP服务器为ZZyh1.linux.LOCAL,其IP地址为192.168.188.15。

此单位的DNS服务器的地址为192.168.188.15、192.168.188.16

需要将192.168.188.111保留给无法配置静态IP地址的打印机,其MAC地址为00:12:34:56:78:90

VLAN1的地址租约是3天,VLAN2的地址租约是8天


zzyh1上的DHCP配置

查看版本信息

[root@localhost~]# uname -a

Linuxlocalhost.localdomain 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014x86_64 x86_64 x86_64 GNU/Linux

[root@localhost~]# cat /etc/RedHat-release

CentOSLinux release 7.0.1406 (Core)


更该主机名

[root@zzyh1~]# vi /etc/hostname

[root@zzyh1~]# cat /etc/hostname

zzyh1.linux.local


安装

#mount /dev/cdrom /media                  //挂在光驱

/dev/sr0on /media type iso9660 (ro,relatime)

#cd /media/Packages                        //进入目录

[root@zzyh1Packages]# ls dhcp*

dhcp-4.2.5-27.el7.centos.x86_64.rpm

dhcp-common-4.2.5-27.el7.centos.x86_64.rpm

dhcp-libs-4.2.5-27.el7.centos.x86_64.rpm


安装支持包

[root@zzyh1Packages]# rpm -vihdhcp-4.2.5-27.el7.centos.x86_64.rpm

warning:dhcp-4.2.5-27.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key IDf4a80eb5: NOKEY

Preparing...                        ################################# [100%]

Updating/ installing...

1:dhcp-12:4.2.5-27.el7.centos      ################################# [100%]


查看安装后生成的配置文件

[root@zzyh1Packages]# rpm -qc dhcp

/etc/dhcp/dhcpd.conf

/etc/dhcp/dhcpd6.conf

/etc/openldap/schema/dhcp.schema

/etc/sysconfig/dhcpd

/var/lib/dhcpd/dhcpd.leases

/var/lib/dhcpd/dhcpd6.leases

[root@zzyh1Packages]# cd /etc/dhcp

[root@zzyh1dhcp]# ls

dhclient.d  dhcpd6.conf dhcpd.conf


配置DHCP的文件

编辑前备份

[root@zzyh1 dhcp]# cpdhcpd.conf dhcpd.conf.origin

[root@zzyh1dhcp]# cat /etc/dhcp/dhcpd.conf

#

# DHCPServer Configuration file.

#  see /usr/share/doc/dhcp*/dhcpd.conf.example

#  see dhcpd.conf(5) man page

#


编辑DHCP的配置文件

# vi/etc/dhcp/dhcpd.conf                //编辑下面内容

optiondomain-name "linuxidc.local";

optiondomain-name-servers 192.168.188.11, 192.168.188.12;

default-lease-time691200;

max-lease-time691200;

subnet192.168.188.0 netmask 255.255.255.0 {

range 192.168.188.100 192.168.188.159;

range 192.168.188.170 192.168.188.253;

default-lease-time 259200;

max-lease-time 259200;

option routers 192.168.188.2;

}

subnet192.168.189.0 netmask 255.255.255.0 {

range 192.168.189.100 192.168.189.253;

option routers 192.168.189.2;

}


host printer1 {

hardware ethernet 00:12:34:56:78:90;

fixed-address 192.168.188.111;
}


重启DHCP服务

配置DHCPD为自动 启动, 这在CentOS 7上的新的变化 了

# chkconfig dhcpd on            //设置自动启动

Note:Forwarding request to 'systemctl enable dhcpd.service'.

ln -s'/usr/lib/systemd/system/dhcpd.service''/etc/systemd/system/multi-user.target.wants/dhcpd.service'

#systemctl enable dhcpd

# systemctl is-enabled dhcpd    

enabled


测试

在一台Windows客户机上进行测试

当用户租用到IP后

#tail /var/log/messages          //查看日志的命令

#tail /var/lib/dhcpd/dhcpd/leases  //只查看dhcp的日志

分配Ip的日志

Aug 2402:04:34 zzyh1 dhcpd: Listening onLPF/eno16777728/00:0c:29:e0:40:8a/192.168.188.0/24

Aug 2402:04:34 zzyh1 dhcpd: Sending on  LPF/eno16777728/00:0c:29:e0:40:8a/192.168.188.0/24

Aug 2402:04:34 zzyh1 dhcpd: Sending on  Socket/fallback/fallback-net

Aug 2402:06:23 zzyh1 dhcpd: DHCPDISCOVER from 00:0c:29:9c:6d:9a via eno16777728

Aug 2402:06:24 zzyh1 dhcpd: DHCPOFFER on 192.168.188.100 to 00:0c:29:9c:6d:9a (zzyh)via eno16777728

Aug 2402:06:24 zzyh1 dhcpd: DHCPREQUEST for 192.168.188.100 (192.168.188.15) from00:0c:29:9c:6d:9a (zzyh) via eno16777728

Aug 2402:06:24 zzyh1 dhcpd: DHCPACK on 192.168.188.100 to 00:0c:29:9c:6d:9a (zzyh)via eno16777728


总结:

这是项目的开始,整个项目包括了DNS,FTP,SAMBA,Web,NTP和防火墙的设置。这些点滴记录这我的成长,菜鸟之路开始慢慢的走向正规系统的练习。希望你的关注和督促,努力吧!骚(少)年!