DHCP:动态主机配置协议
 
基于udp 监听端口 客户端:68(dhclient)  服务端:67(dhcpd)
地址租约信息:/var/lib/dhcpd/dhcpd.leases
租约:
ip地址租约约定:ip用的租期的50%时客户端必须向服务器提出续约的请求,若失败则会用剩下的一半时间即75%再向服务器请求,一般到87.5%再请求不到ip会收回
 
 
进程为:dhcpd
配置文件:/etc/dhcpd.conf 
辅助配置文件:/etc/sysconfig/dhcpd
服务脚本: /etc/init.d/dhcpd start|stop|restart
 
样例配置文件:/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample
出现同一选项是以自由选项为准 作用范围小优先级高
配置DHCP服务器:
前提:
     关掉selinux
     虚拟机中关掉自身的dhcp
     网卡使用hostonly 配置其ip
配置文件:/etc/dhcpd.conf
ddns-update-style interim;    dhcp支持的dns动态更新的方式
ignore client-updates;   不允许客户端更新dns记录
 
subnet 192.168.20.0 netmask 255.255.255.0 {
 
# --- default gateway
        option routers                  192.168.20.1;            网关
        option subnet-mask              255.255.255.0;
 
#       option nis-domain               "domain.org";               nis验证域名
        option domain-name              "example.com";              动态域名
        option domain-name-servers      100.100.10.1,200.200.20.2;  dns服务器
 
        option time-offset              -18000; # Eastern Standard Time
#       option ntp-servers              192.168.1.1;
#       option netbios-name-servers     192.168.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  192.168.20.4 192.168.20.25;           允许分配的地址池
        default-lease-time 21600;                    租约时间
        max-lease-time 43200;                        租约最大时间
 
        # we want the nameserver to appear at a fixed address
        host ns {      主机ip的绑定
                hardware ethernet 00:0C:29:F5:29:21;   主机mac地址
                fixed-address 192.168.20.40;           主机ip
        }
}
       
默认监听每个网卡:0.0.0.0
监听特定网卡地址:/etc/sysconfig/dhcpd配置
                  DHCPDARGS=eth0
客户端动态获得地址:
dhclient eth0 
参数-d 测试会显示获得过程 ctrl +c 取消
要重新获得地址要killall dhclient
使用自己规定的dns服务器在/etc/sysconfig/network-scripts/ifcfg-eth0    添加PEERDNS=no
 
定义地址类别:
            基于mac地址的
            基于操作系统的
class "vmware" {
                match if substring (hardware, 1, 3) = 00:0C:29;
}
 
class "microsoft-client" {
                     match if substring (option vendor-class-identifier, 0, 3) = "MSFT";
                     option routers 192.168.0.254
                     
                      option domain-name-servers      100.100.10.1,200.200.20.2; 
}
    
       pool {
        allow members of "vmware";
        range 192.168.20.40 192.168.20.60;
 
        }
        pool {
        deny members of "vmware";
        deny members of "microsoft-client";
        range 192.168.20.100 192.168.20.120;
}
 
 
中继器代理的应用:实现不同网络段的ip的分配
/etc/sysconfig/dhcrelay
INTERFACES="eth0 eth1" 实现网段的接口即网卡接口
DHCPSERCERS="192.168.20.5"  dhcp服务器地址
开启服务server dhcrelay restart
服务器的配置:/etc/dhcpd.conf 添加
subnet 192.168.100.0 netmask 255.255.255.0 {
        option routers 192.168.100.1;
        option subnet-mask 255.255.255.0;
        range 192.168.100.60 192.168.100.70;
 
}