DIY Projects

How to assign a fixed IP address and a domain name to a Raspberry Pi

3. ssh domoticz.local

Assign a fixed IP address to your Raspberry Pi can be very useful if you have many materials (computers, accessories, home automation, ESP Easy DIY projects, home automation box…) on its local network.

For this tutorial, I used a Raspberry Pi 3 under Raspbian, but the procedure is the same regardless of the Linux distribution.

Assign a fixed IP address to the Raspberry Pi

Open a Terminal under Raspbian or connect in SSH to your Raspberry and then open the configuration of the interfaces file.

 sudo nano/etc/network/interfaces

the configuration file looks like this

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Assign a fixed IP to the interface wlan0 (wireless)

for this tutorial, we’re going to change the configuration of the interface (wlan0) WiFi. Modify the file by adjusting the following configuration to your needs

iface wlan0 inet static
  wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
  iface default inet dhcp

Assign a fixed IP to the interface eth0 (Ethernet)

you can do exactly the same thing for the Ethernet interface. Here is an example of configuration it will adapt to your configuration.

iface eth0 inet static

Add a permanent road

If your IP is not on the same subnet, it is possible to add a permanent route with the option

up route add – net IP_RPI/24 gw IP_GATEWAY, giving for example:

up route add -net gw

For more information:

This configuration works fine if you plug your Raspberry Pi on another computer that is sharing its internet connection. For example, I use my Mac Mini as internet bridge time to update distribution Raspbian for images too old home automation software that do not support the WiFi of the ft3.

Apply the new configuration

Save with Ctrl + X then O (or Y if you’re not in french).

to apply the new configuration, you can restart

 sudo reboot

or raise the layer network

 sudo /etc/init.d/networking restart

Access the Raspberry Pi using its domain name

Raspbian assigns a domain name to the Raspberry. Default is raspberrypi. Not need to know the IP address of the Raspberry to access so we didn’t. For example, SSH simply enter

 ssh pi@raspberrypi.local

Similarly if you do home automation, you can access your Domoticz box from a browser by entering the URL


Cool right!

Change the default domain name

Now, we would like to be able to change the default domain name. Why not give the Raspberry name of the home automation for example box. It’s very simple, just change it in the configuration file host .

 sudo nano/etc/hosts

The configuration file looks like this       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters       raspberrypi

Replace raspberrypi by domoticz for example or any other name (without space, special characters or accented characters). Save with Ctrl + X then Y.

Now open the file hastname and replace raspberrypi by the same domain as before.

sudo nano/etc/hostname

Save and run this command to apply the changes

sudo etc/init.d/

It remains more to restart the Raspberry

sudo reboot

Once rebooted, try to connect by SSH. For example

 ssh pi@domoticz.local 

Now you can access the Domoticz interface in a browser

Much easier to hold an IP right?

Click to rate this post!
[Total: 0 Average: 0]
Exit mobile version