When configuring Ubuntu Server, you may encounter an issue where the Static IP Address reverts to DHCP after a reboot. This problem is common in both Virtual Machines (VMs) (e.g., Proxmox, VirtualBox, VMware) and bare-metal servers.
This guide will help you troubleshoot and resolve this issue by properly configuring your network settings and disabling any conflicting services like cloud-init.
By default, Ubuntu Server uses cloud-init to manage network settings dynamically. While this is helpful in cloud environments, it can override manual network configurations, causing:
- ❌ Static IP changes to DHCP after reboot
- ❌ Netplan configuration files being ignored or overwritten
- ❌ Inconsistent networking behavior
If not resolved, this can result in:
- 🔗 Loss of network connectivity after reboot
- 🌍 Difficulty accessing the server remotely
- 🛑 Conflicts in network infrastructure when multiple devices receive unintended DHCP addresses
To permanently set a Static IP, we will:
- Disable cloud-init (to prevent automatic configuration changes)
- Manually configure the network using Netplan
- Apply and verify the changes
Cloud-init manages the default network configuration, but it often interferes with manual settings. To disable it:
sudo touch /etc/cloud/cloud-init.disabled
Then, remove any existing network configuration files created by cloud-init:
sudo rm -rf /etc/netplan/50-cloud-init.yaml
Disable the cloud-init service:
sudo systemctl disable --now cloud-init
(Optional) If you want to completely remove cloud-init:
sudo apt purge cloud-init -y
Now that cloud-init is disabled, we can manually set up Netplan.
Run the following command to find your active network interface:
ip link show
You will see output like this:
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
Take note of the interface name (e.g., enp0s3), as we will use it in the next step.
Create a new Netplan configuration file:
sudo nano /etc/netplan/50-static-ip.yaml
Add the following configuration (adjusting based on your network setup):
network:
version: 2
renderer: networkd
ethernets:
enp0s3: # Change this to your actual network interface
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
dhcp4: no
Save the file (Ctrl + X → Y → Enter).
Ensure the file has the correct permissions:
sudo chmod 0600 /etc/netplan/50-static-ip.yaml
After setting up the static IP, apply the changes:
sudo netplan generate
sudo netplan try
If everything looks good, make it permanent:
sudo netplan apply
Reboot the server:
sudo reboot
After rebooting, confirm the Static IP is applied:
ip a
If your changes do not take effect, ensure the correct interface is being used:
ip link show
Update your Netplan configuration with the correct name.
Run this command to validate your Netplan configuration:
sudo netplan try
If an error appears, double-check your YAML syntax.
Check if your interface is still requesting DHCP:
journalctl -u systemd-networkd --no-pager | grep -i 'dhcp'
If DHCP is still active, ensure that dhcp4 is set to no in your Netplan file.
By following these steps, you can ensure that your Ubuntu Server retains a Static IP Address across reboots, whether running on a Virtual Machine (VM) or bare-metal hardware.
✔️ Disable cloud-init to prevent conflicts
✔️ Manually configure Netplan with a static IP
✔️ Apply changes and verify the setup
✔️ Troubleshoot if necessary
Now your Ubuntu Server should maintain its network configuration consistently!