2

I am trying to setup static IPs on my 5 raspberry PIs and there is no clear answer as to which configuration to choose and why.

As per a comment on one of the answers to this question How do I set up networking/WiFi/static IP address on Raspbian/Raspberry Pi OS?

Readers should do their homework before adopting the static ip configuration advocated by this answer. For example, the author of dhcpcd discourages use of static ip!! In man dhcpcd.conf he states, For IPv4, you should use the inform ipaddress option instead of setting a static address. Ask yourself why you should follow the recommendation in this answer when the author of dhcpcd says otherwise?

The configurations below all do the same thing but it isnt clear which is preferred.

Set via request

interface wlan0
request 192.168.68.20

Set via static ip

interface wlan0 
static ip_address=192.168.68.20/24 
static routers=192.168.68.1 
static domain_name_servers=192.168.68.1

Set via inform

interface wlan0
inform 192.168.68.20
7

2 Answers 2

1

I agree that How do I set up networking/WiFi/static IP address on Raspbian/Raspberry Pi OS? has the full answer. However, that answer is long and has many other important information.

TL;DR

TL;DR means "Too long, didn't read." This answer is a summery of information provided elsewhere.

Set via request

This is for the range of IP addresses assigned by the DHCP server. Most DHCP servers assign IP addresses from a defined range, say between 192.168.0.100 to 192.168.0.249. The request option politely asks the DHCP server to assign a specific address, say 192.168.0.120, within that range. The DHCP server may ignore the "request" if that IP address is already assigned to another device.

Set via inform

This option is for setting a static IP address outside the DHCP server range. Continuing with the example range of 192.168.0.100 to 192.168.0.249, setting the static IP address of 192.168.0.20 would be outside the DHCP server range.

Note, there is a bug that may fill up your Pi's MicroSD card with log entries if you use this option. See huge syslog filled with dhcpcd lines and Why does dhcpcd flood my logs with with useless messages when I use the `inform` option?

Set via static ip

This is similar to the inform option, but it is more primitive. That is, it works even when there is no DHCP server at the other end. For example, if you connect two Raspberry Pies directly with an Ethernet cable, and neither of the Pies have a DHCP server installed, you can use this option to assign static IP addresses to both the Pies.

What is a DHCP Server?

For most home network the DHCP server is the WiFi Router. You have to go into the "Advanced Setup" of the router using the web interface to see it. For example:

enter image description here

Your router's setup may look different.

Note, if you plan to use a mobile phone as a WiFi access point, then none of these options may work. A mobile phone's WiFi AP has a DHCP server but it does not follow the rules of a standard DHCP server and does not have any "out of range" addresses for static IP address assignments and does not honor any "requests".

A Router based option

You can reserve a specific IP address within the dynamic address range from within the DHCP server in the router. For this you will need to know the MAC address of the Ethernet (or WiFi) interface of the specific Pi you are trying to reserve an IP address for. For example:

enter image description here

My router allows scanning for MAC addresses and that may help you identify the Pi's Ethernet (or WiFi) interface's MAC address.

Note, if you do this, you will have to select IP addresses within the dynamically allowable IP address range, say 192.168.0.100 to 192.168.0.249.

Hope this helps

1
  • 1
    Excellent explanation of each method. Now I understand each's purpose. May 13 at 3:31
2

Excellent question! Here's my answer; a quick summary & details for those interested:

Quick Summary

First/Best Choice: Don't use a static IP address

Your RPi system comes with a network manager (dhcpcd) designed to work on most networks without a single tweak; "it just works" as they say.

Second Choice: Use inform or request options

My network has dynamic-configured hosts on it that have had the same IP address for over 3 yeears! DHCP-assigned IP addresses tend to be "sticky". If you feel the need to make them more-or-less permanent, use the inform or request options. The author of dhcpcd, who knows a little about how this protocol works, recommends inform, but see the However... section in the details below.

Third Choice: Use the static value configuration per man dhcpcd.conf

If you don't understand DHCP, don't choose this option. Back it up, and take the First or Second Choice - really.

Some Details and Background

First choice:

The first choice should always be: Don't use a static IP address - unless you really need one. When do I need one? Well, hardly ever... Quite a few think they need a static IP, but they don't. Static IPs seem to bring out the "knob dicker" in far too many users!

