Set a static IP address with nmtui on Raspberry Pi OS 12 'Bookworm'
[Reference Link]
Old advice for setting a Raspberry Pi IP address to a static IP on the Pi itself said to edit the /etc/dhcpcd.conf
file, and add it there.
But on Raspberry Pi OS 12 and later, dhcpcd
is no longer used, everything goes through Network Manager, which is configured via nmcli
or nmtui
. If you're booting into the Pi OS desktop environment, editing the IP settings there is pretty easy.
You can also configure a static IP entirely via nmcli
without using the UI; see this article on nmcli` from Cyberciti.biz.
But setting a static IP via the command line is a little different.
Install nmtui
The nmtui
Command is Part of the Network-Manager Package, to install use this Commands:
# For Debian-based distributions
sudo apt-get install network-manager
# For RPM-based distributions
sudo yum install NetworkManager-tui
Check for Device Status
First, get the interface information—you can get a list of all interfaces with nmcli device status
:
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected Wired connection 1
docker_gwbridge bridge connected (externally) docker_gwbridge
lo loopback connected (externally) lo
docker0 bridge connected (externally) docker0
wlan0 wifi disconnected --
In my case, I want to set an IP on eth0
, the built-in Ethernet.
Set static IPv4 Address
I can get all the current information about that port with nmcli device show eth0
, and I can edit the connection using the terminal UI (nmtui
):
$ sudo nmtui edit "Wired connection 1"
Go through each setting adding in at least an IPv4 address, Gateway, and DNS Server, for example:
The IP's are just for Show. Change them to fit your Setup.
Then go down to the bottom and select 'OK'.
This saves the static IP configuration, but doesn't apply it immediately. To apply the changes, you need to restart NetworkManager:
$ sudo systemctl restart NetworkManager
Then if you run nmcli device show eth0
, you should see the new IP address (the old one might still be attached to the interface at the same time until you reboot):
root@swarmpi1:~# nmcli device show eth0
GENERAL.DEVICE: eth0
GENERAL.TYPE: ethernet
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: Wired connection 1
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.0.0/24
IP4.GATEWAY: 192.168.0.0
You successfully changed the IPv4 Address from your PI :)