Excellent question! Here's my answer; a quick summary & details for those interested:
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
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
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
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
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:
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
bookcase-raspi - or something like that. A
hostname should mean something to you.
Make sure you have an entry for
/etc/hosts. It should include your chosen hostname (from above) - like this:
-- OR --
Having done this properly, you can always find your RPi on the network by referring to it as follows:
hostname.local -- or -- simply hostname
ping raspi3B.local -- or -- ping raspi3B
ssh [email protected]
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 :)
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.
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):
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.
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
inform, but they won't be apparent in most use cases - refer to RFC 2131 for details.
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.