Last modified on 1/7/2025
IP addresses can be assigned either dynamically by a rounter (automatic) or statically by the user (manual). In addition to the IP addres, the following must be specified:
Before the NetworkManager, a static ip address could easily be assigned to a network interface by specifying the 4 parameters in a configuration file (/etc/network/interfaces or /etc/dhcpcd.conf).
The NetworkManager, has similar network interface configuration files (NetworkManager/system-connections). However, the developers strongly advise against modifying them as the NetworkManager may change them.
The Dynamic Host Configuration Protocol (dhcp) is a protocol for automatically assigning IP addresses and other communications parameters to interfaces connected to the network. It uses a client-server architecture.
A hdcp client communicates with a dhcp server (usually the router) and obtains an IP addresses from the dhcp server. However, a dhcp client can request a static IP addresses from the server.
The hdcp server is usually a router. Almost all modern routers allow you to set a static IP address for interface by corelating the interface's MAC address to an IP address that the user specifies.
As of Raspberry Pi OS 12 (Bookworm), the default network interface manager is the NetworkManager. However, in the past the Raspberry Pi OS has used two other network managers:
From | To | Default | Network Configuration Files |
---|---|---|---|
10/2023 | Present | NetworkManager | /etc/NetworkManager/system-connections |
9/2015 | 10/2023 | hdcpcd | /etc/dhcpcd.conf [10] |
2/2012 | 9/2015 | ifupdown | /etc/network/interfaces or /etc/network/interfaces.d [10] |
Before the NetworkManager became default, the Raspberry Pi Foundation announced that it would be switching to the NetworkManager, and they provided code for you to optionally use it. During this period of time, there were three (3) network managers running at the same time.
Thankfully, the legacy network managers ifupdown and dhcpcd have been removed. Thus, the Raspberry Pi OS now only a single network manager, the NetworkManager.
To set up a static address for an Ethernet Interface, place the following in /etc/network/interfaces:
auto eth0
iface eth0 inet static
address 192.168.200.15
netmask 255.255.255.0
gateway 192.168.200.1
dns 1.1.1.1,23.253.163.53
Note, the dns statement is optional. For multiple dns servers, seperate them with a comma.
As of Nov 19, 2024, the Raspberry Pi OS no longer installs by default the package "ifupdown", which is required for systemd-networkd. To install the legacy ifupdown package:
sudo install apt ifupdown
To enable systemd-networkd:
sudo systemctl enable systemd-networkd
To disable the NetworkManager
sudo systemctl disable NetworkManager
The disadvance of disabling the NetworkManager is that the network icon at top left of the screen will not be displayed. By default the NetworkManager is not suppose to manage any networks that have a presents in interfaces or interfaces.d.
Reference: Raspberry Pi Forums - Re: Static IP with Bookworm - Murph9000 on Dec 29, 2024
In Debian 12, the default network manager depends on the type host:
It is believed this is due to how easy it to set up a static IP address by modifying the ifupdown network configuration file (/etc/network/interfaces [1]. However, for everything else the NetworkManager is easier.
On my HP EliteDesk computers only "ifupdown" is installed by default. Thus, Debian does a good job of not installing multiple network managers. However, Debian does allow the user to install the NetworkManager:
sudo apt update && sudo apt install network-manager
By default, the NetworkManager will not manage any network interface that has entries in /etc/network/interfaces.
This allows for some interfaces to be managed by ifupdown and other interfaces to be managed by the NetworkManager.
You can override the default and have the NetworkManager manage all the interfaces by changing the NetworkManager's configuration file: /etc/NetworkManager/NetworkManager.conf. Under [ifupdown], change managed=false to true.
systemctl status networkmanger
systemctl start networkmanger
systemctl stop networkmanger
systemctl restart networkmanger
systemctl enable networkmanger
systemctl disable networkmanger
Red Hat initiated the NetworkManager project in 2004. Today the NeworkworkManager is project is managed by the NetworkManager.dev, which is under the FreeDesktop.org. The main advantage of the NetworkManger is its ability to manage more complex networking configurations like bridges, bonds, and VLANs.
The NetworkManager is based on a concept of connection profiles. A connection profile contains a network configuration.
A Network Interface Card (NIC) can have more than one connection profile. Connection profiles have priority numbers between -999 and 999. The higher the number, the greater the priority. In the case of equal priority, the profile used last is chosen.
Since servers do not have a GUI, it is neccessary that their network interfaces be managed via the command line. The NetworkManager provides two ways of doing this.
The nmtui provides a text or terminal user interface that allows to user to fill in the IP address, network mast, gateway, and dns servers. It also allows the user to select or de-select other parameters. This is the easies method, but there are somethings that it will not handle. You envoke the nmtui with the command:
nmtui
The more powerful but less friendly alternate is to use the command line. Each command starts with "nmcli".
If you just enter:
nmcli
It will show the IP configuration for each interfaces.
$ nmcli connection modify eth1 ipv4.addr '192.168.6.66/24'
$ nmcli connection modify eth1 ipv4.gateway '192.168.6.1'
$ nmcli connection modify eth1 ipv4.dns '1.1.1.1,1.0.0.1'
Note that the IP address and the network mask have been merged into a single parameter (CIDR). Also note, that you can specify more than one dns server - seperated by commas.
nmcli con modify "Home Ethernet" ipv4.method manual ipv4.addresses 192.168.0.100/24 ipv4.gateway 192.168.0.1 ipv4.dns 8.8.4.4
The NetworkManager's GUI is not nearly as intutive as it should be.
The Network Manager does not fail gracefully. I attempted to set up a PC as a router without selecting the "method" as "Share with other computers", this would case the PC to not reboot or take a minute or two before it rebooted. After, I finally got the PC working as a router, tried to enable nordvpn autostart on the PC, and again, it would not reboot.
In the nm-gui, the prioriy of a connection profile can be changed, under the General Tab.
If you use the NetworkManager to manually set up a static IP address then to reach the Internet, you have to declare at least one dns server. You can use the same IP address as the gateway for the dns sever, and it will look upstream for a dns sever.
To setup a PC as a router, for the IPv4 Setting "Method" you need to select "Shared with other computers". This is not intutive!
However, it does work nicely and it sets up a DHCP server, the Network Address Translation (NAt) and masquerade for you (by making entries in nftables - see below).
You can then fill in the IPv4 address, the netmask, and the gateway. You can also fill in addition dns servers (optional).
Under IPv6 Seeting, you can set a static address or under Method disbable IPv6.
The nftabe code generated by Nftables is:
table ip filter { chain INPUT { type filter hook input priority filter; policy accept; } chain OUTPUT { type filter hook output priority filter; policy accept; } } table ip nm-shared-eth1 { chain nat_postrouting { type nat hook postrouting priority srcnat; policy accept; ip saddr 192.168.200.0/24 ip daddr != 192.168.200.0/24 masquerade } chain filter_forward { type filter hook forward priority filter; policy accept; ip daddr 192.168.200.0/24 oifname "eth1" ct state { established, related } accept ip saddr 192.168.200.0/24 iifname "eth1" accept iifname "eth1" oifname "eth1" accept iifname "eth1" reject oifname "eth1" reject } }
The one problem I am having is that the host behind rounter can ssh into other host on the network, but the other hosts can not ssh into the host behind the router. This might be what it should do! That is,this is what you would want if the router was facing the Internet and not a LAN.
I have found what I consider to be a major problem. If there is a host connected to the software rounter then the software rounter can not connect to the Internet nor the host that is connected via the software router. You can reboot the host that is connected to the software router, and everything will work again - You do not have to reboot the software router. Can this be fixed in the resolver?
The NetworkManger does work well with Nordvpn. If nordvpn is set to autoconnect, then the NetworkManger will only setup IPv4 addresses. If Nordvpn is set to disable autoconnect, then the NetworkManager will assign both IPv4 and IPv6 addresses. The only problem with this is you cannot manually connect to Nordvpn. This is much better than I antisipated. ArchLinux's documentation (section 5.7.2 in Reference 17), which may be old, IPv6 would be enabled and it would bypassed the VPN.
References: