When setting up Debian 12 on Hyper-V, one common issue is that the static IP reverts to dynamic after a reboot.
Despite configuring a static IP, the system continues to obtain a dynamic address via DHCP. After extensive troubleshooting, I found the solution to ensure Debian 12 retains its static IP permanently.
Why Does the IP Keep Reverting to Dynamic?
This issue occurs because Debian 12 utilizes two different network configuration methods:
- Systemd-networkd – A network management system integrated with systemd.
- /etc/network/interfaces – The traditional Debian networking configuration.
If only one of these is configured while the other remains active, the system may still revert to DHCP upon reboot.
Solution: Setting a Permanent Static IP
In this example, we will configure Debian 12 with the static IP 192.168.3.103, a gateway of 192.168.3.253, and DNS servers 192.168.3.22 and 192.168.3.23.
1. Configure Systemd-networkd
First, create a configuration file for systemd-networkd:
0 1 2 |
sudo vi /etc/systemd/network/10-static-eth0.network |
Add the following configuration:
0 1 2 3 4 5 6 7 8 9 |
[Match] Name=eth0 [Network] Address=192.168.3.103/24 Gateway=192.168.3.253 DNS=192.168.3.22 DNS=192.168.3.23 |
Save the file and restart systemd-networkd:
0 1 2 3 |
sudo systemctl enable systemd-networkd sudo systemctl restart systemd-networkd |
2. Configure /etc/network/interfaces
To ensure Debian retains the static IP, configure the traditional network settings as well:
0 1 2 |
sudo vi /etc/network/interfaces |
Add or modify the following:
0 1 2 3 4 5 6 7 8 |
# The primary network interface allow-hotplug eth0 iface eth0 inet static address 192.168.3.103 netmask 255.255.255.0 gateway 192.168.3.253 dns-nameservers 192.168.3.22 192.168.3.23 |
Save the file and restart networking services:
0 1 2 |
sudo systemctl restart networking |
Why Are Both Configurations Important?
There are two key reasons why both configurations must be applied:
1. Systemd-networkd
- Debian 12 relies on systemd-networkd as the primary network manager.
- Without proper configuration, Hyper-V may continue assigning an IP dynamically through DHCP.
2. /etc/network/interfaces
- Some legacy services still depend on this configuration file.
- If this file is not properly set up, the system might still request a dynamic IP upon reboot.
Conclusion
To ensure Debian 12 on Hyper-V always retains a static IP, both systemd-networkd and /etc/network/interfaces must be properly configured.
By following these steps, you can prevent your system from reverting to a dynamic IP after a restart, ensuring a stable and consistent network configuration.