linux dhcp build Introduction

 

 

Dhcp Description :

Full name (Dynamic Host Configuration Protocol)

The most common four kinds of attributes: ip / netmask / dns server / gateway

How it works: predecessor boot protocol (bootp), diskless work, provided for the terminal server disk space, at that time, need to get the boot before the host ip, boot protocol agreement produced, this time only card mac address, this card after the self-powered wake-up play client obtains ip, sending rarp protocol broadcast packets, by mac get ip, then use the ip acquired from the server operating system, ip boot protocol allocation is fixed, the next time you use or the ip, so ip address has a limit, there arises a DHCP, to achieve the purpose of the overload ip address, resulting in the concept of lease.

 

Dhcp message type:

1.client discover: discovery

                   2.server offer:(ip/netmask,gw)

                   3.client request:

                   4.server ack:

 

 

 

Dhcp package installation:

 

 

Dhcp package comes with dhcpd, dhcrelay two daemons, both a process can not be started at the same time, dhcpd can ipv4, ipv6 to provide services, respectively, using a different configuration file dhcpd.conf and dhcpd6.conf, but unavailable ipv6 independent start, need the support of other software.

 

Daemon

The corresponding service

Profiles

Dhcpd

Dhcpd.service

Dhcpd.conf

Dhcpd6.service

Dhcpd6.conf

dhcrelay

Dhcrelay.service

The authors did not find, do not use dhcp relay also.

 

/ User / sbin / dhcpd daemon

     /etc/dhcp/dhcpd.conf to / etc / rc.d / init.d / dhcpd

    

除了dhcp包也可以使用dnsmasq(轻量级dns与dhcp)

Dhcp文件配置:

成功安装dhcp后开始配置,我们可以看到原本配置文件为空,但是有提供一个模板,只要复制即可:

 

 

option domain-name "magedu.com ";#域名选项option用来指定属性,指定除了地址掩码外的其他属性

option domain-name-servers 172.16.0.1,8.8.8.8;#域名服务器选项

 

default-lease-time 86400;#默认租期86400(一天)

max-lease-time 86400;#最大租期

在dhcp中配置文件里,option既可以定义在全局,也可以定义于subnet中,每一个subnet中定义一个子网,也可以放在host中,这个是专门保留的,但是要注意,范围越小越优先!!也说明配置信息可以被继承。

而域名服务器是要配置成ip地址的,因为主机拿到域名的话是无法解析的。

修改后的配置文件如下:

 

 

其他的配置并不需要,可以全部注释掉,子网配置需要与dhcp主机在同一个网段。

Dhcp测试:

通过以下命令重启并且查看dhcp启动状态及端口:

systemctl start dhcpd.service

systemctl status dhcpd.service

ss -unlp

 

 

可以看出来:dhcp监听在67端口

通过另一台主机,使用dhclient -d在前台获取ip:

 

 

可以看出可以获取地址,dhcp配置成功

并且cat /var/lib/dhcpd/dhcpd.leases可以查看dhcp分配记录:

 

 

我们刚刚并没有给dhcp配置网关,所以clinet1的网关并没有改变,接下来我们配置一下网关:

在dhcpd.conf 加入option routers 172.16.100.67;如果有多个subnet通常会写入到相应subnet中。

注意:每次写完文件需要systemctl restart dhcpd.service 重启服务

查看dhcp运行状态:

 

 

      

Guess you like

Origin www.cnblogs.com/abels0025/p/11390434.html