服务 isc-dhcp-server 启动失败

服务 isc-dhcp-server 启动失败

我目前正在做一个项目,用我的 RaspberryPi 制作一个高度安全的路由器,以便在网络上匿名导航。然而,我无法正确配置守护进程来完成与新服务器的 wifi 互联网连接:

确实,当我这样做时:

:~ $ sudo service isc-dhcp-server start

我得到:

Job for isc-dhcp-server.service failed. See 'systemctl status isc-dhcp-server.service' and 'journalctl -xn' for details.

这是我的/etc/dhcp/dhcpd.conf设置

authoritative;

#added

subnet 192.168.42.0 netmask 255.255.255.0{
        range 192.168.42.10 192.168.42.50;
        option broadcast-adress 192.168.42.255;
        option routers 192.168.42.1;
        default-lease-time 600;
        max-lease-time 7200;
        option domain-name "local";
        option domain-name-servers 8.8.8.8, 8.8.4.4;
}

以下是我的/etc/network/interfaces设置:

source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback
iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet static
adress 192.168.42.1
netmask 255.255.255.0

iface wlan0 inet dhcp

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet static
adress 192.168.42.1
netmask 255.255.255.0

iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

up iptables-restore < /etc/iptables.ipv4.nat

我的 RaspberryPi 已有线连接,但有一个 wifi 适配器

这里是systemctl status isc-dhcp-server.service

:~ $ systemctl status isc-dhcp-server.service
● isc-dhcp-server.service - LSB: DHCP server
   Loaded: loaded (/etc/init.d/isc-dhcp-server)
   Active: failed (Result: exit-code) since Tue 2016-06-07 00:13:45 CEST; 53s ago
  Process: 18098 ExecStart=/etc/init.d/isc-dhcp-server start (code=exited, status=1/FAILURE)

有些部分是用可怕的红色写的......

这是journalctl

-- Logs begin at Mon 2016-06-06 21:17:01 CEST, end at Tue 2016-06-07 00:18:32 CEST. --
Jun 07 00:13:45 raspberrypi isc-dhcp-server[18098]: than a configuration issue please read the section on submitting
Jun 07 00:13:45 raspberrypi isc-dhcp-server[18098]: bugs on either our web page at www.isc.org or in the README file
Jun 07 00:13:45 raspberrypi isc-dhcp-server[18098]: before submitting a bug.  These pages explain the proper
Jun 07 00:13:45 raspberrypi isc-dhcp-server[18098]: process and the information we find helpful for debugging..
Jun 07 00:13:45 raspberrypi isc-dhcp-server[18098]: exiting.
Jun 07 00:17:01 raspberrypi CRON[18118]: pam_unix(cron:session): session opened for user root by (uid=0)
Jun 07 00:17:01 raspberrypi CRON[18122]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jun 07 00:17:01 raspberrypi CRON[18118]: pam_unix(cron:session): session closed for user root
Jun 07 00:18:32 raspberrypi sudo[18139]: pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/journalctl -xn
Jun 07 00:18:32 raspberrypi sudo[18139]: pam_unix(sudo:session): session opened for user root by pi(uid=0)

答案1

有以下几件事:

最明显的一个是在这里用两个“d”写地址:

subnet 192.168.42.0 netmask 255.255.255.0{
        range 192.168.42.10 192.168.42.50;
        option broadcast-adress 192.168.42.255;
        option routers 192.168.42.1;
        default-lease-time 600;
        max-lease-time 7200;
        option domain-name "local";
        option domain-name-servers 8.8.8.8, 8.8.4.4;
}

第二个是通过运行以下命令启动无线网络:

sudo ifup wlan0

我本可以开始service isc-dhcp-server做这件事,多亏了这个 raspberrypihq 教程将把 RPi 变成路由器

但是,我现在遇到了一些问题sudo update-rc.d isc-dhcpd-server enable。任何帮助都会受到热烈欢迎!

答案2

如果它对任何人都有帮助,我刚刚在 Pi Zero W 上的 DietPi(Debian Buster)上遇到了这个令人恼火的问题,并且已经解决了问题。

