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

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.cfgStep 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 rebootStep 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 configurationNotes on configuring Netplan
When reconfiguring the static IP, please note the following:
| Key points | Explanation |
|---|---|
| Confirm the NIC name | Execute ip addr or ls /sys/class/net/, confirm the actual network interface name (e.g.eth0,ens33) |
| YAML indentation | Netplan 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 configuration | For 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.114Alternative option (not recommended)
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-initThe 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:
RockyLinux 96 Static IP Configuration Detailed Guide—— This is also a static IP configuration, but it is based on RockyLinux 96 and uses the traditional network-scripts method, allowing comparative study with the Netplan solution.
Guide to Configuring a Static IP in NAT Mode for Ubuntu Server in VMware—— If you are encountering network problems in a virtual machine environment, this article provides complete static IP configuration steps and troubleshooting approaches specifically for VMware NAT scenarios.
Enable the root user on Ubuntu and configure SSH remote login—— After configuring a static IP, you usually need to manage the server remotely. This article explains in detail how to securely enable root SSH login access.
CentOS 7 Configure Alibaba Cloud YUM Repository—— After the system network is connected, the first thing is often to configure software sources. Taking CentOS 7 as an example, this article introduces how to switch to the domestic Alibaba Cloud mirror source to greatly improve software package download speed.
ESXi 8.0 DNS Configuration Guide—— If your Ubuntu runs on an ESXi virtualization platform, this article about ESXi host DNS configuration can help you troubleshoot virtual machine network issues caused by improper host network configuration.