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:

  1. Systemd-networkd – A network management system integrated with systemd.
  2. /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:

sudo vi /etc/systemd/network/10-static-eth0.network

Add the following configuration:

[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:

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:

sudo vi /etc/network/interfaces

Add or modify the following:

# 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:

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.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.