首页 > 代码库 > DHCP服务器

DHCP服务器

源自《Linux 运维之道》丁一明编著 一书的总结

DHCP是Dynamic Host Configuration Protocol(动态主机配置协议)的简写形式,使用DHCP协议可以为客户端主机自动分配TCP/IP参数信息,如IP地址,子网掩码,网关、DNS等。

安装yun –y install dhcp

默认状态下dhcp服务会将日志保存在/var/log/messages文件中,如果遇到服务器故障问题,可以检查该文件。配置文件在于/etc/dhcp/dhcpd.conf文件中。

[root@localhost ~]# gedit /etc/dhcp/dhcpd.conf

配置文件:

#

# DHCP Server Configuration file.

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

# see ‘man 5 dhcpd.conf‘

#

#

subnet 192.168.118.0 netmask 255.255.255.0 {

range 192.168.118.5 192.168.118.15;

option domain-name-servers boot.example.com;

option domain-name "boot.example.com";

option routers 192.168.118.1;

default-lease-time 600;

max-lease-time 7200;

next-server 192.168.118.253;

filename "pxelinux.0";

}

也可以指定主机,并分配给它ip。

默认状态下,dhcp服务将会将日志保存在/var/log/messages文件中,如果遇到服务器故障问题,可以检查该文件。网络参数租期为/var/lib/dhcpd/dhcpd.leases,可以通过检查该文件查看服务器已经分配的资源和相关租期信息。

[root@localhost /]# 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.118.5 {

starts 6 2014/06/21 08:55:49;

ends 6 2014/06/21 09:05:49;

tstp 6 2014/06/21 09:05:49;

cltt 6 2014/06/21 08:55:49;

binding state free;

hardware ethernet 00:0c:29:a0:dd:f2;

}

lease 192.168.118.6 {

starts 6 2014/06/21 11:26:59;

ends 6 2014/06/21 11:36:59;

tstp 6 2014/06/21 11:36:59;

cltt 6 2014/06/21 11:26:59;

binding state free;

hardware ethernet 00:0c:29:b8:12:0d;

}

server-duid "\000\001\000\001\0337\364$\000\014)b\375\001";