Set private network ip in vagrant

I'm trying to use vagrant with Windows as guest.
When I use config.vm.network to configure a host only network with static ip, the setting won't work.
Here is my Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config| config.vm.box = "win08r2" config.vm.guest = :windows config.ssh.max_tries = 1 config.ssh.timeout = 10 config.vm.provider :virtualbox do |vb| vb.gui = true end config.vm.network :private_network, ip :"192.168.56.10" config.vm.network :public_network
end

The ip of vm is something like 196.254.xx.xx or other, just not same with 192.168.56.10.

Is there any problems with my vagrantfile?

Thanks,

1

3 Answers

I could not get my CentOS vm to take an ip using vagrant's private network. It made a new interface with that ip, but wasn't using it. I ended up doing

config.vm.provider :virtualbox do |vb| vb.customize ["modifyvm", :id, "--memory", "3072", "--cpus", "2", "--natnet1", "10.252/16"]
end

Along with allocating some resources, this line will force virtualbox to use nat with 10.252.xx.yy. The default ip for the first interface is 10.252.0.15. Each interface after increases xx by two. yy stays at 15. That is the behavior of virtualbox, not vagrant. Hopefully that helps somewhat.

This setup works for me:

config.vm.network "hostonly", "192.168.56.10"

If you want to access your host machine, you host machine ip address would be 192.168.56.1

2

You can disable DHCP, for that network host if you're using VirtualBox underneath.

e.g. If your network interface is vboxnet0, open VirtualBox, Navigate to File > Preferences > Network and click on the Host-only Networks tab.

Then edit your network interface by clicking on the edit button after choosing vboxnet0. Once the edit dialog box opens, navigate to the DHCP Server tab and un-check Enable DHCP option.

This way the network interface will not be assigned an IP automatically.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like