How to Configure DHCP in Ubuntu Cloud Image on Proxmox
If you want your Ubuntu Cloud image to automatically obtain an IP address via DHCP on boot, you can include the network configuration in the image itself. Here are two methods to achieve this:
Method 1: Using Cloud-Init (Recommended)
Ubuntu Cloud images usually use cloud-init for initial configuration. You can create a user-data file with the following settings:
#cloud-config
network:
version: 2
ethernets:
enp18:
dhcp4: true
dhcp6: false
Steps:
- Create a cloud-init drive and include the
user-datafile. - Ensure your VM in Proxmox has a cloud-init drive attached.
- When the VM boots, it will automatically use DHCP.
Method 2: Directly Modify the Image
If you prefer to edit the image directly without relying on cloud-init, follow these steps:
1. Mount the Ubuntu Cloud Image
guestmount -a ubuntu-cloud.img -m /dev/sda1 /mnt
2. Edit Netplan Configuration
Open the Netplan configuration file and update it as follows:
network:
ethernets:
enp18:
dhcp4: true
dhcp6: false
version: 2
3. Unmount and Save Changes
umount /mnt
Which Method Should You Use?
- If you frequently deploy multiple VMs, cloud-init is more flexible and recommended.
- If you only need a fixed configuration, directly editing the image is simpler.
Now, your Ubuntu Cloud image will automatically obtain an IP address via DHCP upon boot. 🚀