Browse our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteria

How to configure static IP in a Touchberry Pi Panel.

for permanent applications

Introduction


In this post we will see how to configure a static IP in Raspberry Pi working with Raspbian operating system through the command console.

In many occasions we will not want to dedicate our Raspberry Pi to a "normal" computer with screen and keyboard, but we will dedicate it to permanent applications.

Examples of permanent applications are, among many others, a file server, a web server, home automation applications such as controlling lights, making an alarm, or a thermostat, and even when making robots.

In these cases have a static IP is a very important requirement, if not almost essential, to connect with our Raspberry at all times from another device.

Requirements


Your project requires a dynamic or static IP?


Through the IP address we can connect with our device in a simple way.

This IP can be:


  • Dynamic, it can change every time we reboot the device.

  • Static, remains fixed between restarts.


In many cases our devices are connected to the local network through a dynamically assigned IP provided by the DHCP (Dynamic Host Configuration Protocol). 

In this case our router acts as a DHCP server and assigns us an IP address within a range of addresses.

Dynamic IP addresses by DHCP have the advantage of giving us the freedom of not having to configure the devices, or make sure that each one has a different IP. Simply, turn on your computer, laptop, your mobile, your (... whatever ...) and the router is assigned IP without you worry about anything.

However, normally if we have a permanent installation we will want the IP address to be fixed. Because you will not be thankful that you are going to access your files, or turn on the lights of your house and you can not connect because the IP has changed, right?


Configuration


To configure a static IP we must ensure that it is outside the DHCP range (you will have to verify it in the configuration of your router) and that no other device is assigned the same IP.

To configure a static IP in Raspian we must edit the file /etc/dhcpcd.conf with the command:

If we look at the content of the file we will see some commented lines (they begin with '#') that have an example of static IP configuration

 To create our own static IP address, for example for the WiFi interface (wlan0), we copy the commented fragment and modify it so that it looks like this.

1
2
3
4
interface wlan0
static ip_address=192.168.1.200/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1


Being,

interface = Name of the interface that we want to configure

static ip_address = Fixed address we want (leave the / 24 at the end)

static routers = Address of the gateweay (of the router)

static domain_name_servers = Address of the DND server (usually the router). If we want more than one DNS server you can add them separator for a space.


Then we save the changes by pressing 'Ctrl + X' and then confirming with 'Y' and 'Enter'. Now we restart the Raspberry Pi with the command:


1
sudo reboot


Finally we verify that, effectively, we have the IP that we have configured running with the command


1
ifconfig wlan0


And we already have the static IP configuration.

Do you want more information?

Open Source technology allows you to develop your installations.

Just fill the form and we will contact you as soon as we can.

Send