Most of the existing networking tutorials are out of date and won't work on Raspberry Pi OS - Bookworm
2 Answers
How to setup Raspberry Pi OS Networking
In Bookworm NetworkManager
is the default networking configuration tool.
There is Raspberry Pi Ltd. documentation on Configuring Networking
This explains the common basic settings, but does not explain in detail advanced settings.
If you are using an Ethernet connection with a router there should be no configuration required and it should work out of the box.
The Pi3B+, Pi4 and Pi5 have Gigabit Ethernet interfaces and will only work on a Gigabit Ethernet (1000BASE-T) router if a 8 wire CAT 5E cable is used. Earlier Pi models which only supported 100BASE-T work over 6 wire cable.
If you preconfigure during the imaging process you can set the hostname, user/password, Locale, wireless networking and enable ssh and is recommended.
The rest of this tutorial is an introduction to manual configuration (particularly wireless networking) and advanced settings.
This is a work in progress and currently only describes a limited subset of
NetworkManager
capabilities.NetworkManager
has been in use in other OS for many years and there are many on line tutorials.
General
Each WiFi network has a separate config file in /etc/NetworkManager/system-connections/
in a well configured system these will have a 256bit WPA PSK rather than an ASCII passphrase.
Using the Desktop
Open the networking menu on the taskbar.
This should show any Ethernet connection and available WiFi networks.
An additional sub-menu at the bottom, Advanced Options allows you to
- Connect to a Hidden Wi-Fi Network
- Create WiFi Hotspot
- Add a VPN connection
- Connection Information
- Edit Connection
The Edit Connection menu will show available connections
Select a connection and use the +, - or ⚙︎ button to Add, Delete or Edit
The ⚙︎ will bring up another menu and the IPv4 or IPv6 lets you select a Method
Automatic(DHCP)
Automatic(DHCP) addresses only
Manual allows static
Link-Local only
Shared to other computers
Disabled
The Routes
Using the Command Line
There is a nmtui
program which presents a Curses menu with a simplified menu (which operates like raspi-config
).
NetworkManager TUI (Text User Interface)
- Edit a connection
- Activate a connection
- Set system hostname
You can use the nmcli
command to manage NetworkManager from the command line e.g.
nmcli dev wifi list
will scan for wireless networks.
sudo nmcli --ask dev wifi connect ssid
will connect to a network
nmcli connection show
shows existing connections
sudo nmcli connection modify [id | uuid | path] ipv4.route-metric nnn
will change the route metric
There are more examples in Using the Command Line
Prevent networkmanager
from configuring a gateway on an interface
If you want an interface to not install any default routes (often used for local devices) specify
sudo nmcli connection modify connection_name ipv4.never-default yes ipv6.never-default yes
Setting a Static address
If you have a network with a DHCP server you should not setup a static address, let the network do its job. If you want to have a known address reserve one on your router.
If you want to setup a standalone Pi or a server you can assign necessary attributes in Network Manager.
This can be done in different ways; the easiest is to use nmtui
which presents a Curses menu.
Use Edit a connection select a profile then Edit.
Navigate to IPv4 CONFIGURATION and change to Manual
You can set Addresses e.g. 192.168.2.20/24,
Gateway e.g. 192.168.2.1,
DNS Servers e.g. 8.8.8.8,
Search domains & Routing.
This is also possible using the GUI applet (which is similar) or using nmcli
To use nmcli
run a command to set up the IP address.
Next configure the default gateway.
Then set up the DNS server.
nmcli con mod eth0 ipv4.addresses 192.168.2.20/24
nmcli con mod eth0 ipv4.gateway 192.168.2.1
nmcli con mod eth0 ipv4.dns 8.8.8.8
Access Point (Hotspot)
It is easy to create an Access Point (Hotspot) on Network Manager.
The following will create a basic 2.4Gbps Hotspot named MyHotspot using ipv4 with ssid MySSID and password MyPSK
First create a connection named MyHotspot with ssid MySSID:-
sudo nmcli connection add type wifi ifname wlan0 con-name MyHotspot autoconnect yes ssid MySSID
Specify this is to be used as Access Point and wireless band and protocol:-
sudo nmcli connection modify MyHotspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
You can then configure WPA2-PSK security for the Access Point:
sudo nmcli connection modify MyHotspot wifi-sec.key-mgmt wpa-psk
and add a password MyPSK
sudo nmcli connection modify MyHotspot wifi-sec.psk MyPSK
-
Nice summary and needed with the switch to Network Manager. I suggest adding Cat 6 to your Cat 5E note. Cat 6 is now commonly available at similar prices. Also, since command line changes can disappear across a boot, please add a sentence about the persistence of changes made with nmtui and nmcli. Commented Jan 12 at 20:41
Bookworm defaults to "Wired connection 1" instead of eth0, so you need to modify each command line with "Wired connection 1" (with the quotation marks) for it to work
You need to add this otherwise your Pi will continue to use DHCP:
nmcli con mod "Wired connection 1" ipv4.method manual