最近在调试无线软AP软件 hostapd 时遇到个错误,总是无法启动服务。
调试输出如下:
[root@server ~]# /usr/sbin/hostapd /etc/hostapd/hostapd.conf -d ……省略…… Could not set interface wlp2s0 flags (UP): Operation not possible due to RF-kill nl80211: Failed to set interface up after switching mode ……省略……
那 RF-kill 是什么呢?
这里是 rfkill 相关介绍:
rfkill - RF kill switch support (翻译)
好吧,先搜索 rfkill 相关的软件包。
yum search rfkill
[root@server ~]# yum search rfkill 已加载插件:fastestmirror, remove-with-leaves Loading mirror speeds from cached hostfile ============================ N/S matched: fkill ============================ rfkill.x86_64 : A tool for enabling and disabling wireless devices
这里也可以看出 rfkill 是一个启用/禁用无线设备的工具,也就是一个无线设备软开关。
接下来安装 rfkill 软件包。
yum install rfkill
看看 rfkill 有哪些文件。
rpm -ql rfkill
[root@server ~]# rpm -ql rfkill /sbin/rfkill /usr/share/doc/rfkill /usr/share/doc/rfkill/COPYING /usr/share/doc/rfkill/README /usr/share/man/man8/rfkill.8.gz
从输出来看看来就主要一个可执行文件 rfkill。
man rfkill 看看 rfkill 的用法。
man 8 rfkill
[root@server ~]# man 8 rfkill ……简要输出…… rfkill command COMMANDS help Show rfkill's built-in help text. event Listen for rfkill events and display them on stdout. list [type] #查看设备状态 List the current state of all available rfkill-using devices, or just all of the given type. block index|type #关闭开关操作 Disable the device corresponding to the given index. type is one of "all", "wifi", "wlan", "bluetooth", "uwb", "ultrawideband", "wimax", "wwan", "gps", "fm" or "nfc". unblock index|type #开启开关操作 Enable the device corresponding to the given index. If the device is hard-blocked, e.g. via a hardware switch, it will remain unavailable though it is now soft-unblocked.
那么接下来就看看有没有无线设备被关掉。
rfkill list
[root@server ~]# rfkill list 0: phy0: Wireless LAN Soft blocked: yes #开关开启,无线网卡无法使用 Hard blocked: no
解锁操作
rfkill unblock wlan
[root@server ~]# rfkill unblock wlan
再次查看
rfkill list
[root@server ~]# rfkill list 0: phy0: Wireless LAN Soft blocked: no #此时已关闭,可以使用无线网卡 Hard blocked: no
再次运行调试模式
/usr/sbin/hostapd /etc/hostapd/hostapd.conf -d
OK一切正常,那么就可以结束调试以正常模式启动服务了。