搭建DHCP服务器攻略

Top

OS 下 DHCP 配置

安装 DHCP

# centos6.8
yum install dhcp
# rhel8.3  
yum install dhcp-server
# 若要配置启动  ipv6 服务,则还需安装如下服务
yum install radvd  #  可为IPv6 DHCP提供路由广播

IPV4 配置

# 配置文件地址:/etc/dhcp/dhcpd.conf
# /etc/dhcp/dhcpd.conf 配置文件如下

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option arch code 93 = unsigned integer 16;

subnet 172.16.0.0 netmask 255.255.128.0 {
    # 设置客户端默认网关
    option routers             172.16.1.10;
    # 设置网络内部DNS服务器的IP地址
    option domain-name-servers 172.16.1.10;
    # 设置客户端子网掩码
    option subnet-mask         255.255.128.0;
    # 定义DHCP地址池的服务范围,需排除静态地址
    range dynamic-bootp        172.16.10.1 172.16.90.254;
    # 设置默认租约时间, 单位: s 
    default-lease-time         21600;
    # 设置最大租约时间
    max-lease-time             43200;
    # 设置服务器从引导文件中装如主机名,应用于无盘工作站
    next-server                172.16.1.10;
    class "pxeclients" {
        match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
#    if exists user-class and option user-class = "iPXE" {
#        filename "ipxe_after/index.ipxe";
#    } else {
        next-server                172.16.1.10;
        if option arch = 00:07 {
            # 开始启动文件的名称,应用于无盘工作站
            filename "efi/snponly.efi";
        } else if option arch = 00:09 {
            filename "efi/snponly.efi";
        } else if option arch = 00:06 {
            filename "efi/snponly.efi";
        } else {
 #  legacy 模式
            filename "undionly.kpxe";
        }
    }
}

# group for Cobbler DHCP tag: default 为一组参数提供声明
group {

}
 
# 设置永久 IP 地址
host dhcp-client{
    # Mac 地址
    hardware ethernet 00:0C:29:E4:81:9A;
    # IP 地址
    fixed-address 192.168.1.199;
}

IPV6 配置

# ipv6 配置文件地址:/etc/dhcp/dhcpd6.conf
# radvd  服务配置文件地址: /etc/radvd.conf
# 注意: 配置文件书写若有误,则dhcpd6 服务无法开启
# /etc/dhcp/dhcpd6.conf 配置文件如下
default-lease-time 2592000;
preferred-lifetime 604800;
option dhcp-renewal-time 3600;
option dhcp-rebinding-time 7200;
allow leasequery;
option dhcp6.name-servers ::ffff:172.16.1.10;
option dhcp6.domain-search "ipv6.pxe.com";
option dhcp6.bootfile-url code 59 = string;
option dhcp6.client-arch-type code 61 = array of unsigned integer 16;
option dhcp6.info-refresh-time 21600;
dhcpv6-lease-file-name "/var/lib/dhcpd/dhcpd6.leases";
subnet6 faaa:a:a:a::/64 {
        range6 faaa:a:a:a::3 faaa:a:a:a::ffff;
        range6 faaa:a:a:a:: temporary;
        option dhcp6.bootfile-url "tftp://[::ffff:172.16.1.10]/efi/snponly.efi";
}

#  /etc/radvd.conf  配置文件如下 : 
interface eth6                  # 根据实际注意修改网口名
{
        AdvSendAdvert on;
        MinRtrAdvInterval 30;
        MaxRtrAdvInterval 600;
        prefix faaa:a:a:a::/64
        {
                AdvOnLink on;
                AdvAutonomous on;
                AdvRouterAddr on;
        };
        route faaa:a:a:a::/64 {
        };
};

# tftp 服务器地址一定要正确 

ipv6 其他配置

# 打开 IPv6 转发功能,否则客户端之间IPv6无法通信
sysctl -w net.ipv6.conf.all.forwarding=1

开启 dhcp 服务

# centos 6.8 
service dhcpd  status
service dhcpd6  status
# rhel8.3
systemctl start dhcpd.service
systemctl start dhcpd6.servicec
systemctl start radvd

其他

/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid enp125s0f0

华三交换机 DHCP 配置

DHCP 常用命令

# 查看交换机下地址池的配置
display dhcp server pool

# 开启DHCP服务
dhcp enable
# 创建DHCP地址池,并进入DHCP地址池视图
dhcp server ip-pool <pool-name>
# 查看DHCP服务器为客户端分配的IP地址
display dhcp server ip-in-use

完整配置 DHCP 服务

# 创建DHCP地址池,并进入DHCP地址池视图
dhcp server ip-pool 172.16.0 
# 配置DHCP地址池动态分配的主网段
network 172.16.0.0 17
# 配置地址池动态分配的IP地址范围,即公共地址范围 
address range 172.16.100.1 172.16.120.254
# 配置动态分配的IP地址的租约有效期限
expired day 3 hour 12 minute 30 second 30
# 配置DHCP客户端使用的域名后缀
domain-name suosuo
# 配置DHCP客户端使用的网关地址
gateway-list 172.16.7.77
# 配置DHCP客户端使用的DNS服务器地址
dns-list 14.14.14.14
# 配置DHCP客户端使用的TFTP服务器地址, 这里为 PXE 服务器地址
tftp-server ip-address 172.16.1.10
# 退回系统视图
quit
# 保存配置
save 

其他可选配置

# 查看DHCP配置情况
display dhcp server statistics
# 查看地址池已分配的地址
display dhcp server ip-in-use
# 查看地址池剩余没有分配的地址
display dhcp server free-ip
# 查看地址池中已经过期的地址
display dhcp server expried
# 查看交换机下地址池的配置
display dhcp server pool
# 开启DHCP服务
dhcp enable
# 创建DHCP地址池,并进入DHCP地址池视图
dhcp server ip-pool <pool-name>
# 查看DHCP服务器为客户端分配的IP地址
display dhcp server ip-in-use

# ########################### 其他 -----------------

dns-list 14.14.14.14
domain-name suosuo
expired day 3
# 屏蔽 IP  
forbidden-ip  xx.xx.xx.xx
# 配置 TFTP 服务器地址 
next-server 172.16.1.10
# 配置选项值
option 66 ip-address 172.16.1.10
option 67 ascii snponly.efi
# Mac 地址绑定
static-bind ip-address 172.16.17.17 mask 255.255.128.0 hardware-address 6805-cabd-9b8e
# tftp 设置 
tftp-server domain-name pxe
tftp-server ip-address 172.16.1.10

H3C -- 三层技术-IP业务配置指导 --- DHCP 配置

常用Option配置说明

选项代码 选项名称 对应的配置命令 option命令参数选择
3 Router Option gateway-list ip-address
6 Domain Name Server Option dns-list ip-address
15 Domain Name domain-name ascii
44 NetBIOS over TCP/IP Name Server Option nbns-list ip-address
46 NetBIOS over TCP/IP Node Type Option netbios-type hex
66 TFTP server name tftp-server ascii
67 Bootfile name bootfile-name ascii
43 Vendor Specific Information - hex
 # 常用系统架构类型及其对应代码
 Type   Architecture Name
            ----   -----------------
              0    Intel x86PC
              1    NEC/PC98
              2    EFI Itanium
              3    DEC Alpha
              4    Arc x86
              5    Intel Lean Client
              6    EFI IA32
              7    EFI BC
              8    EFI Xscale
              9    EFI x86-64
              
posted @ 2023-11-25 09:52  梭梭666  阅读(160)  评论(0编辑  收藏  举报
返回顶部