So you have bought your Raspberry and you want to figure out how it is working! If you wanna be cool, you don’t install GUI and do your things only by CLI and via SSH… but! You need a connection to your local network!! How connect automatically our raspberry on boot to our wifi network?
Easy, with cron (or service) and via WPA config. Here is how.
First of all, you need to identify your network name. If you boot Raspbian to desktop, you can launch the wpa_gui (WiFi config) application and click ‘Scan’. You’ll find a list that has your network too with all flags you need.
You know, I don’t like this solution so, if you wanna be cool, you can do like this:
sudo iwlist wlan0 scan and find out your wifi ESSID and proto.
SSID is your network name. After you found it, you need to update your /etc/wpa_supplicant/wpa_supplicant.conf file. Here is an example:
psk is your network password. You need to write it there. The other parameters are network specific, I can’t tell you what you need.
- proto could be either RSN (WPA2) or WPA (WPA1).
- key_mgmt could be either WPA-PSK (most probably) or WPA-EAP (enterprise networks)
- pairwise could be either CCMP (WPA2) or TKIP (WPA1)
- auth_alg is most probably OPEN, other options are LEAP and SHARED
- priority is an incremental flag because you can specify more network connetions (just by duplicate the “network object”). Priority is an ascending field.
After doing this you can run
sudo ifdown wlan0 and sudo ifup wlan0 and verify your connection by ping another ip.
Now you have connected your RPi via DHCP. What if you wanna have a static ip?
Here we go.
We need to update our /etc/dhcpd.conf (for info about this file run
man dhcpcd.conf) as the follow:
It’s pretty simply here, you need just specify your static ip and gateway. Then reboot your wifi connection.
So, now you have configured your RPi with your wifi network and static ip but… what if the wifi network goes down and reup after 5min? You need to re-connect manually…
BUT! If you wanna be a cool guy: check every minute (via crontab) if we are still connected to our wifi network and it’s all up:
You need to program this script in your crontab like this:
*/10 * * * * root /bin/bash /home/pi/check-wifi.sh