isc-dhcp-server 非常出色,但确实存在这个怪癖,正如上面的原始询问者所指出的那样。我已经找到了问题所在 - 这不是错误 - 以下是原因的详细信息:

isc-dhcp-server refuses (throws an error) if it cannot see an UP ethernet network subnet at launch time; it DOESN'T (contrary to some commentators) require an actual connection TO the ethernet port to which it is associated.

When developing a WiFi Hotspot device, its normally a case of using hostapd as the AP server function (which re-configures the WiFi hardware to switch to AP mode) and alongside hostapd, you need a dhcp server like isc-dhcp-server to provide the IP address leasing service.

SO: normally the start point, is a WiFi device which at boot, was configured as a CLIENT device, but needs to be switched to HOST mode to act as hotspot. So an early step is to set wlan0 (or whatever) DOWN, prior to launching hostapd.

但是这种情况是 isc-dhcp-server 不喜欢的情况之一:如果您尝试在 hostapd 之前启动它,它将会失败,并抱怨没有子网可供它监听。

So you may innocently then try, adding a new IP address (for the host) to your wlan0 (or equiv) and re-trying: THAT WON'T WORK EITHER, because although you now have a new IP attached to the Ethernet port, you will also find you cannot set it 'UP' (ip link set wlan0 up will FAIL). This is because the port is 'tainted' by the still-active stale address and the wpa-supplicant process which was using it.

LONG STORY SHORT: you need to kill wpa-supplicant, to "free" the old address / FLUSH the ip settings for the port / THEN add the new IP address for host ; EVEN THEN, you'll find isc-dhcp-server STILL won't start, because you can't set the interface up - yet. Finally - run hostapd now, before isc, and IT will (in reconfiguring the chipset) also SET the wlan0 interface, to UP. So now - finally - you CAN run isc-dhcp-server, and it will start cleanly, and your hotspot will be up.

我花了大约五个小时,希望这能为大家节省一些时间。我的总结:

对 ISC-DHCP-SERVER 和 HOSTAPD 进行排序:解决方案

您必须遵循以下顺序:

KILL the wpa-supplicant process (that's sustaining the client conn) this way:

kill -2 $( cat /run/wpa_supplicant.wlan0.pid )

sleep 1

kill -9 $( cat /run/wpa_supplicant.wlan0.pid )

FLUSH the WLAN IP setup, using:

ip addr flush dev wlan0

ADD the new host IP ADDRESS, using:

ip addr add 10.1.1.1/24 dev wlan0

START hostapd, which will also put wlan0 UP:

/usr/sbin/hostapd /etc/hostapd/hostapd.conf &

START isc-dhcp-server ( WLAN is up, as host now ):

sudo service isc-dhcp-server restart

然后,接入点应该处于启动状态并准备好接受客户端。

当然,这些是我的地址/可以根据您的需要进行编辑。

另外两个提示:配置文件 hostapd.conf 和 dhcp.conf 也会让你抓狂:-这里有工作示例。重要提示:不要为 hostapd.conf 中的“drivername”烦恼:它不是必需的。“注释掉”就可以了:

hostapd.conf

接口=wlan0

#驱动程序=brcmfmac

ssid=这是我的 AP

国家代码=美国

硬件模式=g

通道=6

macaddr_acl=0

身份验证=1

忽略广播 SSID = 0

wpa=2

wpa_密码=12345678

wpa_key_mgmt=WPA-PSK

wpa_pairwise=CCMP

wpa_group_rekey=86400

IEEE80211n=1

wme_enabled=1

dhcpd配置文件

注释掉两个模板的“选项域..”行..然后在底部添加以下内容:

子网 10.1.1.0 网络掩码 255.255.255.0 { 范围 10.1.1.100 10.1.1.109; 选项广播地址 10.1.1.255; 选项路由器 10.1.1.1; 默认租用时间 600; 最大租用时间 7200; 选项域名“mynetwork.org”; 选项域名服务器 8.8.8.8, 8.8.4.4; }

虽然这项工作在 Pi 上进行,但它是在纯 Debian 的 DietPi 上进行的,因此同样的建议应该适用于许多 Linux,包括多种风格的 Ububtus。

祝大家好运

相关内容