Setting up Wi-Fi on Raspberry Pi

You can setup Wi-Fi on GUI, or you can configure it from your console. Here is how to do it from the console.

Brief steps:
1. Registering Wi-Fi Network
2. Enabling Automatic Connection
3. Connecting to Wi-Fi network

Let’s get started.

 

1. Registering Wi-Fi Network
1-1. Open /etc/wpa_supplicant/wpa_supplicant.conf

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

1-2. Add last four lines below at the end of the file. Replace <SSID> and <PASSWORD> to appropriate strings for your Wi-Fi network.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
 
network={
    ssid="<SSID>"
    psk="<PASSWORD>"
    key_mgmt=WPA-PSK
}

 

2. Enabling Automatic Connection
2-1. Open “/etc/network/interfaces”.

sudo nano /etc/network/interfaces

2-2. add “auto wlan0” line like below:

auto lo
 
iface lo inet loopback
iface eth0 inet dhcp
 
auto wlan0
allow-hotplug wlan0
...

 

3. Connecting to Wi-Fi Network
3-1. Disable Wi-Fi interface

sudo ifdown wlan0

3-2. Enable Wi-Fi interface

sudo ifup wlan0

* Alternatively, you can reboot the system Instead of step 3-1 and 3-2, to establish Wi-Fi connection.

sudo reboot

3-3. Check assigned IP address

ifconfig wlan0

if everything is ok, you can see a line like below:

inet addr:192.168.51.102 Bcast:129.168.51.255 Mask:255.255.254.0