Ubuntu Server Static IP (Netplan)
📌 Overview¶
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.
🔍 Understanding the Issue¶
⚠️ Cause¶
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
🔄 Effect¶
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
✅ Solution¶
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
1. Disable Cloud-Init¶
Cloud-init manages the default network configuration, but it often interferes with manual settings. To disable it:
Then, remove any existing network configuration files created by cloud-init:
Disable the cloud-init service:
(Optional) If you want to completely remove cloud-init:
2. Manually Configure a Static IP¶
Now that cloud-init is disabled, we can manually set up Netplan.
Step 1: Identify the Network Interface¶
Run the following command to find your active network interface:
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.
Step 2: Create a Static IP Configuration¶
Create a new Netplan configuration file:
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:
3. Apply and Verify Configuration¶
After setting up the static IP, apply the changes:
If everything looks good, make it permanent:
Reboot the server:
After rebooting, confirm the Static IP is applied:
🛠️ Troubleshooting & Additional Tips¶
a. Verify the Correct Network Interface¶
If your changes do not take effect, ensure the correct interface is being used:
Update your Netplan configuration with the correct name.
b. Check Netplan for Errors¶
Run this command to validate your Netplan configuration:
If an error appears, double-check your YAML syntax.
c. Confirm DHCP is Disabled¶
Check if your interface is still requesting DHCP:
If DHCP is still active, ensure that dhcp4 is set to no in your Netplan file.
📌 Conclusion¶
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.
✅ Summary of Key Steps:¶
✔️ 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!