![根据不同的范围在 DHCP 配置中定义多个文件名选项](https://linux22.com/image/766671/%E6%A0%B9%E6%8D%AE%E4%B8%8D%E5%90%8C%E7%9A%84%E8%8C%83%E5%9B%B4%E5%9C%A8%20DHCP%20%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%AE%9A%E4%B9%89%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%E5%90%8D%E9%80%89%E9%A1%B9.png)
介绍
我正在尝试使用 centos 盒子来实现 DHCP 和 TFTP 功能,用于 iPXE 启动。我为 DHCP 配置了一个子网,但它有多个范围,每个范围都有不同的 iPXE 启动 URL。
问题
问题是,一旦主机启动到 iPXE,它只会从最底部的范围获取 URL,而不管 DHCP IP 是从哪个范围分配的https://10.10.2.12:6501/vmw/rbd/tramp
例如,我的主机10.10.2.212
应该获取此 iPXE URL https://10.10.2.12:6501/vmw/rbd/tramp
,而我的主机10.10.2.52
应该获取此IPhttps://10.10.2.13:6501/vmw/rbd/tramp
但它们都是从此 URL 进行 iPXE 启动https://10.10.2.12:6501/vmw/rbd/tramp
我也尝试过定义池,但是池里面的文件名选项不起作用。
预期结果
我的主机10.10.2.212
应该获得这个 iPXE URLhttps://10.10.2.12:6501/vmw/rbd/tramp
并且我的主机具有 IP10.10.2.52
应该获得这个 iPXE URLhttps://10.10.2.13:6501/vmw/rbd/tramp
dhcpd.conf 文件
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
# Domain name
option domain-name "abc.xyz";
# DNS server ips
option domain-name-servers 8.8.8.8;
# Default lease time
default-lease-time 2592000;
# Max lease time
max-lease-time 5184000;
# Log method
log-facility local7;
authoritative;
# Subnet and ip ranges
# ESX ESXi_Mgmt subnet
subnet 10.10.2.0 netmask 255.255.254.0 {
range 10.10.2.52 10.10.2.211;
if ((exists user-class) and (option user-class = "iPXE")) {
filename "https://10.10.2.13:6501/vmw/rbd/tramp";
} else {
filename "undionly.kpxe";
}
range 10.10.2.212 10.10.3.117;
if ((exists user-class) and (option user-class = "iPXE")) {
filename "https://10.10.2.12:6501/vmw/rbd/tramp";
} else {
filename "undionly.kpxe";
}
option subnet-mask 255.255.254.0;
option broadcast-address 10.121.3.255;
option routers 10.121.2.1;
}
# Include reservations
include "/etc/dhcp/reservations.d/domain1.p.opensource";
include "/etc/dhcp/reservations.d/domain1.np.opensource";
答案1
您的 2 个范围在同一范围内将它们添加到单独的池中以获得单独的配置:
filename "undionly.kpxe";
pool {
range 10.10.2.52 10.10.2.211;
if ((exists user-class) and (option user-class = "iPXE")) {
filename "https://10.10.2.13:6501/vmw/rbd/tramp";
}
}
pool {
range 10.10.2.212 10.10.3.117;
if ((exists user-class) and (option user-class = "iPXE")) {
filename "https://10.10.2.12:6501/vmw/rbd/tramp";
}
}
我建议将 if 逻辑更改为使用 iPXE 选项上的功能检测而不是用户类,请参阅https://gist.github.com/robinsmidsrod/4008017