tkykw838861
Posts: 5
Joined: Thu Feb 15, 2024 12:47 pm

How to setup static IP address on Raspberry Pi OS 64bit bookworm

Tue Feb 20, 2024 3:22 pm

I'm trying to setup the static IP address for my local IP address.

I checked with the Google search that there is the config file in /etc/dhcpcd.conf ,
but I could not find that path and the config file such like that.

How should I change a IP config file?

Please give me a procedure how to setup the static IP address.

MiscBits
Posts: 2015
Joined: Wed Jan 27, 2021 12:48 pm

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Tue Feb 20, 2024 3:27 pm

Bookworm uses Network Manager not dhcpcd - you may have missed the news back in October https://www.raspberrypi.com/news/bookwo ... rry-pi-os/

You can use the command line tool sudo nmtui to set things up or the command line nmcli command.

There are a few postings on this forum or the web that will help such as https://www.abelectronics.co.uk/kb/arti ... s-bookworm

Please make a note of the commands you use and their response just incase things go wrong and you need more help.

I would say that's its very rare that you need o set a static address on the device - it is way better to set them on your DHCP server (though I have had remote sites where this was needed).
I would tell you a joke about UDP but you may not get it.

User avatar
jahboater
Posts: 8895
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Tue Feb 20, 2024 4:27 pm

You may just create a file
/etc/network/interfaces.d/eth0
containing something like:

Code: Select all

allow-hotplug eth0
iface eth0 inet static
address 192.168.0.NNN/24
#network 10.0.0.0
netmask 255.255.255.0
gateway 192.168.0.1
Particularly useful if you need to do this in advance (before the first boot) for a headless Pi perhaps.
You can add the eth0 file to the micro SD card, just after you have copied the OS image on.

User avatar
thagrol
Posts: 11314
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Tue Feb 20, 2024 4:57 pm

If you want to stick with network manager the tools you'd use are nmcli or nmtui. The former is pure commandline, the latter uses a text menu based interface.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

drgeoff
Posts: 14039
Joined: Wed Jan 25, 2012 6:39 pm

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Tue Feb 20, 2024 5:35 pm

jahboater wrote:
Tue Feb 20, 2024 4:27 pm
You may just create a file
/etc/network/interfaces.d/eth0
containing something like:

Code: Select all

