Skip to content

Ubuntu 22.04 static IP configuration reset after reboot? Here's a one-step permanent fix. ​

Ubuntu 22.04 Static IP Configuration Reset After Reboot? One Trick to Completely Solve It Diagram

Troubleshooting Record Solve cloud-init Issue of preempting Netplan network configuration

Problem symptoms ​

In the Ubuntu 22.04 system, modify according to the standard procedure /etc/netplan/ the configuration file under it and execute it sudo netplan apply Afterward, the static IP address did indeed take effect. But once executed sudo reboot After restarting the system, the previously configured static IP will be lost, and the network configuration will revert to automatic acquisition via DHCP.

Root cause ​

The problem lies in cloud-init On this cloud environment initialization service, Ubuntu 22.04 is integrated by default.cloud-init, its network management module will Every time the system starts, regenerate the network configuration based on its own configuration file and overwrite the Netplan settings.

This behavior is actually already documented in the official Netplan configuration file, and the recommended solution is to disable it.cloud-init network management functions.

Solution ​

Step 1: Create a disabled configuration file ​

Execute the following command, create a new cloud-init configuration snippet:

bash
sudo vim /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

Step 2: Write the configuration content ​

Paste the following content into the file:

yaml
network: {config: disabled}

Save and exit (:wq).

Principle Description:cloud-init Load in numerical order /etc/cloud/cloud.cfg.d/ the configuration file under the directory,99- The prefix ensures that this configuration takes precedence, thereby disabling its network management module.

Step 3: Clear the cache and restart ​

bash
sudo cloud-init clean
sudo reboot

Step 4: Reapply the Netplan configuration (if needed) ​

After restart,cloud-init No longer interfere with the network configuration. At this point, simply configure Netplan in the standard way:

bash
sudo vim /etc/netplan/01-netcfg.yaml   # Edit configuration file
sudo netplan apply                       # Application configuration

Notes on configuring Netplan ​

When reconfiguring the static IP, please note the following:

Key pointsExplanation
Confirm the NIC nameExecute ip addr or ls /sys/class/net/, confirm the actual network interface name (e.g.eth0,ens33)
YAML indentationNetplan uses the YAML format,Extremely sensitive to indentation, please use spaces instead of Tab
Avoid file conflicts/etc/netplan/ Under it, only one file can define the same network card; it is recommended to keep one configuration file.
DNS configurationFor static IP, it is recommended to also specify nameservers, avoiding DNS resolution issues

Netplan configuration example ​

yaml
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 114.114.114.114

In addition to the above methods, you can also /etc/cloud/cloud.cfg.d/90-installer-network.cfg directly modify the IP address in it. However, doing so has two problems:

  • Treat the symptoms, not the root cause.:cloud-init The configuration override mechanism still exists and may still cause problems in the future.

  • 可维护性差: Network configurations are scattered across two locations, which easily causes confusion and is not conducive to operations and maintenance management.

Therefore,Strongly recommend disabling it directly.cloud-init network management functions, uniformly use Netplan to manage the network.

Advanced Tips ​

Subsequent execution sudo apt upgrade When upgrading system packages, even if cloud-init There’s an update, the one we created.99-disable-network-config.cfg The file will not be overwritten either, and the solution is persistent.

Further Reading ​

If you are interested in Ubuntu network configuration or related operations and maintenance scenarios, the following articles may be helpful to you:

Last updated on11/07/2026, 02:16 PM
@fishfinal | @fishfinals | [email protected]