If your network is set up properly, your zero-conf networking will make your RPi very easy to find. It is also very easy to set up:

  1. Verify you have a unique entry in /etc/hostname. Don't use the default raspberrypi (unless you're only ever going to have a single one); use something like raspi3B, or bookcase-raspi - or something like that. A hostname should mean something to you.

  2. Make sure you have an entry for 127.0.1.1 in /etc/hosts. It should include your chosen hostname (from above) - like this:

127.0.1.1 raspi3B
-- OR --
127.0.1.1 bookcase-raspi

Having done this properly, you can always find your RPi on the network by referring to it as follows:

hostname.local -- or -- simply hostname for example:
ping raspi3B.local -- or -- ping raspi3B ssh pi@raspi3B.local
https://raspi3B.local

If you can find your host by its hostname, why would you want to use a fixed IP? Why not let DHCP do its job? Manual network configuration is drudgery - it's why DHCP was invented. Don't ne a luddite :)

Second choice:

If you have an RPi, and you are running Raspberry Pi OS (nee raspbian), your default DHCP client and network manager is called dhcpcd. You should get to know it - it does an important job for you, so ignore it at your risk.

To configure a static address for your RPi, you should RTFM. The system manual for dhcpcd may be called up from a terminal window very simply: man dhcpcd. There is a separate manual for dhcpcd's configuration file, located at /etc/dhcpcd.conf. Access the "man page" for the configuration file as follows: man dhcpcd.conf; it is here that you will find the instructions for configuring a static IP.

In man dhcpcd.conf the section static value contains the information we need. This seems to be the least-read item of documentation in all of Linux-dom. It lays out exactly how to set up a static configuration as follows (IPv6 omitted for clarity):

interface eth0
   static ip_address=192.168.0.10/24
   static broadcast_address=192.168.0.63
   static routers=192.168.0.1
   static domain_name_servers=192.168.0.1

So we see now that in addition to the IP address, there are other necessary items of information handed over to your RPi host during DHCP: broadcast address, router (gateway) and DNS. Everything your RPi host needs to find its way around the network. So a proper static config includes all of these items. Miss one of them, and the wheels come off... you're wasting your time posting a question here (or worse - somewhere else) wondering why your RPi isn't working... "it worked yesterday" is the most frequently whined complaint heard here.

But if you got to this point in man dhcpcd.conf, you've missed the most important statement in the manual re static confoguration. The author of dhcpcd says this:

For IPv4, you should use the inform ipaddress option instead of setting a static address.

That's a clear enough statement. It's a correct statement. It's correct because of the way the DHCP protocol is designed - see RFC2131 for details. In brief summary, the Internet Standard for DHCP states that static-configured hosts do not communicate with the DHCP server. Now, as an example, suppose that your ISP one day decides to use a new DNS server address, and you are running a static configuration. That's right - now your RPi may not be able to resolve host names on the Internet. Since you didn't read the manual carefully, you're back to wasting time - patching up self-inflicted wounds. This is only one handicap - there are others.

Using a static configuration means also that you must make an IP address reservation on your router/gateway/DHCP server. Since a static-configured host does not communicate with a DHCP server, the job of preventing address collisions falls on your to-do list. Believe it or not, this requirement escapes most users of the static configuration.

However...

While the author's admonition to use the inform option instead of a static configuration is spot-on, there is currently a bug in the implementation of the dhcpcd software distributed by the Raspberry Pi organization. This bug creates a tsunami of log messages when the inform option is enabled - I measured 8/second on a RPi 0W. A patch has been submitted to the upstream sources, the RPi maintainers were notified o/a 2 April, 2022 and you can find detailed instructions for patching your copy of dhcpcd here. Unfortunately, the patch has not found its way through the Raspberry Pi Organization's software maintenance system.

For this reason, you may prefer to use the request option instead of the inform option. There are differences between request and inform, but they won't be apparent in most use cases - refer to RFC 2131 for details.

Third choice:

Yeah - that's right - static configuration is the end of the line - the worst choice for almost all use-cases, but preferred by knob-dickers 10:1. If you think that you've found the use-case that requires a static configuration, I think you're probably wrong. But if you're smart enough to recognize that use case, then you're almost definitely well-informed; enough to not be asking the question here, saying "it worked yesterday"!

If you think you've detected a harsh or belligerent tone in this answer, I'll apologize for that now. I enjoy what I do here on SE; I have learned a lot here answering questions and helping users solve problems. But I've answered this question too many times to enjoy it. If that shows, I'll apologize, but the answer will be the same until DHCP is overhauled or replaced with something else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.