Sunday, February 21, 2016

Raspberry Pi - Setting Static IP address

For Christmas I bought for myself :) Raspberry Pi and installed Raspbian and OpenELEC on this. For now I usually use it as low-energy  uploader/downloader or photo batch processor.
I want to have remote access to it also from outside my home network. By default Raspbian uses DHCP to obtain IP address from my home DHCP server. As I need to forward ports from my ISP router to my Raspberry PI, I need to give it always static IP address. I've been messing around with it a bit until I figured it out. Here is the recipe:

1. Turn off dhcp client which will always override things

$ sudo update-rc.d dhcpcd disable

You can also do it old school way by removing execute right:

$ sudo chmod a-x /etc/init.d/dhcpcd

2. Add the following lines to /etc/network/interfaces (the bold ones are new)

auto lo
auto eth0

iface lo inet loopback

#iface eth0 inet manuala
iface eth0 inet static
address 192.168.1.100
gateway 192.168.1.254
netmask 255.255.255.0


3. We need /etc/resolv.conf with static dns entry. This file is always rewritten by resolvconf utility, so we need to change it. In /etc/resolvconf.conf we add one line:

name_servers=192.168.1.254

My nameserver is my gateway at the same time. 

4. Restart networking services by:

 $ sudo /etc/init.d/networking restart

Works for me. We can check if everything is ok running:

$ /sbin/ifconfig

No comments:

Post a Comment