简单配置DHCP服务器
DHCP:动态主机设定协定(Dynamic Host Configuration Protocol)是一个局域网的网络协议,使用UDP协议工作,主要有两个用途:
(1).给内部网络或网络服务供应商自动分配IP地址给用户
(2).给内部网络管理员作为对所有电脑作中央管理的手段
说明:
dhcp服务不能垮网段,也不能用于外网,只能用于内网环境中
在一个内网网段中,只允许有一台dhcp服务器,不允许出现2台或多台,否则会出现冲突导致dhcp服务不能正常使用。
具体配置:
1.在服务器端:
[root@localhost ~]# rpm -q dhcp package dhcp is not installed #此时发现没有安装dhcp # yum install dhcp –y [root@localhost ~]# cat /etc/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
# cd /usr/share/doc/dhcp-3.0.5/ # cp dhcpd.conf.sample /etc/dhcpd.conf # cd
下面是一个配置实例:
# vim /etc/dhcpd.conf ddns-update-style interim; ignore client-updates; subnet 172.16.0.0 netmask 255.255.0.0 { # --- default gateway option routers 172.16.1.1; option subnet-mask 255.255.0.0; option nis-domain "domain.org"; option domain-name "domain.org"; option domain-name-servers 172.16.1.1; option time-offset -18000; # Eastern Standard Time # option ntp-servers 172.16.1.1; # option netbios-name-servers 172.16.1.1; # --- Selects point-to-point node (default is hybrid). Don't change this unless # -- you understand Netbios very well # option netbios-node-type 2; range dynamic-bootp 172.16.0.1 172.16.55.254; default-lease-time 21600; max-lease-time 43200; # we want the nameserver to appear at a fixed address host ns { next-server marvin.redhat.com; hardware ethernet 12:34:56:78:AB:CD; fixed-address 207.175.42.254; } }
说明:
subnet 172.16.0.0 netmask 255.255.0.0 # 设置子网声明
option routers 172.16.1.1; #为DHCP客户设置默认网关为172.16.1.1
option subnet-mask 255.255.0.0; #为DHCP客户设置子网掩码为255.255.0.0
option domain-name-servers 172.16.1.1; #为DHCP客户设置DNS域为172.16.1.1
range dynamic-bootp 172.16.0.1 172.16.0.254; #为DHCP客户设置自动获取的IP地址范围
default-lease-time 21600; #为DHCP客户设置默认地址租期
max-lease-time 43200; #为DHCP客户设置最大地址租期
# service dhcpd start
2.在客户端:
[root@lihuan ~]# rpm -q dhcp
package dhcp is not installed
确保在客户端没有安装dhcp软件
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
把”BOOTPROTO=static”改为”BOOTPROTO=dhcp”
# service network restart
转载于:https://blog.51cto.com/lihuan/838002