Ubuntu的DHCP服务器“未configuration为侦听任何接口”

我在这一个智慧结束, 我已经尝试了几个小时才能使这个工作,但我很难过。 希望你们中的一个人能帮忙。 🙂

我试图让Ubuntu的dhcp3服务器上工作。 它的安装,并正确设置运行在rc2,3,4,5.d运行级别。 在启动时,其init.d脚本确实得到运行,并且在syslog中,我得到以下内容:

Oct 18 20:40:37 jez-ubuntu dhcpd: Internet Systems Consortium DHCP Server V3.1.1 Oct 18 20:40:37 jez-ubuntu dhcpd: Copyright 2004-2008 Internet Systems Consortium. Oct 18 20:40:37 jez-ubuntu dhcpd: All rights reserved. Oct 18 20:40:37 jez-ubuntu dhcpd: For info, please visit http://www.isc.org/sw/dhcp/ Oct 18 20:40:37 jez-ubuntu dhcpd: Wrote 2 leases to leases file. Oct 18 20:40:37 jez-ubuntu dhcpd: Oct 18 20:40:37 jez-ubuntu dhcpd: No subnet declaration for eth1 (0.0.0.0). Oct 18 20:40:37 jez-ubuntu dhcpd: ** Ignoring requests on eth1. If this is not what Oct 18 20:40:37 jez-ubuntu dhcpd: you want, please write a subnet declaration Oct 18 20:40:37 jez-ubuntu dhcpd: in your dhcpd.conf file for the network segment Oct 18 20:40:37 jez-ubuntu dhcpd: to which interface eth1 is attached. ** Oct 18 20:40:37 jez-ubuntu dhcpd: Oct 18 20:40:37 jez-ubuntu dhcpd: Oct 18 20:40:37 jez-ubuntu dhcpd: Not configured to listen on any interfaces! Oct 18 20:40:39 jez-ubuntu NetworkManager: <info> (eth0): device state change: 1 -> 2 Oct 18 20:40:39 jez-ubuntu NetworkManager: <info> (eth0): bringing up device. Oct 18 20:40:39 jez-ubuntu NetworkManager: <info> (eth0): preparing device. [...] 

正如你所看到的,dhcpd似乎 NetworkManager 之前运行,这是我的eth0(internet)和eth1(家庭networking)接口的设置。 你会认为这与rcX.d符号链接名称有关,并且dhcpd被命名为在NetworkManager之前启动。 不是这样。 我的dhcp3-server符号链接被命名为“S99dhcp3-server”,networkingpipe理器符号链接命名为“S50NetworkManager”,所以它应该在dhcp服务器之前启动。 另外,如果我真的从命令行'/etc/init.d/dhcp3-server'运行(以root身份),服务器运行正常! 它只在启动失败!

为什么说它没有configuration为在任何接口上侦听? 我的所有启动脚本运行之后 ,networkingpipe理器是否不启用接口eth0和eth1? 如果是这样的话,有什么用呢? 当然,其他脚本将需要这些接口在启动时可用? 这是我的/etc/dhcp3/dhcpd.conf文件:

 subnet 192.168.0.0 netmask 255.255.255.0 { option routers 192.168.0.1; option subnet-mask 255.255.255.0; option domain-name-servers 87.194.0.51; option ip-forwarding off; range dynamic-bootp 192.168.0.100 192.168.0.254; default-lease-time 21600; max-lease-time 43200; } 

和我的/ etc / default / dhcp3-server文件:

 # Defaults for dhcp initscript # sourced by /etc/init.d/dhcp # installed at /etc/default/dhcp3-server by the maintainer scripts # # This is a POSIX shell fragment # # On what interfaces should the DHCP server (dhcpd) serve DHCP requests? # Separate multiple interfaces with spaces, eg "eth0 eth1". INTERFACES="eth1" 

据我所知,这些都是正确的。 有任何想法吗?

你可以像这样修改你的/ etc / network / interfaces:

 iface eth1 inet static address 192.168.50.1 netmask 255.255.255.0 up service dhcp3-server restart 

所以dhcp3-server将在networking接口(eth1)真正启动后重新启动。

好的,我想我已经解决了这个问题。 这是Linuxnetworkingpipe理员的一个错误。

看,networkingpipe理员作为引导过程的一部分(这将是'S50NetworkManager'符号链接)运行,并启动您的以太网接口。 但是,它是asynchronous执行的。 这意味着networkingpipe理员立即返回,暗示其后的脚本“OK – networking已经build立”。 其实它没有,而且networkingpipe理员正在后台坐着,正在build立networking。 同时,启动脚本在运行之后,假定networking接口可用,这是一种竞争状态,取决于networkingpipe理员是否已经设置好了。

这是一个可怕的情况,我惊讶的一个错误还没有被修复。 避开networkingpipe理器的一种方法是通过编辑/ etc / network / interfaces来设置你的接口。 但是,我没有做这个工作,而是尝试了这个bug报告中提出的丑恶的黑客攻击: https : //bugzilla.redhat.com/show_bug.cgi?id = 486372

