%20%E4%B8%8A%E9%87%8D%E6%96%B0%E5%95%9F%E5%8B%95%E7%B6%B2%E8%B7%AF%E7%B3%BB%E7%B5%B1.png)
我目前正在嘗試將運行 debian 8.5 的 BeagleBone Black 配置為 WiFi 接入點。使用的程序是hostapd
和dnsmasq
。我已經取得了巨大的進步,原則上接入點按預期工作(我可以連接到它並訪問 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