awm*_*635 2 dhcp debian kvm-virtualization
所以我正在为 KVM 虚拟机运行一个开发服务器。我有一个在主机节点上本地运行的 DHCP 服务器,配置如下:
/etc/dhcp/dhcpd.conf
ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
option rfc3442-classless-static-routes code 121 = array of integer 8;
option ms-classless-static-routes code 249 = array of integer 8;
subnet xxx.xxx.x.0 netmask 255.255.255.0 {
range xxx.xxx.x.2 xxx.xxx.x.127;
option routers xxx.xxx.x.1;
option broadcast-address xxx.xxx.x.255;
option domain-name-servers 8.8.8.8;
option netbios-name-servers 8.8.8.8;
default-lease-time 86400;
max-lease-time 86400;
option rfc3442-classless-static-routes 24, xxx, xxx, x, 0, 0, 0, 0, 0, 0, xxx, xxx, x, 1;
option ms-classless-static-routes 24, xxx, xxx, x, 0, 0, 0, 0, 0, 0, xxx, xxx, x, 1;
host 102 {hardware ethernet 4A:19:BD:DF:B0:07;fixed-address xxx.xxx.x.5;}
}
Run Code Online (Sandbox Code Playgroud)
/etc/default/isc-dhcp-server
# Defaults for isc-dhcp-server initscript
# sourced by /etc/init.d/isc-dhcp-server
# installed at /etc/default/isc-dhcp-server by the maintainer scripts
#
# This is a POSIX shell fragment
#
# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPD_CONF=/etc/dhcp/dhcpd.conf
# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPD_PID=/var/run/dhcpd.pid
# Additional options to start dhcpd with.
# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="vmbr0"
Run Code Online (Sandbox Code Playgroud)
作为参考,这是一个 debian 7 proxmox 服务器。
问题是,服务器通过 DHCP 分配了一个 IP,没有问题。它得到xxx.xxx.x.5,但是通过route -n查看时网关设置为0.0.0.0,因此网络不可达。
VM 网络配置文件的内容:
DEVICE=eth01
BOOTPROTO=dhcp
ONBOOT=yes
Run Code Online (Sandbox Code Playgroud)
此外,当它从 DHCP 获取信息时存在无效参数错误,它们可能是相关的。
客户端登录错误:
在信息有限的情况下很难远程排除故障。但我想试试。
首先,只是一个猜测。通常设备名称是eth0
or eth1
, not eth01
。这可能解释了“无效参数错误”。确保通过VMifconfig -a
或ip link
在 VM中处理正确的 NIC 。
另一个疑点是静态路由。它应该在数组中有 13 个项目,而不是你的 14 个。格式是<netmask>, <network-byte1>, <network-byte2>, <network-byte3>, <router-byte1>, <router-byte2>, <router-byte3>...
. 所以它应该是这样的24,192,168,1, 192,168,1,1, 0, 192,168,1,1
。看看这里。我猜错误的静态路由会覆盖默认网关。
如果这不是问题,您需要一个过程来调试。从您的 DHCP 配置中,我假设vmbr0
是一个 Linux Bridge,并且从那里创建了 VM。您需要通过检查virt net-list
和virt edit <vm>
在主机/管理程序上确认 VM 网络创建正确。您也可以使用virt-manager
. 确保 VM 只有一个 NIC,它从vmbr0
.
如果仍未修复,请进入 VM 并调试 DHCP 客户端。首先,killall dhclient
,然后dhclient eth0
使用dhcpdump -i eth0
或运行和监控流量tcpdump udp and port 67 or 68
。寻找网关选项。确保没有其他 DHCP 服务器挡在路上。(可能是 libvirt 的默认 NAT;或者可能是来自外部的另一个 DHCP 服务器,因为您有一个网桥)。您也可以dhcpdump/tcpdump
在拥有 DHCP 服务器的主机上运行。
我希望这有帮助。