DHCP服务器配置----转

DHCP:Dynamic Host Configuration Protocol前身是bootp
lease:租约
续租:租约到一半的时候就要申请续租
广播:第一个响应的服务器
广播申请,广播响应
广播回复确认


IP:
MASK:
GATEWAY:
DNS:

Client----->DHCPDISCOVER
			DHCPOFER<--------Server
Client----->DHCPREQUEST
            DHCPACK<-----Server
以上都广播报文


续租:
Client----->DHCPREQUEST
			DHCPACK<-------Server
以上为单播

DHCP不能跨网段进行

需要配置路由器的DHCP-RELAY,DHCP中继


DHCP分配的网段要在某一个网卡的地址在同一网段内
[root@salt-master ~]# yum install dhcp
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
iso                                                                                                                                                                 | 3.7 kB     00:00     
Not using downloaded repomd.xml because it is older than what we have:
  Current   : Mon May 23 07:51:24 2016
  Downloaded: Sun May 22 13:52:33 2016
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.1.1-51.P1.el6.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================================
 Package                                Arch                                     Version                                                       Repository                             Size
===========================================================================================================================================================================================
Installing:
 dhcp                                   x86_64                                   12:4.1.1-51.P1.el6.centos                                     iso                                   823 k

Transaction Summary
===========================================================================================================================================================================================
Install       1 Package(s)

Total download size: 823 k
Installed size: 1.9 M
Is this ok [y/N]: y
Downloading Packages:
dhcp-4.1.1-51.P1.el6.centos.x86_64.rpm                                                                                                                              | 823 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : 12:dhcp-4.1.1-51.P1.el6.centos.x86_64                                                                                                                                   1/1 
  Verifying  : 12:dhcp-4.1.1-51.P1.el6.centos.x86_64                                                                                                                                   1/1 

Installed:
  dhcp.x86_64 12:4.1.1-51.P1.el6.centos                                                                                                                                                    

Complete!
[root@salt-master ~]# rpm -ql dhcp
/etc/dhcp
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/openldap/schema/dhcp.schema
/etc/portreserve/dhcpd
/etc/rc.d/init.d/dhcpd
/etc/rc.d/init.d/dhcpd6
/etc/rc.d/init.d/dhcrelay
/etc/rc.d/init.d/dhcrelay6
/etc/sysconfig/dhcpd
/etc/sysconfig/dhcpd6
/etc/sysconfig/dhcrelay
/etc/sysconfig/dhcrelay6
/usr/bin/omshell
/usr/sbin/dhcpd
/usr/sbin/dhcrelay
/usr/share/doc/dhcp-4.1.1
/usr/share/doc/dhcp-4.1.1/3.0b1-lease-convert
/usr/share/doc/dhcp-4.1.1/IANA-arp-parameters
/usr/share/doc/dhcp-4.1.1/README.ldap
/usr/share/doc/dhcp-4.1.1/api+protocol
/usr/share/doc/dhcp-4.1.1/dhclient-tz-exithook.sh
/usr/share/doc/dhcp-4.1.1/dhcpd-conf-to-ldap
/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample
/usr/share/doc/dhcp-4.1.1/dhcpd6.conf.sample
/usr/share/doc/dhcp-4.1.1/draft-ietf-dhc-ldap-schema-01.txt
/usr/share/doc/dhcp-4.1.1/ms2isc
/usr/share/doc/dhcp-4.1.1/ms2isc/Registry.perlmodule
/usr/share/doc/dhcp-4.1.1/ms2isc/ms2isc.pl
/usr/share/doc/dhcp-4.1.1/ms2isc/readme.txt
/usr/share/doc/dhcp-4.1.1/sethostname.sh
/usr/share/doc/dhcp-4.1.1/solaris.init
/usr/share/man/man1/omshell.1.gz
/usr/share/man/man5/dhcpd.conf.5.gz
/usr/share/man/man5/dhcpd.leases.5.gz
/usr/share/man/man8/dhcpd.8.gz
/usr/share/man/man8/dhcrelay.8.gz
/var/lib/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.lease

[root@salt-master ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf 
cp: overwrite `/etc/dhcp/dhcpd.conf'? y

DHCP-Server:UDP/67
DHCP-Client:UDP/68
[root@salt-master ~]# vim /etc/dhcp/dhcpd.conf 

option domain-name "uplooking.com";
option domain-name-servers 192.168.1.200;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
        option routers          192.168.1.1;
        option subnet-mask      255.255.255.0;
        option time-offset      -18000;
        range 192.168.1.220 192.168.1.223;
        default-lease-time 21600;
        max-lease-time 43200;
}
[root@salt-master ~]# /etc/init.d/dhcpd start
Starting dhcpd:                                            [  OK  ]
[root@salt-master ~]# netstat -anutlp|grep dhcp
udp        0      0 0.0.0.0:67                  0.0.0.0:*                               2085/dhcpd 

找一台服务器由于多个dhcp的存在他可能不会选则自己的服务器或者你想给服务器指定IP地址
[root@salt-master ~]# vim /etc/dhcp/dhcpd.conf 

option domain-name "uplooking.com";
option domain-name-servers 192.168.1.200;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
        option routers          192.168.1.1;
        option subnet-mask      255.255.255.0;
        option time-offset      -18000;
        range 192.168.1.223 192.168.1.224;
        default-lease-time 21600;
        max-lease-time 43200;
        host ns2 {
                hardware ethernet 00:0C:29:38:1E:F7;
                fixed-address 192.168.1.201;
        }
}
添加host选项
注意这个地址一定部在range的范围之内
另外有专用的话等级比自动分配要高



客户端
[root@salt-master ~]# dhclient -h
Internet Systems Consortium DHCP Client 4.1.1-P1
Copyright 2004-2010 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Usage: dhclient [-4|-6] [-SNTP1dvrx] [-nw] [-p <port>] [-s server]
                [-cf config-file] [-lf lease-file][-pf pid-file] [-e VAR=val]
                [-I <dhcp-client-identifier>] [-B]
                [-H <host-name> | -F <fqdn.fqdn>] [-timeout <timeout>]
                [-V <vendor-class-identifier>]
                [-R <request option list>]
                [-sf script-file] [interface]
客户端直接
dhclient命令就可以用了手动获取dhcp分配地址
dhclient -d选项工作在前台

转载于:https://my.oschina.net/liubaizi/blog/758030

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值