我被这个wlan0折腾的不轻,可能ap热点没有建立起来,和这个有关。
我准备用一个usb的无线网卡,芯片是9271 Atheros ,建立wifi热点。
lsusb
Bus 003 Device 003: ID 0cf3:9271 Atheros Communications, Inc. AR9271 802.11n
这个 9271 Atheros 的mac是`00:1a:8c:30:08:b1`.
我的安卓手机的mac是 f0:79:59:cb:d8:eb ,热点创建后,我用安卓手机来连接。
vim /etc/network/interfaces
auto dsl-provider
iface dsl-provider inet ppp
pre-up /bin/ip link set eth0 up
provider dsl-provider
auto eth0
iface eth0 inet static
address 192.168.22.1
netmask 255.255.255.0
dns-server 114.114.114.114
auto wlan0
iface wlan0 inet static
address 192.168.22.2
netmask 255.255.255.0
vim /etc/hostapd/hostapd.conf
hw_mode=g
channel=11
driver=nl80211
ssid=test
interface=wlan0
# encryption
wpa=2
wpa_passphrase=password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP
ctrl_interface=/var/run/hostapd
# Only root can configure hostapd
ctrl_interface_group=0
vim /etc/dnsmasq.conf
log-queries
log-facility=/var/log/dnsmasq/dnsmasq.log
interface=wlan0
listen-address=192.168.22.1
dhcp-range=192.168.22.2,static,255.255.255.0
dhcp-option=3,192.168.22.1
dhcp-option=6,114.114.114.114
配置文件都设好了,现在建立wifi热点。
nmcli radio wifi off
rfkill unblock wlan
ifconfig wlan0 192.168.22.2 up
service dnsmasq restart
service hostapd restart
注意此时的wlan0 192.168.22.2是我的usb无线网卡。
hostapd /etc/hostapd/hostapd.conf
现在用android手机来连接这个热点,ssid `test` and password `password`.
hostapd /etc/hostapd/hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf
Using interface wlan0 with hwaddr 00:1a:8c:30:08:b1 and ssid "test"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
wlan0: STA f0:79:59:cb:d8:eb IEEE 802.11: authenticated
wlan0: STA f0:79:59:cb:d8:eb IEEE 802.11: associated (aid 1)
wlan0: AP-STA-CONNECTED f0:79:59:cb:d8:eb
wlan0: STA f0:79:59:cb:d8:eb RADIUS: starting accounting session 57917673-00000000
wlan0: STA f0:79:59:cb:d8:eb WPA: pairwise key handshake completed (RSN)
wlan0: AP-STA-DISCONNECTED f0:79:59:cb:d8:eb
这里的wlan0显示的 f0:79:59:cb:d8 就是安卓手机的mac.
cat /var/log/dnsmasq/dnsmasq.log
Jul 22 09:26:50 dnsmasq[2452]: exiting on receipt of SIGTERM
Jul 22 09:26:50 dnsmasq[2593]: started, version 2.72 cachesize 150
Jul 22 09:26:50 dnsmasq[2593]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect
Jul 22 09:26:50 dnsmasq-dhcp[2593]: DHCP, static leases only on 192.168.22.2, lease time 1h
Jul 22 09:26:50 dnsmasq[2593]: reading /etc/resolv.conf
Jul 22 09:26:50 dnsmasq[2593]: using nameserver 114.114.114.114#53
Jul 22 09:26:50 dnsmasq[2593]: read /etc/hosts - 6 addresses
Jul 22 09:27:13 dnsmasq[2593]: exiting on receipt of SIGTERM
Jul 22 09:27:13 dnsmasq[2647]: started, version 2.72 cachesize 150
Jul 22 09:27:13 dnsmasq[2647]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect
Jul 22 09:27:13 dnsmasq-dhcp[2647]: DHCP, static leases only on 192.168.22.2, lease time 1h
Jul 22 09:27:13 dnsmasq[2647]: reading /etc/resolv.conf
Jul 22 09:27:13 dnsmasq[2647]: using nameserver 114.114.114.114#53
Jul 22 09:27:13 dnsmasq[2647]: read /etc/hosts - 6 addresses
Jul 22 09:27:28 dnsmasq-dhcp[2647]: DHCPDISCOVER(wlan0) f0:79:59:cb:d8:eb no address available
Jul 22 09:27:33 dnsmasq-dhcp[2647]: DHCPDISCOVER(wlan0) f0:79:59:cb:d8:eb no address available
Jul 22 09:27:42 dnsmasq-dhcp[2647]: DHCPDISCOVER(wlan0) f0:79:59:cb:d8:eb no address available
上述过程可以看出:
1.热点是建立了,刚建立的时候wlan0 使用了我的usb无线网卡作为界面
Configuration file: /etc/hostapd/hostapd.conf
Using interface wlan0 with hwaddr 00:1a:8c:30:08:b1 and ssid "test"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
2.授权后,wlan0也变了
wlan0: STA f0:79:59:cb:d8:eb IEEE 802.11: authenticated
变成我安卓手机的mac.
3.安卓手机没有获得正确的ip地址
dnsmasq-dhcp[2647]: DHCPDISCOVER(wlan0) f0:79:59:cb:d8:eb no address available
问题1:
wlan0 是变化的,这种变化是正常的,还是我在设置上的不正确,导致的?
问题2:
DHCPDISCOVER(wlan0) f0:79:59:cb:d8:eb no address available
由于安卓手机没有获得正确的ip,导致热点AP-STA-DISCONNECTED ,如何在热点建立后,让android手机正常连接上?