我目前已使用 Ubuntu 提供的说明建立了 10 个无盘服务器。启动服务器后,我想为它们分别分配新 IP。由于服务器根文件是通过 NFS 从单个源挂载的,因此 /etc/network 中的接口文件是相同的。
我的问题是如何配置接口文件,以便当不同的服务器读取同一个文件时,为它们分配不同的IP?
非常感谢
答案1
您不会通过共享/etc/network/interfaces
文件来执行此操作。
为了实现这一点,请使用dnsmasq
的DHCP
服务器。来自man dnsmasq
:
The dnsmasq DHCP server supports static address assignments and multiple networks. It automatically sends a sensible default set of DHCP options, and can be configured to send any desired
set of DHCP options, including vendor-encapsulated options. It includes a secure, read-only, TFTP server to allow net/PXE boot of DHCP hosts and also supports BOOTP. The PXE support is
full featured, and includes a proxy mode which supplies PXE information to clients whilst DHCP address allocation is done by another server.
The dnsmasq DHCPv6 server provides the same set of features as the DHCPv4 server, and in addition, it includes router advertisements and a neat feature which allows nameing for clients
which use DHCPv4 and stateless autoconfiguration only for IPv6 configuration. There is support for doing address allocation (both DHCPv6 and RA) from subnets which are dynamically dele‐
gated via DHCPv6 prefix delegation.
通过仔细阅读man dnsmasq
,您将看到如何将特定的 IP 地址分配给特定的 48 位MAC
地址(HWaddr
输出字段ifconfig
)。
答案2
您需要网络DHCP
中lan
或路由器上的服务器来分配ip parm
给您的服务器。
您可以使用Ubuntu
服务器执行此操作。
要dhcp
在服务器上安装服务,请运行以下命令
sudo apt install isc-dhcp-server
根据您的 ip/mac 地址更改配置
sudo nano /etc/dhcp3/dhcpd.conf
编辑1dhcp
- 添加了不同卡上的第二个池的配置
配置示例
subnet 192.168.100.0 netmask 255.255.255.0 {
interface eth0;
option domain-name "domain.net";
option broadcast-address 192.168.100.255;
option routers 192.168.100.1;
option domain-name-servers 192.168.100.1, 8.8.8.8;
# Define the scopes for this DHCP pool
pool {
range 192.168.100.2 192.168.100.200;
# static reserve = 192.168.100.201 - 192.168.100.254
}
host static-custid {
hardware ethernet 00:01:02:03:04:05;
fixed-address 192.168.100.205;
}
host static-custid {
hardware ethernet 00:01:02:03:04:06;
fixed address 192.168.100.206;
}
}
subnet 10.0.0.0 netmask 255.255.255.0 {
interface eth2;
default-lease-time 6000;
max-lease-time 7200;
range 10.0.0.100 10.0.0.200;
option subnet-mask 255.255.255.0;
option routers 10.0.0.254;
option broadcast-address 10.0.0.255;
}
注意:您的dhcp
池来自192.168.100.2 192.168.100.200
,您的网络掩码是255.255.255.0
您的路由器上的地址192.168.100.1
。DHCP 服务器将始终为主机分配具有 mac 地址的00:01:02:03:04:05
ip 192.168.100.205
,具有 mac 00:01:02:03:04:06
ip 192.168.100.206
。但是,如果主机具有 mac,00:01:02:03:04:08
服务器将从池中分配下一个空闲 ip 地址。
更改配置后,重新启动 dhcp 服务器。