How to set static IP for OpenHAB
Do you need a fixed address for OpenHAB outside the range of DHCP addresses that the router assigns? This is sometimes useful, especially if you have, for example, identical RPi as a backup, if there is a problem, simply switch to a backup RPi and you will have the same IP.
The alternative is to set a fixed address for RPi on your router, but you must then do this for both RPi, or adjust it manually. In PiHome, it is important to not change the address of the MQTT Broker, which is currently running on RPi, so static IP is good way.
General settings that work on Debian including openhabian, Raspbian etc. Open to edit the dhcpcd.conf file with the command below:
sudo nano /etc/dhcpcd.conf
and add this part at the end. Change your IP address to the desired ranges as needed
# Static IP address:
interface eth0
# OpenHAB static IP
static ip_address=10.1.1.200/24
#Your router IP
static routers=10.1.1.100
static domain_name_servers=10.1.1.100 8.8.8.8
Press the shortcut right CTRL+O to save, confirm with Enter key, and press the right CTRL+X to exit nano editor.
Restart the operating system with the command:
sudo reboot
and your RPi should now have a static IP address:
Tip: In openhabian, the OpenHAB3 version runs also the Network Manager and therefore it may happen that the above setting will cause the RPi to have both a static address and a DHCP address. An alternative, specifically for openhabian, is to set the static address via the network-manager nmcli with the commands below. In this case you can skip setting dhcpcd.conf
Display the name of the connection in the terminal with command:
nmcli connection show
NAME UUID TYPE DEVICE
Wired connection 1 3f5ce7eb-238b-3bea-b16a-5edhsjakakf9 ethernet eth0use these commands to apply static IP address:
sudo nmcli con mod Wired\ connection\ 1 ipv4.addresses "10.1.1.200/24"
sudo nmcli con mod Wired\ connection\ 1 ipv4.gateway "10.1.1.100"
sudo nmcli con mod Wired\ connection\ 1 ipv4.dns "10.1.1.100 8.8.8.8"
sudo nmcli con mod Wired\ connection\ 1 ipv4.method manual
sudo nmcli con mod Wired\ connection\ 1 connection.autoconnect yes
sudo reboot
Add comment