Setting up WiFi connection
Start by booting the Raspberry Pi, connected to a display and a keyboard. Open up the terminal and edit the network interfaces file:
$ sudo nano /etc/network/interfaces
This file contains all known network interfaces, it'll probably have a line or two in there already.
Change the first line (or add it if it's not there) to:
auto wlan0
Then at the bottom of the file, add these lines telling the Raspberry Pi to allow wlan as a network connection method and use the/etc/wpa_supplicant/wpa_supplicant.conf
as your configuration file.
[sourcecode language="bash"]
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
[/sourcecode]
(ctrl-X, then type Y to quit and save)
The next step is to create this configuration file.
Configuring WiFi connection
Open up the wpa_supplicant.conf file in the editor.
$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Again, some lines might already be present, just add the following.
[sourcecode language="bash"]
network={
ssid="YOUR_NETWORK_NAME"
psk="YOUR_NETWORK_PASSWORD"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}[/sourcecode]
The other parameters are network specific, I can't tell you what you need. If you boot Raspbian to desktop, you can launc the wpa_gui (WiFi config) application and click 'Scan'. You'll find a list that has your network too with all flags you need. To do this on a RPi A you'll have to disconnect your keyboard and connect your dongle once the scanning list is open.
proto
could be eitherRSN
(WPA2) orWPA
(WPA1).key_mgmt
could be eitherWPA-PSK
(most probably) orWPA-EAP
(enterprise networks)pairwise
could be eitherCCMP
(WPA2) orTKIP
(WPA1)auth_alg
is most probablyOPEN
, other options areLEAP
andSHARED
Make sure it works
Reboot the Raspberry Pi and it should connect to the wireless network. If it doesn't, repeat above steps or get help from an adult.
A static IP
Since the goal of this tutorial is to be able to work with the RPi without external keyboard or display, you want to be ssh into it. The best way is to make sure it'll always have a static IP on your network.
Doing so is simple. Open the /etc/network/interfaces file again and add the following changes: Change iface wlan0 inet dhcp into iface wlan0 inet static. This changes the wlan0 interface from DHCP to static. Add the following lines before the wpa-conf line:
[sourcecode language="bash"]
address 192.168.1.155 # Static IP you want
netmask 255.255.255.0
gateway 192.168.1.1 # IP of your router
[/sourcecode]
The Raspberry Pi will still be able to connect to the internet.
Wrapping up
With these changes you'll be able to always connect to your Raspberry Pi over your wireless network via ssh at the same, static IP. This means you can disconnect keyboard, mouse and display and have it plugged in a wall socket, anywhere, taking almost no space.
As an overview, my interfaces- and wpa_supplicant-files:
[sourcecode language="bash"]
# /etc/network/interfaces
auto wlan0
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.155
netmask 255.255.255.0
gateway 192.168.1.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
[/sourcecode]
[sourcecode language="bash"]
# /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="NYO_WWWP"
psk="topsecret"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}
[/sourcecode]