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

相关内容