Centos 搭建dhcp服务器

Centos 搭建dhcp服务器,第1张

dhcp是动态主机配置协议,使用udp协议,主要使用udp67和udp 68号端口

1.client端会发送dhcp discover广播包

2.dhcp服务器会回应dhcp offer广播包

3.client端会发送dhcp request广播包

4.dhcp服务器发送dhcp ack广播包

[root@mini ~]# rpm -qa dhcp

[root@mini ~]# cat /etc/centos-release

CentOS release 6.9 (Final)

[root@mini ~]# uname -r

2.6.32-696.el6.i686

[root@mini ~]# uname -m

i686

[root@mini ~]# yum install -y dhcp

[root@mini ~]# rpm -qa dhcp

dhcp-4.1.1-53.P1.el6.centos.1.i686

[root@mini ~]# rpm -qc dhcp

/etc/dhcp/dhcpd.conf

/etc/dhcp/dhcpd6.conf

/etc/openldap/schema/dhcp.schema

/etc/portreserve/dhcpd

/etc/sysconfig/dhcpd

/etc/sysconfig/dhcpd6

/etc/sysconfig/dhcrelay

/etc/sysconfig/dhcrelay6

/var/lib/dhcpd/dhcpd.leases

/var/lib/dhcpd/dhcpd6.leases

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

#

# DHCP Server Configuration file.

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

#  see 'man 5 dhcpd.conf'

#

查询dhcp sample文件(dhcpd.conf.sample文件为dhcp配置文件模板)

# rpm -ql dhcp

配置完成后的文件

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

#

# DHCP Server Configuration file.

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

#  see 'man 5 dhcpd.conf'

#

# A slightly different configuration for an internal subnet.

subnet 172.16.1.0 netmask 255.255.255.0 {

range 172.16.1.10 172.16.1.30

option domain-name-servers mini.localdomain

option domain-name "mini.localdomain"

option routers 172.16.1.1

option broadcast-address 172.16.1.1

default-lease-time 600

max-lease-time 7200

}

查看配置是否正确

[root@mini ~]# /etc/init.d/dhcpd configtest

Syntax: OK

DHCP启动失败,并查询到如下报错信息(/var/log/messages)

Nov  6 06:37:24 mini dhcpd: No subnet declaration for eth0 (192.168.28.139).

Nov  6 06:37:24 mini dhcpd: ** Ignoring requests on eth0.  If this is not what

Nov  6 06:37:24 mini dhcpd:    you want, please write a subnet declaration

Nov  6 06:37:24 mini dhcpd:    in your dhcpd.conf file for the network segment

Nov  6 06:37:24 mini dhcpd:    to which interface eth0 is attached. **

Nov  6 06:37:24 mini dhcpd:

Nov  6 06:37:24 mini dhcpd:

Nov  6 06:37:24 mini dhcpd: Not configured to listen on any interfaces!

Nov  6 06:37:24 mini dhcpd:

Nov  6 06:37:24 mini dhcpd: This version of ISC DHCP is based on the release available

Nov  6 06:37:24 mini dhcpd: on ftp.isc.org.  Features have been added and other changes

Nov  6 06:37:24 mini dhcpd: have been made to the base software release in order to make

Nov  6 06:37:24 mini dhcpd: it work better with this distribution.

Nov  6 06:37:24 mini dhcpd:

Nov  6 06:37:24 mini dhcpd: Please report for this software via the CentOS Bugs Database:

Nov  6 06:37:24 mini dhcpd:    http://bugs.centos.org/

Nov  6 06:37:24 mini dhcpd:

Nov  6 06:37:24 mini dhcpd: exiting.

解决办法:

这是因为DHCP程序发现没有“Not configured to listen on any interfaces”,只需要配置相应的IP到目标网卡中便可以解决这个问题。

[root@mini ~]# ifconfig eth1 172.16.1.1/24

[root@mini ~]# /etc/init.d/dhcpd start

Nov  6 06:43:11 mini dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1

Nov  6 06:43:11 mini dhcpd: Copyright 2004-2010 Internet Systems Consortium.

Nov  6 06:43:11 mini dhcpd: All rights reserved.

