已有现成工具实现常见需求,一般不必手工配置,如 hotspotd 和 create_ap
较新的linux发行版一般使用wpa_supplicant软件连接wifi并进行密码验证。其自动连接是通过 /etc/network/interfaces
文件中的
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
的第二行实现的。若需要开热点,则要把wpa相关的自动配置行注释掉,然后执行ifdown wlan0
和ifup wlan0
重启网口
之后编辑hostapd的配置文件/etc/hostapd/hostapd.conf
以启动热点
# This is the name of the WiFi interface we configured above
interface=wlan0
# 一般笔记本集成网卡用nl80211 而第三方tp-link的网卡使用rtl871xdrv
driver=nl80211
# the name of the network
ssid=Pi3-AP
# Use the 2.4GHz band
hw_mode=g
# Use channel 6
channel=6
# Enable 802.11n
ieee80211n=1
# Enable WMM
wmm_enabled=1
# Enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
# Accept all MAC addresses
macaddr_acl=0
# Use WPA authentication
auth_algs=1
# Require clients to know the network name
ignore_broadcast_ssid=0
# Use WPA2
wpa=2
# Use a pre-shared key
wpa_key_mgmt=WPA-PSK
# The network passphrase
wpa_passphrase=raspberry
# Use AES, instead of TKIP
rsn_pairwise=CCMP
然后需要配置DHCP服务,必要的话还可以用iptables
启动转发路由以共享上网。关于DHCP服务,linux下有很多工具可以使用,比如dnsmasq udhcpd isc-dhcp-server等,详情可参考[linux中的DHCP工具]
手工建立ap的详细配置步骤可见
https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/
http://raspberry-at-home.com/hotspot-wifi-access-point/
http://raspberrypi.stackexchange.com/questions/22259/ap-with-tl-wn725n-v2
对于TP-LinkWN725 v2无线网卡,需要替换hotspotd才能实现ap功能。修改后的文件可从这里或这里下载,然后替换掉/sbin/
下的同名文件
源代码工程托管在RTL8188
注意,这类网卡在使用create_ap
时,必须开启--driver rtl871xdrv
指令,否则无法工作