1、nmcli命令配置IP和gateway
nmcli con add con-name JK_AGV ifname wlan0 type wifi ssid JK_AGV ip4 192.168.2.108/24 gw4 192.168.2.1
2、配置password
nmcli con modify JK_AGV wifi-sec.key-mgmt wpa-psk nmcli con modify JK_AGV wifi-sec.psk JK12345+
3、配置静态ip
nmcli conn mod JK_AGV ipv4.method manual
4、连接WiFi
nmcli conn up JK_AGV
5、配置/lib/systemd/system/rc.local.service
[Unit] Description=/etc/rc.local Compatibility Documentation=man:systemd-rc-local-generator(8) ConditionFileIsExecutable=/etc/rc.local After=network.target [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 RemainAfterExit=yes GuessMainPID=no [Install] WantedBy=multi-user.target Alias=rc-local.service
6、WiFi断网自动联网脚本
#!/bin/sh
while :
do
sleep 10
gateway=$(route -n | grep wlan0 | grep UG | awk '{print $2}')
if [ -z $gateway ];
then
echo "the gateway is null, wlan0 connecting..."
nmcli conn up JK_AGV
else
ping -c 3 -I wlan0 -s 8 $gateway >/dev/null 2>&1
if [ $? = 0 ];
then
echo "wifi is connected"
else
echo "wlan0 connecting..."
nmcli conn up JK_AGV
fi
fi
sleep 150
done
exit 0
7、配置/etc/rc.local
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. bash /root/auto_connect_wifi.sh > /var/wifi.log 2>&1 & exit 0
8、创建软链接
ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/
posted on
浙公网安备 33010602011771号