Proxmox API - permanently set IP on Ubuntu VM

Rasto Carnecky

New Member
Feb 13, 2024
1
0
1
Hello, could you pls help me with network configuration of Ubuntu 20.04 VM via Rest API ? I need to permanently set IP for network interface ens18, tried it like this:
1) curl POST api2/json/nodes/<node_name>/qemu/<vm_id>/config {"ipconfig0": "name=ens18,ip=XXX.XXX.XXX.XXX/24,gw=XXX.XXX.XXX.XXX"} -> response 200 but no change of IP ...kinda expected

2) curl POST api2/json/nodes/<node_name>/qemu/<vm_id>/config {"net0": "virtio=XX:XX:XX:XX:XX:XX,bridge=vmbr0,firewall=1,ip=XXX.XXX.XXX.XXX/24"}
-> "net0":"invalid format - format error\nnet0.ip: property is not defined in schema ...

What is the proper way to achieve permanent change of IP ?
 
Hi,
Proxmox can't directly set the IP inside a VM, because it has no control over the VMs network stack. Setting the IP via the ipconfig[n] option is a feature of cloud-init. If you have cloud-init set up, AFAIK you still need to restart the VM so it reevaluates the cloud-init config.
Another possibility would be to use the qemu-guest-agent if it is installed on your target system. You can use it to execute arbitrary commands inside the VM [0].

[0] https://forum.proxmox.com/threads/about-use-agent-config-ip-address-all-faile.69728/
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!