嵌入式linux网络配置

2019-07-12 18:12发布

做嵌入式经常用到网络配置,在这里总结一下

创建 wpa_supplicant.conf

开放的wii
ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
   ssid="ssid"
   scan_ssid=1
}
WPA加密方式
ctrl_interface=/var/run/wpa_supplicant
network={
          ssid="ssid"
          scan_ssid=1
          key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
          pairwise=TKIP CCMP
          group=CCMP TKIP WEP104 WEP40
          psk="123456"   #密码 }

启动配置网络的脚本

#!/bin/bash
echo "=============start.sh================"
#init internet
#wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
ps_out=`ps | grep wpa_supplicant | grep -v 'grep' | grep -v $0`
result=$(echo $ps_out | grep "$1")
echo $result
if [[ "$result" == "" ]];then
res=`wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf`
echo "wpa_supplicant:"$res
else
res=`wpa_cli reconfigure`
echo "wpa_cli: "$res
fi
sleep 1
pid=`cat /var/run/udhcpc.wlan0.pid`
if [[ "$pid" != "" ]]; then
kill -9 $pid
fi
sleep 1
res=`udhcpc -T 20 -R -n -p /var/run/udhcpc.wlan0.pid -i wlan0`
echo "udhcpc: "$res
#/etc/init.d/networking start

echo "=============start.sh end================"