Giving Static IP to Pi

For raspbian version, check /etc/os-release

Raspbian 7 (wheezy)

Edit /etc/network/interfaces

ETH0:
change from
ifface eth0 inet dhcp

change to

iface eth0 inet static
address 192.168.1.111
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255

Wireless Lan (Edimax for example)

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.2.111
gateway 192.168.2.1
dns-nameservers 8.8.8.8 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1 dev wlan0

When I have both eth0 and wlan0 setup as static, I dunno why, but all my wlan0 traffic goes to eth0’s gateway. So I’ve to add the last line to force a route to wlan0 gateway in order to have internet access for wireless lan. Wired.

Sometime the /etc/resolv.conf also got reset to blank. I’ve to add the dns-nameservers manually.

Getting the wifi works is really pain in the ass.

That’s why unix system always need an administrator.

Raspbian 8 (jessie)

Edit /etc/dhcpcd.conf

interface eth0
static ip_address=192.168.1.111
static routers=192.168.11.1
static domain_name_servers=192.168.11.1

Reference
http://sizious.com/2015/08/28/setting-a-static-ip-on-raspberry-pi-on-raspbian-20150505/



Leave a Reply

Your email address will not be published. Required fields are marked *