带有单个 NIC 的 wifi AP

Mar*_*iae 10 networking wireless-networking wireless-access-point

我正在尝试将我的电脑无线网卡用作 AP,同时通过同一张网卡连接到我的 wifi 网络,但我遇到了问题。我试图实现的是相当于 Windows 的虚拟 Wi-fi 技术。原则上,这很简单:

service network-manager stop
iw dev wlan0 del
iw phy phy0 interface add new0 type station
service network-manager start
iw phy phy0 interface add new1 type __ap
hostapd -B /etc/hostapd.conf
Run Code Online (Sandbox Code Playgroud)

具有适合 hostapd 的配置:

cat /etc/hostapd/hostapd.conf 
interface=new1
driver=nl80211
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
ssid=XXXX
country_code=us
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
eap_server=0
wpa=2
wpa_passphrase=XXXX
wpa_pairwise=TKIP CCMP
rsn_pairwise=TKIP CCMP
Run Code Online (Sandbox Code Playgroud)

但是,驱动程序 nl80211 拒绝将虚拟 IF new1 置于 AP 模式。有趣的一点来了: iw list 的输出包含

Supported interface modes:
         * IBSS
         * managed
         * AP
         * AP/VLAN
         * monitor
software interface modes (can always be added):
         * AP/VLAN
         * monitor
valid interface combinations:
         * #{ managed } <= 1, #{ AP } <= 1,
           total <= 2, #channels <= 1, STA/AP BI must match
         * #{ managed } <= 2,
           total <= 2, #channels <= 1
Run Code Online (Sandbox Code Playgroud)

很明显我的 wifi 卡(iwlwifi 下的 Intel Centrino Advanced-N 6235 [8086:088e])支持 AP 模式(我已经测试过了),并且我已经将“有效接口组合”解释为我最多可以拥有此卡上同时有 1 个托管和 1 个 AP vif。但后来我注意到了一个看起来很神秘的约束,STA/AP BI 必须匹配。

有谁知道这意味着什么,以及这是否阻碍了我在卡上使用两个 vif 的尝试,一个在站中,另一个在 AP 模式下?干杯

Mar*_*iae 8

其实,神秘的句子

STA/AP BI must match
Run Code Online (Sandbox Code Playgroud)

似乎与我的设置不起作用无关。事实证明相反

 #channels <= 1
Run Code Online (Sandbox Code Playgroud)

是让它发挥作用的关键。我最终明白这意味着当我在同一个物理设备(我的英特尔迅驰,无论如何)上有两个 vif 时,我只能使用一个通道,一个在 AP 中,另一个在 Station 模式下。因此,我将 hostapd conf 文件中的频道切换到我尝试连接的频道,并且没有错误消息。

此时我配置了iptables,启动了dnsmasq,然后通过hostapd

echo 1 >/proc/sys/net/ipv4/ip_forward
iptables --table nat --append POSTROUTING --out-interface new0 -j MASQUERADE
iptables --append FORWARD --in-interface new1 -j ACCEPT
dnsmasq 
/usr/local/bin/hostapd /etc/hostapd/hostapd.conf
Run Code Online (Sandbox Code Playgroud)

然后我得到了它,一个 wifi 卡同时作为接入点和客户端工作到连接到互联网的网络。


dir*_*rkt 7

如果有人来这里确定“STA/AP BI 必须匹配”:

include/net/cfg80211.h特别是 中的内核源代码struct ieee80211_iface_combination

 * @beacon_int_infra_match: In this combination, the beacon intervals
 *  between infrastructure and AP types must match. This is required
 *  only in special cases.
Run Code Online (Sandbox Code Playgroud)

所以BI信标间隔,让它匹配应该不是一个大问题。