STA 模式:
1.使用iwlist wlan0 scanning 查看能够扫描到的WiFi的ssid
2.连接wifi的配置文件:wpa_supplicant.config
执行命令:wpa_supplicant -c /tmp/wpa_supplicant.config -i wlan0 &
3.ifconfig wlan0 192.168.1.5 ;route add default gw 192.168.1.1 设置IP和网关 ,也可以通过udhcpc -i wlan0 自动获取路由器分发的IP地址.
4.iwconfig 查看路由是否连接
5.后面就可以直接ping网络
AP模式:
需要使用hostapd udhcpd
1.在/etc/hostapd.conf中修改热点名字与密码
2.分配网络 ip 的配置文件(/etc/udhcpd.conf):
内容部分截图:
start 192.168.0.20 //自动分配 ip 的开始范围
end 192.168.0.254 //自动分配 ip 的结束范围
3.创建热点:
hostapd -B /etc/hostapd.conf -f /var/log/hstap.log
4.设置IP
ifconfig wlan0 192.168.1.4
5.为连接上的设备分配IP
udhcpd -f /etc/udhcpd.conf &