Help static ip on wifi setup - Raspberry Pi

Associate
Joined
8 Dec 2004
Posts
1,970
Location
Paignton, Devon
Hi all,

I am new to Linux and am using Raspian on my Raspberry Pi2, i want to set it up with a static ip so i sudo nano /etc/network/interfaces and get..

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

~
~
~
~
~
~
"/etc/network/interfaces" 17 lines, 295 characters

My questions are..

1. why is there Wlan0 and Wlan1?
2. how do i edit /etc/network/interfaces to add a static ip address, its a wireless router with wpa2 encryption.

Thanks all
 

That seems so convoluted compared to when I used to setup my Debian boxes. I'd usually just run ifconfig to ID the devices and then open /etc/network/interfaces and blitz the file clean (or usually left the loopback as it doesn't need touched).

# Loopback
auto lo eth0
iface lo inet loopback

# Ethernet
iface eth0 inet static
address x.x.x.x (whatever IP I want to dictate to the machine)
netmask 255.255.255.0 (the usual)
gateway x.x.x.x (whatever your router IP is)

You could set network and broadcast, but it's generally not advised as it overly complicates things and if you get the settings wrong it'll drop connection and it calculates the correct settings automatically via the address and netmask bit anyway.

# Wireless.
auto wlan0
iface wlan0 inet dhcp
wpa-ssid YOUR-SSID-HERE
wpa-psk YOUR-PASSWORD-HERE

Wireless I'd always leave on DHCP because roaming and having to manually adjust it every time you go to a friends or family to connect to their network or a public network is just a pain in the ass.

Some of that might be out of date with the latest Debian, but it worked on Squeeze and Wheezy from memory.
 
Raspian uses a custom implementation of dhcpcd to manage its network configuration. Instead of editing /etc/network/interfaces, you should define your static IP details in /etc/dhcpcd.conf. Just add the details at the bottom of the file like this for example;

# Static IP Configuration
interface eth0
static ip_address=192.168.1.5
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 4.4.4.4

When you reboot it should just come up with the static address.

Edit: for wireless, replace the eth0 with wlan0.
 
Back
Top Bottom