allow-hotplug eth0
iface eth0 inet static
address 192.168.0.NNN/24
#network 10.0.0.0
netmask 255.255.255.0
gateway 192.168.0.1
Particularly useful if you need to do this in advance (before the first boot) for a headless Pi perhaps.
You can add the eth0 file to the micro SD card, just after you have copied the OS image on.
But not so useful if you only have a Windows PC which cannot access the partition in which that file needs to be placed. :(
Quis custodiet ipsos custodes?

User avatar
thagrol
Posts: 11314
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Tue Feb 20, 2024 6:51 pm

drgeoff wrote:
Tue Feb 20, 2024 5:35 pm
jahboater wrote:
Tue Feb 20, 2024 4:27 pm
You can add the eth0 file to the micro SD card, just after you have copied the OS image on.
But not so useful if you only have a Windows PC which cannot access the partition in which that file needs to be placed. :(

Indeed. But if we're talking about before first boot, you can modify firstrun.sh (which is on the boot partition) to do it: Bookworm Point to Point Ethernet (inc g_ether)
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

MiscBits
Posts: 2015
Joined: Wed Jan 27, 2021 12:48 pm

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Wed Feb 21, 2024 12:16 am

jahboater wrote:
Tue Feb 20, 2024 4:27 pm
You may just create a file
...
The NM creators strongly recommend you do not create the files directly but use the package tools (i.e. they reserve the right to change the file use / layout / names etc).

Not been caught on NM (yet) but have been on a couple of application packages in my time :oops:

Edited 21/02 - refer to post below.
Last edited by MiscBits on Wed Feb 21, 2024 12:47 pm, edited 1 time in total.
I would tell you a joke about UDP but you may not get it.

User avatar
jahboater
Posts: 8895
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Wed Feb 21, 2024 12:37 am

MiscBits wrote:
Wed Feb 21, 2024 12:16 am
The NM creators strongly recommend you do not create the files directly but use the package tools (i.e. they reserve the right to change the file use / layout / names etc).
How do they expect you to do that when the Pi is not running (before the first boot) ?

User avatar
thagrol
Posts: 11314
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Wed Feb 21, 2024 1:16 am

MiscBits wrote:
Wed Feb 21, 2024 12:16 am
jahboater wrote:
Tue Feb 20, 2024 4:27 pm
You may just create a file
...
The NM creators strongly recommend you do not create the files directly but use the package tools (i.e. they reserve the right to change the file use / layout / names etc).

Are they saying that about /etc/network/interfaces[.d/*] or /etc/NetworkManager/system-connections/*? AIUI, in a default RPiOS Bookworm installation the only thing NM does with the former is scan them for which interfaces it should ignore.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

MiscBits
Posts: 2015
Joined: Wed Jan 27, 2021 12:48 pm

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Wed Feb 21, 2024 12:45 pm

I thought it was strange (dates from pre? Bullseye notes).

The notes on the dev page now state:
If a default NetworkManager.conf is provided by your distribution's packages, you should not modify it, since your changes may get overwritten by package updates
and
NetworkManager can overwrite certain user configuration options via D-Bus or other internal operations. In this case it writes those changes to /var/lib/NetworkManager/NetworkManager-intern.conf. This file is not intended to be modified by the user, but it is read last and can shadow user configuration from NetworkManager.conf
As for first run:
Instead, you can add additional .conf files to the /etc/NetworkManager/conf.d directory. These will be read in order, with later files overriding earlier ones. Packages might install further configuration snippets to /usr/lib/NetworkManager/conf.d. This directory is parsed first, even before NetworkManager.conf. Scripts can also put per-boot configuration into /run/NetworkManager/conf.d. This directory is parsed second, also before NetworkManager.conf. The loading of a file /run/NetworkManager/conf.d/name.conf can be prevented by adding a file /etc/NetworkManager/conf.d/name.conf. Likewise, a file /usr/lib/NetworkManager/conf.d/name.conf can be shadowed by putting a file of the same name to either /etc/NetworkManager/conf.d or /run/NetworkManager/conf.d.
I'll edit my post above as this seems to be a moving target (my bad).
I would tell you a joke about UDP but you may not get it.

tkykw838861
Posts: 5
Joined: Thu Feb 15, 2024 12:47 pm

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Thu Feb 22, 2024 12:31 am

Thank you so much for all kind replies.

If I would like to set the static IP address for Wireless LAN,
so what should I command for this?

I change the following from eth0 to wlan0 only,
Is that correct?

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.NNN/24
#network 10.0.0.0
netmask 255.255.255.0
gateway 192.168.0.1

pluffmud
Posts: 12
Joined: Thu Jul 27, 2023 3:12 pm

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Sun Feb 25, 2024 3:42 pm

The static ip should probably of the form "192.168.0.nnn/32"

see https://unix.stackexchange.com/question ... sing-nmcli

User avatar
thagrol
Posts: 11314
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Sun Feb 25, 2024 4:04 pm

pluffmud wrote:
Sun Feb 25, 2024 3:42 pm
The static ip should probably of the form "192.168.0.nnn/32"

see https://unix.stackexchange.com/question ... sing-nmcli
No.

It varies with the subnet in use. Officially it's 192.168.0.0/16. I'm not sure but I suspect a /32 netmask isn't actually a good idea as it means the entire address specifies the subnet and none of its bits the host.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
thagrol
Posts: 11314
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Sun Feb 25, 2024 4:05 pm

tkykw838861 wrote:
Thu Feb 22, 2024 12:31 am
Thank you so much for all kind replies.

If I would like to set the static IP address for Wireless LAN,
so what should I command for this?

I change the following from eth0 to wlan0 only,
Is that correct?

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.NNN/24
#network 10.0.0.0
netmask 255.255.255.0
gateway 192.168.0.1

You need to add in the wpa_supplicant ttuff but I've no idea how to do that on Bookworm.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

pluffmud
Posts: 12
Joined: Thu Jul 27, 2023 3:12 pm

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Sun Feb 25, 2024 4:07 pm

so I guess my 2 vlans created via nmcli which lists the static ips in that fashion are not actually working ? weird

User avatar
thagrol
Posts: 11314
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Sun Feb 25, 2024 4:25 pm

pluffmud wrote:
Sun Feb 25, 2024 4:07 pm
so I guess my 2 vlans created via nmcli which lists the static ips in that fashion are not actually working ? weird

Not necessarily. I said I wasn't sure...
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

angus1024
Posts: 21
Joined: Thu May 10, 2018 6:10 am

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Wed Mar 13, 2024 11:14 pm

I put some effort and found the static address can be set in Bookworm using network manager = nmcli. It is necessary to set the address, gateway(=ip address of box sitting between local network and www) and dns.It can work for both ethernet (eth0) and wifi (wlan0). You can find out names and status using commands
sudo nmcli c , sudo nmcli d , ifconfig

For me -changing the wifi address to 192.168.0.54 was
sudo nmcli c mod "preconfigured" ipv4.addresses 192.168.0.54/24 ipv4.method manual
sudo nmcli c mod "preconfigured" ipv4.gateway 192.168.0.1
sudo nmcli c mod "preconfigured" ipv4.dns "8.8.8.8,8.8.4.4"
and boot.

setting ethernet to 192.168.0.55 was

sudo nmcli c mod "Wired connection 1" ipv4.addresses 192.168.0.55/24 ipv4.method manual
sudo nmcli c mod "Wired connection 1" ipv4.gateway 192.168.0.1
sudo nmcli c mod "Wired connection 1" ipv4.dns "8.8.8.8,8.8.4.4"


I found that both appeared that both connections worked at the same time on my raspberrypi (!). consider command
hostname -I

ethernet and wifi can be turned on/off using ifconfig (worked for me):

sudo ifconfig eth0 up
sudo ifconfig eth0 down
sudo ifconfig wlan0 up
sudo ifconfig wlan0 down

I found this link useful but they selected a different dns address to that I use above and found to work:
https://www.abelectronics.co.uk/kb/arti ... -bookworm

Thanks - hope its useful - likely trivial
angus1024

User avatar
AndyD
Posts: 2468
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia

Re: How to setup static IP address on Raspberry Pi OS 64bit bookworm

Thu Mar 14, 2024 6:53 am

Jeff Geerling recently put up a blog post: Set a static IP address with nmtui on Raspberry Pi OS 12 'Bookworm' that looks very useful.

Return to “Networking and servers”