Connect your Raspberry Pi to Wireless Network Automatically

Do not worry, doing this job is actually easier than you think. Let’s see how:

Firstly, in cases when you need to reset the default settings, backup your configuration files with command below;


$ sudo cp /etc/network/interfaces /etc/network/interfaces_bak

Then edit the -/etc/network/interfaces- file like following content (for auto dhcp/WPA-WPA2);


$ sudo nano /etc/network/interfaces

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
   wpa-ssid "NETWORK_NAME"
   wpa-psk "NETWORK_PASSWORD"

If you want to assign static ip address to your RPi here the solution;)


$ sudo nano /etc/network/interfaces
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0

iface wlan0 inet static 
   wpa-ssid "NETWORK_NAME" 
   #(set these lines for their respective encryption type- wpa, wep, etc.)
   wpa-psk "NETWORK_PASSWORD"
   address 192.168.0.XX 
   #(This is the IP you want your raspberry pi to have)
   netmask 255.255.255.0 
   #(This is almost always the same)
   gateway 192.168.1.1 
   #(almost always the same as well. you can verify with netstat -nr)

Finally reboot your device;


$ sudo reboot

Check your internet connection;


$ ping google.com

That’s it!

Reference: https://github.com/retropie/retropie-setup/wiki/Wifi