debian/ubuntu安装和设置wifi 热点/ap
2019-01-24 10:11:40
One-minute read
安装hostapd和dnsmasq
sudo apt-get install hostapd dnsmasq
修改hostapd配置文件
sudo vim /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=test_wifi
hw_mode=g
channel=7
macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
wmm_enabled=1
ieee80211n=1
ht_capab=[HT40-][SHORT-GI-20][SHORT-GI-40]
wpa=2
wpa_passphrase=mypasswd
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
修改hostapd default配置
vim /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"
配置dnsmasq
vim /etc/dnsmasq.conf
resolv-file=/etc/resolv.dnsmasq.conf
server=/cn/114.114.114.114
server=/taobao.com/114.114.114.114
server=/google.com/8.8.8.8
listen-address=127.0.0.1,192.168.11.1
dhcp-range=192.168.11.50,192.168.11.150,12h
dhcp-option=3,192.168.11.1
dhcp-option=6,192.168.11.1
cache-size=1024
conf-dir=/etc/dnsmasq.d
vim /etc/resolv.dnsmasq.conf
nameserver 114.114.114.114
nameserver 223.5.5.5
nameserver 223.6.6.6
禁用network-manager 管理wlan
查看wlan0的mac地址
ifconfig wlan0 | grep -i hwaddr
wlan0 Link encap:Ethernet HWaddr 7d:e6:d2:30:9f:f2
修改network manager配置
vim /etc/NetworkManager/NetworkManager.conf
在文件底部新增
[keyfile]
unmanaged-devices=mac:7d:e6:d2:30:9f:f2
重启nm
service network-manager restart
这样wlan卡就不会被NM接管了,然后启动相关服务
systemctl enable dnsmasq.service
systemctl enable hostapd.service
systemctl start dnsmasq.service
systemctl start hostapd.service
查看wifi网络,是否已经存在了这个:test_wifi的wifi网络,试用mypasswd登录,这个时候可能会一直处于获取ip地址的过程中,查看系统的日志文件:
tail -f /var/log/daemon.log
会发现有如下错误:
Jan 24 17:44:50 debian dnsmasq-dhcp[8295]: DHCP packet received on wlan0 which has no address
这是因为wlan0没有ip地址,可以使用如下命令设置wlan0的ip地址:
ifconfig wlan0 192.168.11.1
如果后续不用ap了,要删除ip地址的配置可以使用如下指令删除:
ip addr del 192.168.11.1 dev eth0
这个时候在看日志应该没问题,可以顺利连上wifi了,搞定!
参考链接: