openHABian and Static IP Address

@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.

3 Likes

Hmmm I’m not sure. As you can read above, I don’t think it’s a much needed option. The normal user will probably not need it, the “slightly” experienced can just go through the normal steps as everyone can find here: https://wiki.debian.org/NetworkConfiguration#Configuring_the_interface_manually

Still if you wish for such a function, feel free to contribute a PR! :wink:

@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.

How should I proceed?

Edit /etc/dhcpcd.conf to your needs.

Thanks @sihui !

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?

To define a static ip for your RPi you can just add:

interface eth0
static ip_address=192.168.0.xxx/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

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 …

I did the following in the /etc/dhcpd.conf

interface wlan0
static ip_address=192.168.178.211/24
static routers=192.168.178.1
static domain_name_servers=192.168.178.1

but when rebooting it doesn’t change the ip, it still stays the old one…

It is a Raspberry Pi 3 B+. What is the problem?

If you are on Stretch static ip config has changed, please search the net.

Mine works by editing /etc/dhcpcd.conf. Cheers

I am using 2.4.0.1 openhabian. So is that Stretch?

Please search the forum for related issues, there are a couple of them:
https://community.openhab.org/search?q=openhabian%20wifi

https://averagemaker.com/2017/11/raspbian-version.html

1 Like

I faced almost same problem & problem resolved after fresh installation of Openhab 2.

I am not sure about why this problem arises in my previous setup, but it was started after enabling WIFI connection. So during fresh openhab setup I first applied statistic ip in dhcpd.conf file before doing anything else. & It works.

https://community.openhab.org/t/solved-how-to-set-static-ip-of-eth0-port/62974/2

I think there’s an error in the openhabian configuration when setting up static IP.

I eventually found my way out by following the steps described at StackExchange: How do I set up networking with static IP address

In essence, I had to replace /etc/network/interfaces/interfaces with /etc/network/interfaces/interfaces.dpkg-old, edit /boot/cmdline.txtand add net.ifnames=0 as boot parameter (to make sure your network interfaces are named eth0 and wlan0), and then add the following lines at the bottom of etc/dhcpcd.conf:

interface eth0
static ip_address=192.168.0.XX/24
static routers=192.168.0.1
static domain_name_servers=<dns.ip.addr.1> <dns.ip.addr.2>

Where xx represents the last byte of the static IPv4 address I want to assign to the wired Ethernet link (eth0 interface), and <dns.ip.addr.1> <dns.ip.addr.2> represents a space-separated list of IPv4 / IPv6 addresses of domain servers you should use (e.g., as provided by your ISP).

In my case I know I can pick any value for xx in the range 2 to 99 as those addresses are not assigned by the DHCP server of my cable modem/router. And I have to use static IP addresses as my modem/router doesn’t expose static address assignment.

Should you not know the names of your network interfaces, then please run ifconfig -a.

Hmmm, I am confused when reading all the articles about setting a static IP for Openhab. I also need to set a static IP and search for a simple and stable solution.

Is 2.4 now using stretch out not and
when I would use your recommendation will this be overwritten when updating OH?

Thanks a lot

To my knowledge there are 2 openhabian distributions available, one based on stretch (does not support RPi4), one based on buster (supports RPi4). The openhabian-config script will help you select the openHAB release you’d like to use, irrespective of the openhabian distribution. Right now, you can chose between:

  • openHAB 2.4 stable
  • openHAB 2.5 milestone (currently M4) — I’d recommend this for new deployments
  • openHAB daily snapshots — only use if you want/need to test new features or new binding updates

If your home automation setup is critical, I’d say to leave it at the current openHAB release and use a second computer (RPi) to prepare the migration to a newer openHAB version (based on 2.5 snapshot).

I haven’t tried upgrading a stretch-based image to buster; instead I reinstalled a blank buster-based openhabian distribution.

I did. Worked flawless.

Thanks a lot,

So I could solve the static IP issue for my OH2 2.4 on PI3b.

First:
I have edited the etc/dhcpcd.conf

interface wlan0
static ip_address=192.168.2.99/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1

restarted -> Not working

Second
I have edited additionally the /etc/network/interface file and just left that one line active:

source-directory /etc/network/interfaces.d

restarted -> BINGO works

Edit 02August2020
I updated to Pi4/Buster and I had exactly the same issue. It was required to follow the second step
and add/create the file and line /etc/network/interface. I think the file wasn´t existing and so
it was empty when using sudo nano /etc/network/interface.

2 Likes

It worked!