Configuring Private IP in startup script

I need to be able to automatically configure the private IP for my instances. Once the instance is spun, I realize that the Sample Network Configuration is generated with some examples.

I'm using an Ubuntu 18 based image.

The question is how do I generate the 10-ens3.yaml and 10-ens7.yaml in the startup script with the correct values?


  • edited May 4

    You can access that information in a startup script using the Vultr Metadata API. There is an example in this document:

  • For Ubuntu 18.04:

    apt update
    apt install -y jq
    private_ip="$(curl -s | jq '.interfaces[1].ipv4.address' | tr -d '"')"
    echo "network:
      version: 2
      renderer: networkd
          mtu: 1450
          dhcp4: no
          addresses: [$private_ip/16]" > /etc/netplan/10-ens7.yaml
    netplan apply
Sign In or Register to comment.