Is it possible to either specify an ip address on launch, or "reset" the next ip address to be used?

I’m in the process of putting together a custom cloud-init.yaml file which configures a multipass instance for a specific environment (LAMP, but with multiple PHP versions available, and some additional software, PHPMyAdmin, MailHog, and a few other things)

In trying to test out my yaml file, I’ve essentially launched and then deleted and purged a number of multipass instances. Every time a launch new instance, it is assigned the next IP address in the range.

Is it possible to somehow “recover” used IP addresses of deleted instances, or set a specific IP address for a newly launched instance?

I did some digging in the GitHub repository and found some mentions of using the
–network switch when launching a new instance, but this doesn’t seem to be what I’m looking for.

The main reason I’m asking is that I have an /etc/hosts record set on the host machine, and I have to update it every time I launch a new instance. Perhaps there’s a better way to achieve this.

Hi @jonathanbossenger!

It’s not clear what your host OS is. Are you using a Windows, macOS, or Linux host? The handling of the DHCP IP address is very dependent on the host.

Regarding --network, this basically puts the instance on your LAN and uses your router’s DHCP/DNS handling- this is in addition to the current NAT’d network. This may be a solution for you.

1 Like

Aha, I see, thanks @townsend, I didn’t realise it was OS specific.

I’m working on both macOS and Ubuntu.

Hey @jonathanbossenger,

On macOS hosts, this how the macOS built in DHCP server works and there really isn’t anything we can do to control that- we are at the mercy of Apple unfortunately. If you want to use the --network option, you’ll need to switch to the qemu driver via $ multipass set local.driver=qemu.

On Ubuntu hosts, in theory, it should reuse the same IP address for the NAT’d network.

1 Like

Got it, thanks @townsend

Out of interest, on a Mac, what happens when the next available ip reaches 255? Does it increment the third octet?

Out of interest, on a Mac, what happens when the next available ip reaches 255? Does it increment the third octet?

TBH, I’m not quite sure. One may have to delete /var/db/dhcpd_leases and let it start from scratch.

1 Like

Ha! I’m able to delete previously leased IPs by deleting them from that file.

Thanks @townsend, massive help.

1 Like

@jonathanbossenger, cool, glad it’s working for you! :+1:

2 Likes