dnsmasq 需要在 BeagleBone Black (Debian 8.5) 上重新啟動網路系統

dnsmasq 需要在 BeagleBone Black (Debian 8.5) 上重新啟動網路系統

我目前正在嘗試將運行 debian 8.5 的 BeagleBone Black 配置為 WiFi 接入點。使用的程序是hostapddnsmasq。我已經取得了巨大的進步,原則上接入點按預期工作(我可以連接到它並訪問 Lighty 託管的網站),但有一點問題。重新啟動後我無法連接,因為dnsmasq抱怨 wlan0 沒有地址。

摘自/var/log/syslog

Jun 24 12:01:03 arm dnsmasq[487]: warning: interface wlan0 does not currently exist
Jun 24 12:01:03 arm dnsmasq-dhcp[487]: DHCP, IP range 192.168.3.20 -- 192.168.3.200, lease time infinite
Jun 24 12:01:53 arm dnsmasq-dhcp[487]: DHCP packet received on wlan0 which has no address

當我重新啟動網路系統時,/etc/init.d/networking restart一切運作正常,如上所述。重新啟動dnsmasq或致電ifup wlan0都無法解決該問題。根據日誌,我猜測存在某種計時問題(即 USB WiFi 棒在 dnsmasq 啟動後被識別,等等),但我真的不知道如何克服。我已經添加了allow-hotplug wlan0/etc/network/interfaces但它沒有改變任何東西。

除了 /etc/network/interfaces 之外:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
    address 192.168.3.1

我的/etc/dnsmasq.conf很基本:

# Disable DNS
port=0
interface=wlan0
no-dhcp-interface=eth0
dhcp-range=interface:wlan0,192.168.3.20,192.168.3.200,infinite

編輯:

跑步ifconfig wlan0 192.168.3.1也有效。

答案1

您可以建立一個 if-up 腳本來檢查 dnsmasq 是否必須重新啟動。

/etc/network/if-up.d/dnsmasq:

#!/bin/sh
[ "$IFACE" != "lo" ] || exit 0

restartDnsMasq() {
    if [ -d /run/systemd/system ]; then
        systemctl reload --no-block dnsmasq >/dev/null 2>&1 || true
    else
        invoke-rc.d dnsmasq restart >/dev/null 2>&1 || true
    fi
}

# Find out if dnsmasq is configured to run on a single interface
interface=$(cat /etc/dnsmasq.conf | grep interface | awk -F '=' '{print $2}')
if  [ "x${interface}" = "x" ]; then
    # all interfaces
    logger DnsMasq not configured for any particular interface, restarting because $IFACE came up.
    restartDnsMasq
else
    if [ "${interface}" = "$IFACE" ]; then
        # The interface that dnsmasq is running on is being brought up
        logger DnsMasq configured for interface ${interface}, restarting because $IFACE came up.
        restartDnsMasq
    else
        logger DnsMasq configured for interface ${interface}, not restarting because $IFACE came up.
    fi 
fi

相關內容