Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Allow setting an IP address on :bridged #743
I would like to be able to manually set an IP address on a Vagrant machine using the Vagrantfile.
It does it on both my Ubuntu machine and Mac.
This is what I get on my Ubuntu machine which is where I will be running my Vagrant machines:
Nice, the stack trace is a bug, but unfortunately you can't statically assign an IP on bridged networks. Since the behavior of a bridged network is to join your existing network, your best bet is to assign a static MAC address to your bridged network, then configure your router so that that MAC address always gets the same IP address.
added a commit
Feb 16, 2012
"you can't statically assign an IP on bridged networks" - actually, that is exactly what is needed in my case, because I am setting up a development network and the virtual machine is the DHCP server for other virtual machines and some physical hosts on the bridged network (which is an isolated network to test an OpenStack private cloud).
Do you see any chance of implementing that? :)
This would be a useful feature, and Im not sure why it is judged as not possible.
I might misunderstand the question, but I know I can boot a VM with vagrant and a bridged network for eth1, then manually assign the VM a static ip. On CentOS I edit
As long as Im not assigning anything that can conflict with the DHCP server then there is no problem, and the VM can be accessed by all other machines on the network at this static IP...
... until I reboot. Because vagrant doesn't know about this config then of course it resets it to DHCP on reboot.
If I can set that up manually each time the machine reboots, surely Vagrant could manage it via its config?
[edit: fixed netmask setting in example]
really simple solution
@mitchellh please reconsider your position on this. Not being able to assign a static IP on bridged interfaces makes Vagrant close to useless for doing any meaningful operations/infrastructure work.
I'm a sysadmin/devops by trade so my use case for Vagrant may be atypical. I often set up some VirtualBox machines to try out some infrastructure setups and service configurations. Being able to bring up a couple of boxes with predictable network addresses and have them talk over various network protocols to each other is essential for setting up an operations lab. I've been using VirtualBox for this type of testing with bridged interfaces and static IP addresses for years, without a hitch.
You mention DHCP with MAC addresses in the config as an alternative, but we should be able to set this up from within a Vagrantfile. Heck, the only router I have in my apartment is the one I got from my ISP who pretty much locked down advanced configuration. I couldn't fiddle with the DHCP settings if I wanted to.
I understand where you're coming from. There is the risk of having conflicting addresses. Put a big bold warning in the docs saying users should make sure the IP addresses they assign don't overlap with their DHCP pool. Have Vagrant quickly ping the IP before assigning it to make sure it's not already in use. Bury the option deep in the docs if you must, but please, provide this option.
I'll get off my soapbox now, thanks for reading.
I solved the problem with a workaround.
First i have to say that i don't understand the developer of this damn great product, because it really is a problem to not be able to set a static IP Address on a bridged network.
Ok, enough talk, here's my solution:
config.vm.network :public_network, :bridge => 'en0: Ethernet', :auto_config => false
This will setup the network adapter but neither configures nor activates it.
This configures and activates the network adapter with a static IP.
Thanks for the tip on your bridged network workaround. It doesn't seem like the ability to set :auto_config for a bridged network is documented in the Vagrant documentation. Anyway below is the Chef equivalent to your Puppet exec resource.
Thanks to the others the solution I came up with was to stick this into my
If you don't have a
Here is my solution with ansible as the 'provisioner' : https://github.com/bryfry/vaspi
This really seems like a basic feature that any normal provider like virtualbox should have out of the box.
+1 to get this patched to not rely on provisioning hacks to get standard functionality.
You could make this much simpler for us. You could trivially have Vagrant's internal SSH working over v6 link local addresses. Alternatively let us tell Vagrant the static IPv4 or IPv6 address we will configure and let us configure /etc/network/interfaces or the equivalent and ignore the rest of the networking config from there.