Static IP on Public Network/Bridged

3,156 views
Skip to first unread message
Message has been deleted

James Jelinek

unread,
May 25, 2013, 12:10:10 PM5/25/13
to vagra...@googlegroups.com
Here is a very basic Vagrantfile that I'm using to boot a web and db server which I plan to setup nginx/rails and mysql.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.define :web do |web|
web.vm.box = "web"
web.vm.hostname = "web"
web.vm.network :public_network, ip: "192.168.1.200"
end

config.vm.define :db do |db|
db.vm.box = "precise32"
db.vm.hostname = "db"
db.vm.network :public_network, ip: "192.168.1.201"
end
end


I want to assign a static IP to the interface instead of having dhclient pull one. I've read the documentation and this seems to be the way to do it but each time I boot the VMs they grab an IP from the dhcp pool of my router instead of the IPs I've specified.

Am I doing something wrong here?


Raymond Kroeker

unread,
May 25, 2013, 12:59:16 PM5/25/13
to vagra...@googlegroups.com

Hi James, 

One thing I've noticed with my them machines is that on my host only networks the static IP is there and works (ie ssh and other services) *even though* ifconfig reports the dhcp address.  After restarting the interface it reports correctly as well.

Raymond

--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Weidong Shao

unread,
May 26, 2013, 1:50:47 PM5/26/13
to vagra...@googlegroups.com
I am running into the same issue. Looks like Vagrant assumes that a
bridge interface use DHCP. on my Ubuntu Guest, it appends the
following block in /etc/network/interface

auto eth2
iface eth2 inet dhcp

I want to use static IP and could not figure out a way to do it under vagrant.
I hate to have to resort to VBoxManage to configure networking and
start/stop vm.

Is there any way to override vagrant's network config on bridge interface?


thanks,
Wei

Trevor Roberts

unread,
May 27, 2013, 8:03:25 AM5/27/13
to vagra...@googlegroups.com
It is not possible to assign a static IP for bridged\public interfaces in the Vagrantfile. You can set the MAC address in the Vagrantfile and then set your hypervisor's dhcp server (or if you use a different dhcp server) to recognize that MAC address and assign a specific IP of your choosing.

I do not know how to do this for Virtualbox, but there are write-ups online if you search Google.

Carlos Encine

unread,
Jun 13, 2014, 1:11:28 AM6/13/14
to vagra...@googlegroups.com
in my vagrantfile i use

config.vm.network "public_network", bridge: 'eth1', ip: "192.168.0.104"

to set static ip from my server
Reply all
Reply to author
Forward
0 new messages