Debian Bookworm uses systemd-networkd by default, replacing the legacy /etc/network/interfaces file. If your static IP fails to assign, it is likely because you edited the old configuration file while systemd-networkd manages the network via .network files in /etc/systemd/network/. Switching to the correct backend resolves the loopback assignment issue immediately.
Understanding the Network Backend Shift
The transition from Debian 11 (Bullseye) to Debian 12 (Bookworm) introduced a significant change in how network interfaces are managed. Previously, administrators relied onifupdown, which used text-based configurations in /etc/network/interfaces. In Bookworm, systemd-networkd is the primary network manager for server installations. This service reads configuration files with the .network extension located in /etc/systemd/network/.
If you followed a tutorial designed for older Debian versions or Ubuntu, you may have modified /etc/network/interfaces. While this file still exists, it is no longer processed by default unless you explicitly install and enable the ifupdown package. Consequently, any static IP entries placed there are ignored by the system, leading to the symptoms where the interface remains unconfigured or falls back to DHCP.
This shift ensures that network configuration is integrated more tightly with the systemd ecosystem, allowing for better dependency management and state tracking. However, it requires a different approach to defining static addresses, routes, and DNS servers. Understanding this architectural change is the first step in troubleshooting why your public IP address is not persisting across reboots or why the loopback address appears incorrect.
Verifying the Active Network Manager
Before making changes, you must confirm which service is currently controlling your network interfaces. You can check the status ofsystemd-networkd using the following command:
systemctl status systemd-networkd
If the service is active and running, it is managing your connections. If it is inactive or failed, the system might be falling back to other managers like NetworkManager or ifupdown, depending on the installation type. For a headless server, systemd-networkd is the standard. You can also list all network interfaces and their current states with:
networkctl status
This command provides detailed information about each interface, including whether it is configured statically, dynamically via DHCP, or in an uninitialized state. If the output shows "unmanaged" for your primary interface, it confirms that systemd-networkd is not processing its configuration correctly, often due to missing or malformed .network files.
Configuring Static IP with systemd-networkd
To properly configure a static IP address, you need to create or edit a.network file in /etc/systemd/network/. The filename should correspond to the interface name, such as eth0.network or ens3.network. If you are unsure of the exact interface name, use ip link to identify it.
Create the configuration file using a text editor like nano or vim:
sudo nano /etc/systemd/network/eth0.network
Inside this file, you define the match criteria and the link settings. A typical static configuration looks like this:
[Match]
Name=eth0
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=1.1.1.1
The [Match] section ensures the configuration applies only to the specified interface. The [Network] section defines the static address, netmask (via CIDR notation), gateway, and DNS resolvers. Replace eth0 with your actual interface name, and adjust the IP address, gateway, and DNS values to match your network environment.
After saving the file, you must restart the systemd-networkd service to apply the changes:
sudo systemctl restart systemd-networkd
Then, verify that the interface has obtained the correct IP address using ip addr show eth0. If the address appears correctly, the configuration is successful. If not, check the journal logs for errors:
journalctl -u systemd-networkd -f
This log stream will reveal syntax errors or permission issues preventing the configuration from loading. Common mistakes include typos in the interface name or invalid IP formats.
Handling Conflicting Configurations
Sometimes, residual configurations from previous setups can interfere withsystemd-networkd. If you previously edited /etc/network/interfaces, ensure that the ifupdown package is not installed or enabled, as it might conflict with systemd-networkd. However, do not remove ifupdown blindly if other services depend on it. Instead, simply ensure that /etc/network/interfaces does not contain directives for your primary interface, or comment them out.
Additionally, check if NetworkManager is running. On server installations, NetworkManager is often disabled, but if it is active, it may take control of the interface before systemd-networkd can bind to it. You can disable NetworkManager if it is not needed:
sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager
This ensures that systemd-networkd remains the sole manager of the network interface, preventing race conditions during boot.
Troubleshooting Common Issues
Even with correct configuration files, issues can arise due to caching or service dependencies. One common problem is thatsystemd-resolved handles DNS resolution separately from systemd-networkd. If your DNS lookups fail after setting the static IP, ensure that systemd-resolved is enabled and running:
sudo systemctl enable --now systemd-resolved
Another issue is the order of service startup. If other services depend on network connectivity, they might fail if the network is not fully initialized. systemd-networkd typically starts early in the boot process, but you can enforce ordering by adding dependencies to your service units if necessary.
If you are using a virtual machine, such as VirtualBox, ensure that the network adapter is set to Bridged or NAT mode appropriately. Misconfigured virtual network adapters can prevent the guest OS from obtaining any IP address, regardless of the static configuration. For bridged networking, the host's physical interface must be accessible, and the VM must be configured to use the correct MAC address.
For users migrating from older Debian versions, it is crucial to understand that the configuration syntax has changed entirely. Relying on old tutorials can lead to persistent failures. Always refer to the official systemd.network man pages for accurate syntax and options. These documents provide comprehensive details on all available directives, including advanced features like VLAN tagging, bonding, and wireless configuration.
Testing Connectivity
Once the static IP is assigned, test connectivity to ensure everything is working as expected. Useping to check reachability to the gateway and external hosts:
ping -c 4 192.168.1.1
ping -c 4 8.8.8.8
If pings succeed, verify DNS resolution:
nslookup google.com
Successful DNS resolution indicates that both the network and DNS configurations are correct. If pings fail, check the routing table with ip route show to ensure the default gateway is set correctly.
Related Resources
If you encounter delays in starting applications after configuring the network, consider reviewing Debian Bookworm: Long Delay in Starting Applications via SSH-X for insights into service initialization timing. Additionally, for those using virtual machines, understanding bridge networking is essential; see VirtualBox Debian 12 Guest Bridge Can't Ping LAN Box for troubleshooting steps related to virtual network adapters.Frequently Asked Questions
Why is my static IP not persisting after reboot?
Your configuration file is likely in the wrong location or format. Ensure you are editing files in /etc/systemd/network/ with the .network extension, not /etc/network/interfaces. After modifying the file, restart systemd-networkd or reboot the system to apply changes.
Can I still use ifupdown on Debian Bookworm?
Yes, but it is not recommended for new server installations. You must install the ifupdown package and disable systemd-networkd to use it. However, sticking with systemd-networkd is the standard approach for Bookworm and ensures better integration with modern systemd features.
How do I find my interface name?
Use the command ip link or ls /sys/class/net/ to list all network interfaces. Look for names like eth0, ens3, or wlan0. Use this exact name in the Name= directive of your .network file.
What if I don't know my gateway IP?
If you are on a local network, the gateway is typically the first usable IP in your subnet, often ending in .1. You can discover it by checking your router's admin page or using ip route show when connected via DHCP to see the current default route.
Does systemd-networkd support IPv6?
Yes, systemd-networkd fully supports IPv6. You can add multiple Address= lines for both IPv4 and IPv6, and configure IPv6 privacy extensions or SLAAC as needed. Refer to the man systemd.network page for specific IPv6 directives.