Hostapd陌生感

adr*_*min 5 networking wireless-networking bridge raspberry-pi

不久前,我问了一个关于使用桥接网络连接设置我的 Raspberry Pi 的问题 - Linux 中的有线到无线网桥- 我得到了很好的答案。

现在,我不得不重新开始使用 Raspberry Pi 并使用所描述的设置。但它不会在网桥中包含 wlan0 设备,说明:

 can't add wlan0 to br0: Operation not supported
Run Code Online (Sandbox Code Playgroud)

但如果我跑

/usr/bin/hostapd /etc/hostapd/hostapd.conf
Run Code Online (Sandbox Code Playgroud)

然后 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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

Bat*_*hyX 6

就是这么简单:在它进入 AP 模式后,hostapd将您的接口添加到指定的网桥。在 hostapd 运行之前将您的接口添加到网桥中是不可能的,因为您的接口仍处于默认托管模式。bridge=wlan0

不要告诉ifupdown(via /etc/network/interfaces) 添加wlan0到您的网桥,hostapd而是让我们这样做:

bridge-ports eth0 # no wlan0 here.
Run Code Online (Sandbox Code Playgroud)

哦,你/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
Run Code Online (Sandbox Code Playgroud)