我在dhcp3-server的init.d脚本的启动函数的开头添加了一个5秒的延迟('sleep 5'),这给networkingpipe理员足够的时间来build立networking接口(尽pipe当然还没有保证) – 它的工作。 现在,dhcpd启动成功。

如bugzilla.redhat.com上的错误#486372和#447442所述,这可能是networkingpipe理器(应阻塞,直到其有线networking接口可用)或dhcpd(应更新为等待networking接口变得可用,而不是只是崩溃)。 虽然这绝对是一个错误。

我想这个问题的原因是不同的。

我试图使用DHCP来configuration服务器将监听的接口。 AKA我的局域网已经连接到服务器的eth0端口,我试图获得DHCP来configurationeth0。 不工作,显然; DHCP监听接口必须静态configuration(/ etc / network / interfaces)。

如我错了请纠正我。 我不认为应该静态configurationDHCP侦听设备。

我有一个类似的问题,但在我的情况下,networking接口(eth0)从来没有起来 – 它没有正确初始化。 这是间歇性地发生的,大约有20%的时间。 放慢延迟,或按照其他答案中的build议重新启动DHCP服务器并不能解决我的问题。

在我的情况下,解决scheme是重新启动networking服务,然后通过类似以下脚本(片段,不可运行开始到结束)的dhcp服务器…

 # Check if the networking is running ... # look for "192.168.0.202" within this command's output ifconfig # If the networking is not running, then restart the network interfaces via this command: sudo service networking restart # Check if the DHCP service is running ... # look for "dhcpd" within this command's output ps -C dhcpd # If the DHCP service is not running, then restart the DHCP service via this command: sudo service isc-dhcp-server restart 

我刚刚在Ubuntu上遇到这个问题,我修正了一点点不同。 我正在使用isc-dhcp-server服务,但它试图在所需的接口启动之前启动,崩溃,然后耗尽重新生成的限制。 我在/ etc / init中的upstartconfiguration文件中在线启动进行了小小的编辑:

 start on runlevel [2345] and net-device-up IFACE=eth0 

这样,服务将不会尝试启动,直到所需的接口启动。

以下是validation您是否有主题错误的要点列表:

  1. isc-dhcpd-server正在看里面:

在/ etc /默认/ ISC-DHCP服务器

文件来识别接口名称,ONLY将为dynamic地址提供服务(不再是系统的所有接口,而仅在此文件中提到)。 确保你至less定义了1个接口(并且不需要eth0 ):

 INTERFACES="enp0s31f6" 
  1. isc-dhcpd-server将不会接受上面提到的接口(在我的例子中是enp0s31f6 ),如果你没有给它分配静态IP地址,它将为它提供dynamic分配的IP地址。 地址分配完成于:

的/ etc /networking/接口

通过提供以下设置块:

 # Define the static address and set it to serve with DHCP. Link it to the existing interface. iface enp0s31f6 inet static address 10.20.0.1 netmask 255.255.255.240 #below are optional settings #gateway 192.168.100.251 #dns-nameservers 8.8.8.8 

在为所选接口configuration静态地址之后,请确保它是可用的,使用以下命令的帮助来分配向上和定义的地址(通过重新启动networking):

 sudo service networking restart 

否则isc-dhcpd-server会拒绝运行

  1. isc-dhcpd-server将只提供在其中定义了dynamic释放子networking的接口

的/etc/dhcp/dhcpd.conf

通过为接口地址提供单独的块定义(至less一个)(您select的接口静态IP必须与configuration的子网匹配):

 subnet 10.20.0.0 netmask 255.255.255.0 { range 10.20.0.10 10.20.0.100; option subnet-mask 255.255.255.0; option routers 10.20.0.1; option broadcast-address 10.20.0.255; option domain-name-servers 192.168.100.254, 8.8.8.8; } 

通过仅符合所有3个规则,您将获得在Ubuntu上运行的DHCP服务(已在16.04版上parsing和validation)

最后现在是执行命令启动isc-dhcpd-server的时候了:

 sudo service isc-dhcp-server start 

要validationconfiguration成功,请使用另一个命令:

 sudo service isc-dhcp-server status 

并查看以下几行以确认成功:

 ● isc-dhcp-server.service - ISC DHCP IPv4 server Active: active (running) since Wed 2017-05-10 15:28:13 CEST; 29min ago May 10 15:28:13 system-P50 dhcpd[26869]: Listening on LPF/enp0s31f6/0a:3e:47:75:17:a8/10.20.0.0/24 

我已经打了一天这个错误信息。

 No subnet declaration for eth1 (no IPv4 addresses). 

最后在我的情况错误来自dhcp服务脚本通过启动它与systemctl命令。

 #cat /etc/systemd/system/dhcpd.service [Service] Type=notify ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid **eth1** 

只要修改ethXX号码

刷新

 #systemctl daemon-reload 

重新启动它:

 #systemctl start dhcpd