Skip to content

Instantly share code, notes, and snippets.

@bergpb
Forked from hivian/raspberry-pi-static-ip.md
Created October 30, 2024 12:41
Show Gist options
  • Save bergpb/286466fcd15de558e426422fa90a2a75 to your computer and use it in GitHub Desktop.
Save bergpb/286466fcd15de558e426422fa90a2a75 to your computer and use it in GitHub Desktop.
Set a static IP Address on Raspberry Pi OS Bookworm (october 2023 update)

Use static network IP address on Raspberry PI Bookworm

With the release of Raspberry Pi OS Bookworm, networking on the Raspberry Pi was changed to use NetworkManager as the standard controller for networking, replacing the previous dhcpcd system. NetworkManager includes a command line tool called "nmcli," which can control NetworkManager and report on the network status.

Step 1

Display the list of network interfaces:

sudo nmcli -p connection show

You should see a list like this:

======================================
  NetworkManager connection profiles
======================================
NAME                UUID                                  TYPE      DEVICE
----------------------------------------------------------------------------
Wired connection 1  bd220d18-7d6a-36a5-9820-4f67de2c01fc  ethernet  eth0
mywifi              2359440b-8991-4c86-a905-b011dced4587  wifi      wlan0
lo                  c29ba7c5-98ff-4fa0-8d8e-06b30b8ec384  loopback  lo

Step 2

Set the Ip address, Gateway and DNS Server (both can be provided by the router and have the same address) for your ethernet or/and wifi connection.

sudo nmcli c mod "Wired connection 1" ipv4.addresses 192.168.1.75/24 ipv4.method manual

sudo nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.254

sudo nmcli con mod "Wired connection 1" ipv4.dns 192.168.1.254

If you want to use multiple DNS servers, you can add them separated by commas; for example, to use Google's DNS servers, use the following.

sudo nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8,8.8.4.4"

The same method can be used for adding multiple IP addresses to the same network connection; for example, the following command would assign IP addresses 10.0.0.220, 10.0.0.221 and 10.0.0.222.

sudo nmcli c mod "Wired connection 1" ipv4.addresses "10.0.0.220/24, 10.0.0.221/24, 10.0.0.222/24" ipv4.method manual

Step 3

When you have finished updating the network settings on your Raspberry Pi, you can restart the network connection with the following command.

sudo nmcli c down "Wired connection 1" && sudo nmcli c up "Wired connection 1"

Note: If you are using SSH to connect to your Raspberry Pi, running the above command will cause the SSH session to end if the IP address changes.

To revert the network connection from static to automatic, run the following commands:

sudo nmcli con modify "Wired connection 1" ipv4.method auto

sudo nmcli c down "Wired connection 1" && sudo nmcli c up "Wired connection 1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment