工作在AP模式就需要有线网卡和无线网卡进行桥接,这就要求我们首先要建立一个桥接接口。 使用 nmcli 命令来配置:
首先使用 ip link 命令就可以看到哪些本机已经识别是网卡名称:
ip link[root@server ~]# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: p2p1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
link/ether 00:14:78:66:2e:a7 brd ff:ff:ff:ff:ff:ff
3: wlp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 90:94:e4:78:49:b5 brd ff:ff:ff:ff:ff:ff 使用 nmcli 建立一个桥接接口 br0 并设置开机自动连接,“br0”可以自由设定,只要保证上下配置一致就可以。为了方便通用,一般桥接接口都是用这种方式命名。
其他命令方式进行配置:
虽然还有其他方式建立网桥的命令,但是如果是在 CentOS 7 下面,最简单的还是使用 nmcli 命令,因为 CentOS 7 默认提供 NeteorkManager 这个软件,使用 nmcli 命令配置好连接后一直有效。但 nmcli 也并不是万能的,前面有提到过,我目前遇到了两个问题:1. nmcli 不支持将无线网卡加入到网桥;2. 到目前为止 nmcli 不支持设置无线网卡静态IP地址(这个在 hostapd 配置路由模式会遇到)。
关于 CentOS 7 桥接网络配置可以看看《<<<<<<这篇文章>>>>>>>》。 启动 hostapd 服务
到此我们已经配置了网桥,网桥将自动从路由器获取IP地址、网关及DNS等设置,也就是本机将自动就能上网。hostapd 也配置好了,SSID为test,密码12345678。因为是桥接接口,所以当无线客户端连接成功后也将自动从路由器那获取IP地址、网关及DNS等设置。
现在是时候启动 hostapd 服务了。
systemctl start hostapd.service 而结果确实启动失败,查看服务状态:
systemctl status hostapd.service[root@server ~]# systemctl status hostapd
● hostapd.service - Hostapd IEEE 802.11 AP, IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator
Loaded: loaded (/etc/systemd/system/hostapd.service; enabled)
Active: failed (Result: exit-code) since 一 2015-09-21 20:19:49 CST; 3s ago
Process: 6897 ExecStart=/usr/sbin/hostapd /etc/hostapd/hostapd.conf -P /run/hostapd.pid $OTHER_ARGS (code=exited, status=1/FAILURE)
Main PID: 6897 (code=exited, status=1/FAILURE)
9月 21 20:19:49 server hostapd[6897]: wlp2s0: interface state HT_SCAN->DISABLED
9月 21 20:19:49 server hostapd[6897]: wlp2s0: AP-DISABLED
9月 21 20:19:49 server hostapd[6897]: wlp2s0: Unable to setup interface.
9月 21 20:19:49 server hostapd[6897]: wlp2s0: interface state DISABLED->DISABLED
9月 21 20:19:49 server hostapd[6897]: wlp2s0: AP-DISABLED
9月 21 20:19:49 server hostapd[6897]: hostapd_free_hapd_data: Interface wlp2s0 wasn't started
9月 21 20:19:49 server hostapd[6897]: nl80211: deinit ifname=wlp2s0 disabled_11b_rates=0
9月 21 20:19:49 server systemd[1]: hostapd.service: main process exited, code=exited, status=1/FAILURE
9月 21 20:19:49 server systemd[1]: Unit hostapd.service entered failed state.
9月 21 20:19:49 server systemd[1]: hostapd.service failed. 上面实际上看不出任何问题的具体细节。
6、hostapd 调试
先看看 man hostapd 的手册了解一下如何进行调试。
man hostapd[root@server ~]# man hostapd
……省略……
hostapd [-hdBKtv] [-P <PID file>] <configuration file(s)>
-h Show usage.
-d Show more debug messages. #调试选项
-dd Show even more debug messages. #调试选项详细输出
-B Run daemon in the background.
-P <PID file> Path to PID file.
-K Include key data in debug messages.
-t Include timestamps in some debug messages.
-v Show hostapd version.
……省略…… 看样子很简单大致就是上面的内容。那接下来以调试模式运行。
/usr/sbin/hostapd /etc/hostapd/hostapd.conf -d[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
……省略……
坑提示:“Operation not possible due to RF-kill”,那么 RF-kill 又是什么呢?关于 RF-kill 可以看看这篇《rfkill 无线设备软开关》。