Normal client mode.
$sudo apt-get update
$sudo apt-get install hostapd -y
$sudo apt-get install dnsmasq -y
$sudo systemctl disable hostapd
$sudo systemctl disable dnsmasq
/etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=RPI3wifi
hw_mode=g
channel=6
wmm_enabled=0
macaddr_acl=0
auth_algs=1
wpa=2
wpa_passphrase=1234567890
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
/etc/default/hostapd
#demon_conf=""
==>
demon_conf="/etc/hostapd/hostapd.conf"
/etc/dnsmasq.conf
#Pi3Hotspot Config
#stop DNSmasq from using resolv.conf
no-resolv
#Interface to use
interface=wlan0
bind-interfaces
dhcp-range=10.0.0.3,10.0.0.20,12h
server=8.8.8.8
/etc/network/interfaces
allow-hotplug wlan0
iface wlan0 inet manual
#wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
/etc/rc.local
#!/bin/sh -e
==>
#!/bin/bash -e
insert between fi and exit 0
#Wifi config - if no prefered Wifi generate a hotspot
#RPi Network Conf Bootstrapper
createAdHocNetwork()
{
echo "Creating RPI Hotspot network"
ifconfig wlan0 down
ifconfig wlan0 10.0.0.5 netmask 255.255.255.0 up
service dnsmasq start
service hostapd start
echo " "
echo "Hotspot network created"
echo " "
}
echo "================================="
echo "RPi Network Conf Bootstrapper"
echo "================================="
echo "Scanning for known WiFi networks"
ssids=( 'mySSID1','mySSID2' )
connected=false
for ssid in "${ssids[@]}"
do
echo " "
echo "checking if ssid available:" $ssid
echo " "
if iwlist wlan0 scan | grep $ssid > /dev/null
then
echo "First WiFi in range has SSID:" $ssid
echo "Starting supplicant for WPA/WPA2"
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null 2>&1
echo "Obtaining IP from DHCP"
if dhclient -1 wlan0
then
echo "Connected to WiFi"
connected=true
break
else
echo "DHCP server did not respond with an IP lease (DHCPOFFER)"
wpa_cli terminate
break
fi
else
echo "Not in range, WiFi with SSID:" $ssid
fi
done
if ! $connected; then
createAdHocNetwork
fi
출처: