cat /sbin/auto_wifi.sh #!/bin/sh if [ $ACTION = "add" ]; then wpa_supplicant -B -c/etc/wpa_wpa2.conf -iwlan0 wpa_cli -a/sbin/wpa_action.sh -B else killall wpa_supplicant killall wpa_cli killall dhclient fi
chmod +x /sbin/auto_wifi.sh
一连接上WIFI AP, 就自动执行dhclient 创建一脚本: cat /sbin/wpa_action.sh #!/bin/sh IFNAME=$1 CMD=$2 if [ "$CMD" = "CONNECTED" ]; then echo connect $IFNAME, dhclient for it > /dev/console dhclient $IFNAME fi if [ "$CMD" = "DISCONNECTED" ]; then echo disconnect $IFNAME, kill dhclient for it > /dev/console killall dhclient fi