I have a clean implementation of openHAB running on Pi3. (downloaded: openhabianpi-ua-netinst-20170218-git11d8ebc.img and installed on 16 GB SD through Etcher).
I would like to set a static IP address.
On a Pi2 i have a clean implementation of jessy. I managed to set a static IP via:
sudo nano /etc/dhcpcd.conf
I modified it to:
static ip_address=192.168.0.200/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
I tried this running openHAB - not successful.
Question: how do I set a static IP address in openHAB?
I looked at the documentation and through the messages in the community. No luck.
Help is appreciated.
I havenāt used openhabian but I wonder if by its name it is Debian based. I would try standard Debian static IP in /etc/network/interfaces:
I have installed Jessie a million times over the last while and never used a dhcpcd.confā¦ I always edit the interfaces file.
On second thought, isnāt dhcpcd.conf related to setting up a dhcp server. You donāt want to run a server, you want to retrieve an address from one.
on a Pi3 running openhabian /etc/dhcpcd.conf is empty
/etc/network/interfaces:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
I modified this to:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet
static ip_address 192.168.1.221/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
However: openhab denies me permission to save the file.
@peterz1 I have to ask in case your goal is different. Nowadays setting a static IP address is seldom what you want to do. If you want your device to own a static IP itās often better to set a static DHCP lease in your router settings (tell the router to always assign the same IP address).
Thatās unrelated to openhab. You need to use sudo to edit this file with elevated permissions. If you are not familiar with that concept you should (!) invest a few minutes to learn the Linux basics! e,g, https://linuxjourney.com
Btw. Iāve format-tweaked your previous comment.
Overall I think this should be your configuration:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.221
netmask 255.255.255.0
gateway 192.168.1.1
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Additionally youāll need to configure DNS as described e.g. here or here. Once again: Spare yourself from all that by setting a static IP in your router.
DHCP reservations are great and have their place but I reject the thought that they are better than static for systems serving up a service. I admittedly use both at home (and work, think printers, smartphones) but servers, cameras, mqtt devices etcā¦ all static for me!
I donāt want to force anyone nor do I say that itās the only valid option. However here are a few arguments:
DHCP option is easier and platform independently configured, minimal room for error (see aboveā¦)
DHCP stays in control of address assignment for dynamic and static devices, one point of administration
A device will always be assigned with an IP address, irrespective of the subnet it is in (prepared for change, with the one condition that the network provides a DHCP server)
Advantages of device-side static IP assignment: Safe against router failure (in which case IP address assignment is the least of your problems )
So yes, my very personal and not-one-true-answer opinion is that DHCP address assignment is better.
Those are valid points but mostly when related to small all-in-one type home networks which admittedly is what most people here have.
I think you meant safe against DHCP server failures, not router. My router (and everybodyās for that matter) has absolutely zero to do with dhcp. If my dhcp server failsā¦ then that is my only worry as that is all it does. My router will keep routing away happily. For the all-in-one units, technically your dhcpd implementation could crash without routing, gateway and other services failing as its just a small linux box anyways.
I also donāt find home ārouterā dhcp implementations to be overly robust or easy to work with (for anything better than VERY simple flat networks). I suspect the vast majority of them would force you to (or do it without asking) clean out the reservation table if you changed a subnet. You would also have to re-key all of these pairs if you changed different hardware as you arenāt going to be able to export/import them.
Change a nic or docker container or restore a vm; you could be looking at new mac addresses. I actually have automated backup validation software that would fail if you didnāt have static IPās for servers at work.
All in all, I think they have their place but the industry best practice for servers definitely still is static. I read and implement a fair amount of solutions as an SE and documentation still expects static IP for most situations. Thatās all I was saying. My intent wasnāt to say you were wrong, just that neither is BETTERā¦ even static.
Besidesā¦ heās now learning about linux!!! Nothing is better than linux!!! oops, next opinion topic
Yep you are right, all I said was aimed at the normal home network with one subnet, a bunch of devices and one active component acting as physical switch, router, NAT and DHCP. Thatās also why I used ārouterā as the equivalent to āDHCP serverā.
We both agree that a bigger network will define other requirements and static configurations have their place there. Iām helping manage a small ISP backbone network and there almost all devices are statically configured.
In the end we both have different preferences and thatās great, the world would be boring otherwise
@ThomDietrich Do you think you could make an option to set a static IP in openhabian-config? You could put a disclaimer that it is not the preferred way to set up.
@ThomDietrich, thatās right, DHCP address assignment is better - but with one of the latest Debian updates, I had the strange behavior that the MAC address of my RPi ethernet interface changed on every reboot! That makes it impossible to use DHCP address reservation to make the IP address of my openhabian āstaticā. The only way which worked for me was to edit the interface file on OS level.
Iām use to set static addresses in my router for all my āregularā devices. Openhab server running on RPI3 installed initially whit Openhabian is in that list. Everything works fine but I have a question about what Iām trying to do currently:
I want to prepare a setup similar to mine for my parents. So, I just disconnect my RPI, burn an image of my SD card and run that card on another RPI. From there, no problem everything is identical. I removed complex stuff from Paper UI and keep only basic functionalities I want for the second setup.
The problem is that my parents router is running under a different address as mine (192.168.0.1 instead of 192.168.2.1). Because of that (I thinkā¦ because Iām not a pro in network configuration), DHCP server of the router of the final location is not attributing any IP address. I just donāt see the RPI in that router. I donāt want to change basic address of that router and have to change everything already connected just to add the Openhab setup.
Do you think this could fit my need following my previous post (replacing xx by the wanted address) ?
######################################################
# TEMPLATE: A different IP address on each network
#
# The arping address should be the router
# or some other machine guaranteed to be
# available. You need to know the addresses
# of the servers. If none of the arpings find
# an active machine then you will get a DHCP
# allocation.
######################################################
interface eth0
arping 192.168.2.1
arping 192.168.0.1
profile 192.168.2.1
static ip_address=192.168.2.xx/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1
profile 192.168.0.254
static ip_address=192.168.0.xx/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
But If I use this, I understand the IP address will be static if arping find out a router on the network. What will happen if I remove static ip_address in both profile? Should I get an address from DHCP server if a router is found at 192.168.2.1 or 192.168.0.1 or it will not work at all?
Finally, Iām not sure if I should keep āāpersistentāā lower in the script. It was there on the original script but Iām not sure to understand if it will interact with the arping and profile setup when I will change the RPI to itās final location?
Be careful if you are using Stretch and have predictable network names enabled, this will change your interface name (eth0).
There are a lot of posts around the net dealing with this ā¦