Raspberry Pi Network Manager
Setting up a Static IP Address (an IP address that does not change)
The Raspberry Pi OS Bookworm version now uses Network Manager (nm) by default for network configuration, instead of dhcpcd which was used previously.
Network Manager manages the network based on "connections".
On a fresh system, it creates a default wired connection called "Wired Connection 1" and a default wireless connection based on the SSID provided during setup.
Check Active Network Services
To confirm which networking service your system is using, you can check for active network-related services:
systemctl list-units --type=service | grep -i network
Output
networking.service loaded active exited
NetworkManager-dispatcher.service loaded active running Network Manager
NetworkManager-wait-online.service loaded active exited Network Manager
NetworkManager.service loaded active running Network Manager
The output shows the Raspberry Pi is using NetworkManager
as its primary tool for managing network connections.
This is indicated by the presence of NetworkManager.service
marked as loaded active running
. Additionally, you have networking.service
which typically handles traditional networking scripts but seems to be managing less in this setup given that NetworkManager
is also active.
Key Points about Network Manager
Connection information is stored in /etc/NetworkManager/system-connections/*.nmconnection files which must have 600 file permissions. Editing these requires restarting the connection or rebooting.
The nmcli command line tool allows managing connections - viewing attributes, bringing connections up/down, modifying attributes, renaming, etc. Tab completion is supported.
nmtui provides a text user interface as an easier alternative to nmcli for complex setups without needing to remember all the nmcli details.
Connection files can be copied between systems for reuse. The UUIDs don't seem to cause issues.
Enabling a captive portal connection automatically enables IP forwarding, which may need to be manually disabled using sysctl if undesired.
For headless setup, it's recommended to switch from dhcpcd to NetworkManager on a running Bullseye system first before doing a dist-upgrade to Bookworm. Directly switching using raspi-config in a headless setup can lead to loss of network access.
Overall, Network Manager is seen as more user-friendly and a standard across Linux distros compared to the previous dhcpcd setup on Raspberry Pi OS. But it has a learning curve for those used to the old way.
If Network Manager is not installed
The last task we need to complete before we enable Network Manager on our Raspberry Pi is to install the actual software.
To install the “network-manager
” package to your device, run the command below in the terminal.
sudo apt install network-manager
Set Static IP via NetworkManager
Here’s how you can proceed with setting a static IP address through NetworkManager
:
Requirements
Raspberry Pi running Raspberry Pi OS (Debian-based Linux)
Access to a terminal or SSH session on the Raspberry Pi
NetworkManager Installed
Checking Network Manager status: To verify if Network Manager is running, use the following command:
nmcli -t -f RUNNING general
We need to collect four important pieces of information first
[your-static-ip]
[router-ip]
[dns-ip]
[dns-search-domain]
To find the placeholder details for configuring a static IP address using Network Manager, you need to gather the following information:
Static IP Address ([
your-static-ip
]
)
[
your-static-ip
]
)Determine the static IP address you want to assign to your device.
It should be an available IP address within your network's range.
Example:
192.168.1.100
Check the current IP address
hostname -I
Note down the IP address displayed.
For example: 192.168.68.64
Subnet Mask
The subnet mask is usually denoted by
/24
for a typical home network, which corresponds to255.255.255.0
.Adjust the subnet mask according to your network's configuration.
ip addr show wlan0
The output:
wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 2c:cf:67:2c:91:1a brd ff:ff:ff:ff:ff:ff
inet 192.168.68.67/22 brd 192.168.71.255 scope global dynamic noprefixroute wlan0
valid_lft 5851sec preferred_lft 5851sec
inet6 fe80::62a8:8dd9:cb43:c3b1/64 scope link noprefixroute
valid_lft forever preferred_lft forever
From the output inet 192.168.68.64/22
, the /22
is the CIDR (Classless Inter-Domain Routing) notation that represents the subnet mask.
This notation indicates that the first 22 bits of the IP address are used to identify the network part of the address, with the remaining bits (out of 32 in total for IPv4) available for host addresses.
Identifying all network interfaces
First, get a detailed list of all interfaces with nmcli device status
:
nmcli device status
The output
DEVICE TYPE STATE CONNECTION
wlan0 wifi connected preconfigured
lo loopback connected (externally) lo
docker0 bridge connected (externally) docker0
p2p-dev-wlan0 wifi-p2p disconnected --
eth0 ethernet unavailable --
What does the output mean?
wlan0
Type: wifi (Wireless LAN interface)
State: connected
Connection: preconfigured
Explanation: The wireless network interface
wlan0
is currently connected to a WiFi network using a connection profile named "preconfigured". This indicates that your Raspberry Pi is actively connected to a wireless network using this profile.
lo
Type: loopback
State: connected (externally)
Connection: lo
Explanation: The loopback interface (
lo
) is always considered connected. It's used by the system for internal communications (e.g., communicating with itself). "Connected (externally)" here indicates that it’s managed outside of the typical network management frameworks but still operational for its purposes.
docker0
Type: bridge
State: connected (externally)
Connection: docker0
Explanation:
docker0
is a network bridge used by Docker to handle communications between Docker containers and the host machine. Similar tolo
, "connected (externally)" suggests it’s managed by Docker and not directly by standard network management tools.
eth0
Type: ethernet
State: unavailable
Connection: --
Explanation: The Ethernet interface
eth0
is marked as unavailable, which means there is no Ethernet cable connected or the interface is not configured/activated, making it not ready for use.
Which Network Interface to use?
To set up a static IP address on your Raspberry Pi, you should choose the network interface that is actively connected to the network and that you typically use to communicate over your network.
Based on our configuration, the best candidate is:
wlan0
Type: wifi (Wireless LAN interface)
State: connected
Connection: preconfigured
Reasons to Choose wlan0
Active Connection: It is currently connected to a WiFi network, which means it's actively being used to connect your Raspberry Pi to the network.
WiFi Access: As it's a WiFi connection, setting a static IP address can be particularly useful if you frequently connect to this Raspberry Pi remotely, as WiFi-assigned IPs can change more frequently due to the dynamic nature of DHCP allocations by routers.
Modify Network Connections Using nmcli
Then, let's find the name of the connection you want to configure. Again use the command:
nmcli device status
The output
NAME UUID TYPE DEVICE
preconfigured 8c6e2331-08f0-4e8e-a392-710af4dc3e5c wifi wlan0
lo 12d503fa-b077-41fb-a0b4-4229c0a9cdfa loopback lo
docker0 b3300958-c4e3-4d75-826f-7c787a2070ed bridge docker0
Wired connection 1 c2e4dd17-2c70-35cf-a746-151f5ba9d0f6 ethernet --
We have decided to configure the wireless connection and its default name is 'preconfigured'
NAME UUID TYPE DEVICE
preconfigured 8c6e2331-08f0-4e8e-a392-710af4dc3e5c wifi wlan0
Gateway IP Address ([
router-ip
]
)
[
router-ip
]
)Find the IP address of your network's gateway (router).
It is usually the first IP address in your network's range.
Example:
192.168.1.1
This is how we identify the default network interface and gateway
ip r | grep default
This command will show the default gateway used by the Raspberry Pi and the interface it is connected through, such as eth0
for Ethernet or wlan0
for Wi-Fi.
Here is the output from our Raspberry Pi
default via 192.168.68.1 dev wlan0 proto dhcp src 192.168.68.67 metric 600
This indicates that your default gateway IP address is 192.168.68.1.
This is the IP address of the router your Raspberry Pi communicates with for accessing networks outside your local network, such as the internet.
dev wlan0: This specifies that the network device used for this connection is wlan0
, which is typically a WiFi interface on the Raspberry Pi.
proto dhcp: This tells you that the IP address was assigned via DHCP (Dynamic Host Configuration Protocol), which means the IP configuration is dynamically assigned by your network's DHCP server (usually your router).
src 192.168.68.67: This is the current IP address assigned to your Raspberry Pi on the network.
DNS Server IP Address
DNS Server IP Address ([dns-ip]
):
Determine the IP address of your DNS server.
You can use the IP address of your router if it acts as a DNS server, or you can use public DNS servers like Google's DNS (
8.8.8.8
or8.8.4.4
).Example:
192.168.1.1
or8.8.8.8
Using NetworkManager you can use the nmcli
command to find DNS settings:
nmcli dev show wlan0 | grep 'IP4.DNS'
This command will output the DNS servers configured for the wlan0
interface.
IP4.DNS[1]: 202.142.142.142
IP4.DNS[2]: 202.142.142.242
The command nmcli dev show wlan0 | grep 'IP4.DNS'
does the following:
nmcli dev show wlan0
: This command is used to display detailed information about the network device named wlan0
, which is typically the wireless network interface.
|
: This is the pipe symbol, which is used to pass the output of the previous command as input to the next command.
grep 'IP4.DNS'
: The grep
command is used to search for specific patterns within the output. In this case, it searches for the pattern 'IP4.DNS'
in the output of the nmcli dev show wlan0
command.
IP4.DNS[1]: 202.142.142.142
IP4.DNS[2]: 202.142.142.242
These lines indicate the DNS (Domain Name System) server IP addresses that are currently assigned to the wlan0
interface. In this case, there are two DNS servers configured:
IP4.DNS[1]
: The first DNS server has the IP address202.142.142.142
.IP4.DNS[2]
: The second DNS server has the IP address202.142.142.242
.
These DNS server IP addresses are used by the system to resolve domain names to their corresponding IP addresses when accessing network resources or browsing the internet.
By using the nmcli dev show
command with grep
, you can quickly retrieve specific information about a network interface, such as the assigned DNS servers, without displaying all the other details provided by nmcli
.
Once you have the connection name, modify its settings
nmcli con mod "Connection Name" ipv4.addresses [your-static-ip]/24 ipv4.gateway [router-ip] ipv4.dns [dns-ip] ipv4.dns-search [dns-search-domain] ipv4.method manual
[your-static-ip] -
192.168.68.67
[router-ip] -
192.168.68.1
[dns-ip] -
202.142.142.142
[dns-search-domain]
Not relevant
Based on the information you provided, you can use the following command to configure the static IP address using Network Manager:
sudo nmcli con mod "will-wifi" ipv4.addresses 192.168.68.67/24 ipv4.gateway 192.168.68.1 ipv4.dns 202.142.142.142 ipv4.method manual
We will replace "Connection Name" with "will-wifi' -which is the actual name of the connection you want to modify.
You can find the connection name by running nmcli connection show
.
Here's a breakdown of the command:
nmcli con mod
: This command is used to modify an existing network connection."Connection Name"
: Replace this with the actual name of the connection you want to modify - 'will-wifi'.ipv4.addresses 192.168.68.67/24
: This sets the static IP address to192.168.68.67
with a subnet mask of/24
(equivalent to255.255.255.0
).ipv4.gateway 192.168.68.1
: This sets the gateway IP address to192.168.68.1
.ipv4.dns 202.142.142.142
: This sets the DNS server IP address to202.142.142.142
.ipv4.method manual
: This sets the IPv4 configuration method to manual, indicating that you want to use a static IP address.
Note that you haven't provided a value for [dns-search-domain]
, so I haven't included the ipv4.dns-search
option in the command. If you have a specific DNS search domain you want to use, you can add it to the command like this:
nmcli con mod "will-wifi" ipv4.addresses 192.168.68.67/24 ipv4.gateway 192.168.68.1 ipv4.dns 202.142.142.142 ipv4.dns-search example.com ipv4.method manual
After running the command, the static IP configuration will be applied to the specified connection.
To activate the changes, you can either bring the connection down and up again:
sudo nmcli con down "will-wifi"
sudo nmcli con up "will-wifi"
Or, you can reboot your system to ensure the changes take effect:
sudo reboot
After applying the changes, your device should have the specified static IP address (192.168.68.67
) configured through Network Manager.
nmcli device status
The output
DEVICE TYPE STATE CONNECTION
wlan0 wifi connected will-wifi
lo loopback connected (externally) lo
docker0 bridge connected (externally) docker0
p2p-dev-wlan0 wifi-p2p disconnected --
end0 ethernet unavailable --
Changing Connection Name
To change the connection name using Network Manager, you can use the nmcli
command with the connection modify
or connection edit
option. Here's how you can change the connection name:
Using connection modify
nmcli connection modify "Old Connection Name" connection.id "New Connection Name"
Replace "Old Connection Name"
with the current name of the connection you want to modify, and "New Connection Name"
with the desired new name for the connection. For example, to rename the connection "preconfigured" to "will-wifi":
nmcli connection modify "preconfigured" connection.id "will-wifi"
Once you have gathered these details, you can modify the connection using the nmcli
command:
nmcli con mod "will-wifi" ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns 192.168.1.1 ipv4.dns-search example.com ipv4.method manual
Make sure to replace "Connection Name"
with the actual name of your connection and the placeholders with the corresponding values you found.
To apply the changes, you can either bring the connection down and up again:
nmcli con down "Connection Name"
nmcli con up "Connection Name"
Or, you can reboot your system to ensure the changes take effect:
sudo reboot
After applying the changes, your device should have the specified static IP address configured through Network Manager.
Check the IP Configuration
To verify the changes:
ip addr show
Restart NetworkManager Service
If you want to make sure all settings are correctly applied or need to refresh the NetworkManager:
sudo systemctl restart NetworkManager
Troubleshooting Tips
Ensure that the connection name and parameters you use with
nmcli
match exactly what’s required for your network configuration.Use
nmcli
to list detailed information about a connection, which can help in troubleshooting:
nmcli con show "will-wifi"
Sometimes changes might not take effect until the network service is restarted or the device is rebooted.
Verify the Configuration
After your Raspberry Pi reboots, check that the static IP address is correctly assigned:
hostname -I
You should see the static IP address you configured.
Conclusion
Setting a static IP address makes your Raspberry Pi accessible consistently at the same address, which is particularly useful for network applications like file servers or media centres.
By following these steps, you've ensured that your Raspberry Pi will retain the same IP address across reboots, making it easier to connect and manage remotely.
Last updated
Was this helpful?