Hostapd 奇怪之处

Hostapd 奇怪之处

前段时间,我问了一个关于如何设置我的树莓派桥接网络连接的问题 -Linux 中的有线到无线桥接- 我得到的答案很有效。

现在,我不得不重新开始使用 Raspberry Pi,并使用所描述的设置。但它不会将 wlan0 设备纳入网桥中,如下所示:

 can't add wlan0 to br0: Operation not supported

但如果我跑

/usr/bin/hostapd /etc/hostapd/hostapd.conf

然后 wlan0 设备就成功添加到网桥了。有人能解释一下这里发生了什么吗,以及我如何完全自动将 wlan0 添加到网桥吗?

USB 设备正在使用 ath9k_htc 驱动程序。

按要求:/etc/network/interfaces 和 /etc/hostapd/hostapd.conf 基于上面提到的答案(虽然我已经转向 WPA 并停止使用 WEP),现在看起来像这样(按照下面的答案):

auto lo
iface lo inet loopback
iface eth0 inet static
address 0.0.0.0
iface wlan0 inet static
address 0.0.0.0

auto br0
iface br0 inet dhcp
    bridge_ports eth0
    pre-up ip link set eth0 down
    pre-up ip link set wlan0 down
    pre-up brctl addbr br0
    pre-up brctl addif br0 eth0
    pre-up ip addr flush dev eth0
    post-down ip link set eth0 down
    post-down ip link set wlan0 down
    post-down ip link set br0 down
    post-down brctl delif br0 eth0 wlan0
    post-down brctl delbr br0

interface=wlan0
bridge=br0
driver=nl80211
auth_algs=1
macaddr_acl=0
ignore_broadcast_ssid=0
logger_syslog=-1
logger_syslog_level=0
hw_mode=g
ssid=SSID
channel=11
wpa=2
wpa_passphrase=PASSPHRASE
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ctrl_interface=/var/run/hostapd
ieee80211n=1

答案1

就是这么简单:在开启 AP 模式后,hostapd将您的接口添加到指定的网桥。在 hostapd 运行之前,无法将您的接口添加到网桥中,因为您的接口仍处于默认管理模式。bridge=wlan0

不要告诉ifupdown(via /etc/network/interfaces) 添加wlan0到你的桥接器,而是让它hostapd来做:

bridge-ports eth0 # no wlan0 here.

哦,你的/etc/network/interfaces太臃肿了。你不需要摆弄 brctl。

auto lo
iface lo inet loopback

# If you don't need to configure eth0, don't add a stanza for eth0.

iface wlan0 inet manual
    # hostapd has ifupdown hooks in /etc/network/if-*.d/, just like bridge-utils
    hostapd /etc/hostapd/hostapd.conf

auto br0
iface br0 inet dhcp
    # This will run dhcp on eth0, then proceed to create an AP.

    # bridge-ports already handles creating the bridge, adding the ports and
    # upping them (with ifconfig and ioctls :-( )
    bridge_ports eth0

    # After the bridge is set up with only eth0, up the interface using
    # the previously defined stanza.  hostapd will add wlan0 to the bridge
    # using the modern rtnetlink API.
    post-up ifup wlan0

    # When preparing to down, destroy the AP (and remove it from the bridge)
    # before the bridge is downed.
    pre-down ifdown wlan0

答案2

通常这些接口无法桥接,因为 WiFi 链路层报头没有单独的源(或目标)地址字段 - 假定它始终与传输(或接收)设备的地址相同。这意味着 WiFi 设备无法充当桥接器。

我猜 hostapd 将接口切换到“4addr”模式,其中标头包含所有四个地址。如果您已iw安装,请运行:

iw dev wlan0 set 4addr on

相关内容