如何在 dhcpd 中通过 MAC 地址分配 IP

ada*_*lar 11 linux dhcpd

如何使用 dhcpd 分配特定于 mac 地址的 IP 地址?

到目前为止我已经尝试过

host blah { hardware ethernet <mac address>; fixed-address <ip address>;}
Run Code Online (Sandbox Code Playgroud)

在我的 dhcpd.conf 中。但是在重新启动 dhcpd 和具有相关 mac 地址的机器后,我再次获得了一个随机 IP。

sau*_*us2 8

这是非常好的格式——我用的完全一样。只有我在行尾附加了评论(另外)。这是工作的摘录dhcpd.conf

host wrt45gl-etika  { hardware ethernet 00:21:29:a1:c3:a1; fixed-address ---.219.43.135; } # MSIE routeris WRT54GL
Run Code Online (Sandbox Code Playgroud)

正如@Christoph 所提到的,可能会声明全局选项(或使用的服务默认值),这可能会影响分配 IP 的方式/可能会覆盖它。

在从dhcp3-server (v3)迁移到isc-dhcp-server (v4) 时,我需要添加一些强制选项并重写一些声明。但是配置文件的结构仍然很简单:

#
# Sample configuration file for ISC dhcpd for Debian
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)

ddns-update-style none;

# option definitions common to all supported networks...

option domain-name "mf.vu.---";
option domain-name-servers ---.219.80.11, ---.219.80.2, ---.171.22.22;

default-lease-time 2678400;
max-lease-time 2678400;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.

authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).

log-facility local7;


# The subnet that shares this physical network

shared-network TOTAL_MF {
 server-name "letta.mf.vu.--";

 subnet ---.219.43.128 netmask 255.255.255.192 {
  option routers ---.219.43.190;
  option broadcast-address ---.219.43.191;

  group {
    host wrt45gl-etika  { hardware ethernet 00:21:29:a1:c3:a1; fixed-address ---.219.43.135; } # MSIE routeris WRT54GL
    # ...
    host saulute        { hardware ethernet 00:21:28:10:f4:16; fixed-address ---.219.43.189;  } # Virtual Qemu PC NIC
  }
 }

 subnet 172.16.43.128 netmask 255.255.255.192 {
  option routers 172.16.43.129;
  option broadcast-address 172.16.43.191;

  group{
    host ligo           { hardware ethernet 08:00:20:7A:E2:70; fixed-address 172.16.43.179;   } #a225 ligo
    # ...
    host vumfsa2        { hardware ethernet 00:80:48:8d:12:f0; fixed-address 172.16.43.140;   } # 118
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

在那里我使用了 no pool,没有range声明。只有两个子网声明(一个后跟另一个)。

在那里,我没有分配给我的主机的随机 IP,这些 IP 在这里声明(与 MAC 绑定)。