Nov  6 06:43:11 mini dhcpd: For info, please visit https://www.isc.org/software/dhcp/

Nov  6 06:43:11 mini dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file

Nov  6 06:43:11 mini dhcpd: Wrote 0 leases to leases file.

Nov  6 06:43:11 mini dhcpd: Listening on LPF/eth1/00:0c:29:c5:2b:7e/172.16.1.0/24

Nov  6 06:43:11 mini dhcpd: Sending on  LPF/eth1/00:0c:29:c5:2b:7e/172.16.1.0/24

Nov  6 06:43:11 mini dhcpd:

Nov  6 06:43:11 mini dhcpd: No subnet declaration for eth0 (192.168.28.139).

Nov  6 06:43:11 mini dhcpd: ** Ignoring requests on eth0.  If this is not what

Nov  6 06:43:11 mini dhcpd:    you want, please write a subnet declaration

Nov  6 06:43:11 mini dhcpd:    in your dhcpd.conf file for the network segment

Nov  6 06:43:11 mini dhcpd:    to which interface eth0 is attached. **

Nov  6 06:43:11 mini dhcpd:

Nov  6 06:43:11 mini dhcpd: Sending on  Socket/fallback/fallback-net

[root@mini ~]# cat /var/lib/dhcpd/dhcpd.leases

注意:如果Linux开启了防火墙,那么需要对UDP 67和UDP 68放行。或者直接将放火墙关闭

[TOC]

主要参考知识

centOS7下DNS服务器的安装与配置 - csdn - 主要参考

CentOS7.3使用BIND配置DNS服务器(一) - csdn - 主要参考

四、bind(named)配置文件 - csdn

Linux系统下搭建DNS服务器——DNS原理总结 - csdn - 从概念层面看 DNS 解析

DNS正反向解析库配置篇(一) - csdn - 正反向解析文件配置

DNS配置详解 BIND实现正向解析和反向解析 - cnblog - 正反向解析文件配置

DNS域名解析服务--Named服务 - 说明详细

搭建DNS服务器 - - 域名解析文件配置说明

Linux中DNS配置 - csdn - 配置文件语法检查用的比较好

linux中dns服务器的搭建 - csdn - nslookup 使用的比较好

其他扩展知识

反向域名解析有什么功能? - 百度百科

Centos7/RHEL7中的ifconfig、netstat、route几个常用指令被替代 - csdn

运维小技巧:使用ss命令代替 netstat,和netstat说再见 - csdn

Linux安装nslookup - csdn

如图:

修改前先备份: cp -p /etc/named.conf /etc/named.conf.bak // 参数-p表示备份文件与源文件的属性一致。

修改配置: vi /etc/named.conf , 配置内容如下:

检查一波

添加配置: vi /etc/named.rfc1912.zones , 配置内容如下:

基于 name.localhost 模板,创建配置文件: cp -p /var/named/named.localhost /var/named/named.reading.zt

配置正向域名解析文件 named.reading.zt : vi /var/named/named.reading.zt ,配置内容如下:

说明:

授权 named 用户 chown :named /var/named/named.reading.zt

检查区域文件是否正确 named-checkzone "reading.zt" "/var/named/named.reading.zt" ,如图:

基于 name.localhost 模板,创建配置文件: cp -p /var/named/named.localhost /var/named/named.192.168.0

配置反向域名解析文件 named.192.168.0 : vi /var/named/named.192.168.0

授权 named 用户 chown :named /var/named/named.192.168.0

检查区域文件是否正确 named-checkzone "0.168.192.in-addr.arpa" "/var/named/named.192.168.0" ,如图:

重启 named 服务,让配置生效 systemctl restart named

配置 ifcfg-xxxx vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 , 具体内容如下:

如图:

重启网络服务,让配置生效 systemctl restart network.service

bind-utils 软件包本身提供了测试工具 nslookup

nslookup test.reading.zt , 或者,如下图:

nslookup 192.168.0.232 , 或者,如下图:


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/481708.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-06-08
下一篇2023-06-08

发表评论

登录后才能评论

评论列表(0条)

    保存