In the midst of my work upgrading the Raspberry Pi Dramble to Raspbian Jessie Lite, I noticed one of the basic components of the architecture—static IP addresses for all the Raspberry Pis—was not working correctly anymore. My Ansible playbooks configured the /etc/network/interfaces
file correctly, so it would define a static IP address for the eth0
interface (the built-in Ethernet port on the Pi):
auto lo
iface lo inet loopback
iface eth0 inet static
address 10.0.1.60
netmask 255.255.255.0
gateway 10.0.1.1
dns-nameservers 8.8.8.8 8.8.4.4
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
In the past, with Raspbian Wheezy, everything worked fine, and the Pi would (after a reboot) use the static IP address 10.0.1.60
.
In Raspbian Jessie Lite, there is a little additional configuration you need to provide for dhcpcd, since Raspbian uses dhcpcd5
by default. If you want, you could disable/uninstall dhcpcd5
entirely, but it's simpler to provide the correct static IP configuration in dhcpcd's configuration file. In my case, I edited /etc/dhcpcd.conf
, and put the following inside, after the rest of the configuration:
interface eth0
static ip_address=10.0.1.60/24
static routers=10.0.1.1
static domain_name_servers=8.8.8.8 8.8.4.4
After rebooting the Raspberry Pi, the static IP address configuration worked just like it did with Wheezy. Another note; you can also delete the persistent dhcp lease info by removing the following files:
/var/lib/dhcp/dhclient.leases
/var/lib/dhcpcd5/dhcpcd-eth0.lease
For the Dramble, I made all the above changes to the Ansible playbook that configures Pi networking in this commit.
Comments
Thanks, I was looking on changing the ip address of my raspberry. You gave the answer.
And offcourse, many thanks for the developper, who now have made it very logical, setup the fixed ip in the dhcp config file. Yeah.
Hi Jeff, Would this also work on the rasbian pi 2 b with jessie version 8.
Yes; should work on any system with Jessie.
To my mind, this is a fairly major bug - an interface that is defined as static in /etc/network/interfaces shouldn't be interfered with by dhcpcd (I see one suggestion that changing from "allow-hotplug eth0" to "auto eth0" fixes it - but it seems, oddly, that you have neither in your config file above?)
If you don't actually need dhcpcd then removing it is surely easier long term (given it's just one command) than maintaining a second configuration file and adheres to the general best practice of not running unnecessary services (aside from the security angle, this is also important on systems of limited resource such as the Pi!). I see some anecdata from the pi forum that suggests that removing the dhcpcd5 package deletes /etc/network/interfaces, though, which seems completely and totally insane (even if the package was purged I would not expected /etc/network/interfaces to be in the dhcpcd5 package).
Perhaps the least-impact fix (if you don't mind running dhcpcd unnecessarily, or need it for a wlan interface or similar) is to tell it to ignore eth0 (or whatever interface you want to stop it from interfering with): "denyinterfaces eth0" in /etc/dhcpd.conf should work, by the looks of things. That way, if you come to change the interface address on eth0 you won't have to also modify dhcpcd.conf each time.
Shouldn't there be a line in /etc/network/interfaces to bring the interface up
auto eth0
Otherwise it needs you to manually bring it up with
sudo ifup eth0
There shouldn't be any need to use dhcp at all with a statically assigned address.
Will it work if I dont add a DNS IP? and why do we need to assign the same IP leased from our DHCP?
Thank you for this! Bookmarking...
Hello Jeff.
I discovered the same things you did apart from the lease files, but there is still one thing I am missing and still looking for it. Where do you set up the domain search option? Meaning the domain suffix that sould be appended to a hostname you are looking up, if none is provided with the hostname. There should be an option there but I don't see it in the man. Maybe I am not looking in the right place. Do you have any idea?
Just add "search_domains=your.domain" to /etc/resolvconf.conf"
thanks, after messing around with this (pi zero / jessie lite) for a while this actually worked! nice job, thanks again.
I am using jessie on the rpi b+. I am sorry to say this does not work. It works on the rpi 3, but sadly not on the B+. In fact there seems to be no way of setting a static ip on the B+.
Hi again
Success at last. Took this from comment section on another blog.
There is a simple alternative of adding
alias {
interface "wlan0";
fixed-address 192.168.1.123;
}
to
/etc/dhcp3/dhclient.conf
That will still use all dhcp-information but add the specified ip-address as an alias to the interface. Thus it will survive changes on the router, buying of a new one etc.
It worked for me. Thats all I can say.
All the best...
Why in the world would you assign a /24 subnet as an ip adress to a single host? I don't think you really know what you are doing here.
Meh, I don't know why the
/etc/network/interfaces
example has a /24, you're just as well leaving it off (I'm guessing it was a copypasta error from thedhcpcd.conf
). If you leave it on, it doesn't effectively make a difference on that host, it's still interpreted as IP address10.0.1.60
.I'll update the example though, since as you indicate there's no reason to put CIDR notation in there, much less a wide-ranging one.
I am leaving it in the dhcpcd.conf example, though, since the official documentation in ArchWiki has/recommends it. See also Debian manpages for dhcpcd.conf.