Vagrant seems to ignore any static ip

393 views
Skip to first unread message

Andreas J

unread,
Aug 6, 2015, 3:44:48 AM8/6/15
to Vagrant
Hi,

I have the following setup

host: Win7
guest: hashicorp/precise32
provider: VirtualBox 5.0.0
Vagrant 1.7.4

with this Vagrantfile

config.vm.define "qa" do |qa|
    qa.vm.box = "hashicorp/precise32"
    qa.vm.network :forwarded_port, guest: 80, host: 8080
    qa.vm.network "private_network", ip: "192.168.50.4", virtualbox__intnet: true
    qa.vm.provider :virtualbox do |vb|
         vb.name = "qa"
 vb.memory = 1024
    end
end

whatever I type for the "private_network", I always get a VM on 127.0.0.1:2222. I tried with and without "virtualbox__intent", I tried with type: "dhcp", but the ip adress is ignored - the VM is always only accessible via 127.0.0.1

What do I do wrong ?

Thanks/Cheers

Alvaro Miranda Aguilera

unread,
Aug 6, 2015, 7:15:52 AM8/6/15
to vagra...@googlegroups.com
Hello,

127.0.0.1 is the ip of localhost, each machine can reach himself on that ip.

When you create a vagrant box with virtualbox, the guest will get the
first nic with ip 10.0.0.15 (or similar),

your host VM, will create a port forward, from :2222 to guest:22

So when you or vagrant connect to 127.0.0.1:2222 will be using this
port forward to reach the guest.

What you need to do is connect to guest and do `ifconfig` and you
will see the nics and ip

eth0 or first nic usually will be 10.0.0.15 (or similar)
eth1 or seconf nic will have the either private or public IP

once you confirm that additional ip is set, try to ping and ssh using that ip

Hope this helps
Alvaro
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/mitchellh/vagrant/issues
> IRC: #vagrant on Freenode
> ---
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vagrant-up/04915f32-e9a4-46ee-821e-354ff0b5daf1%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Andreas J

unread,
Aug 6, 2015, 7:45:49 AM8/6/15
to Vagrant
Hi Alvaro,

thanks for the reply. Indeed when I connect to the guest and run 'ifconfig', I see the 192.168.50.4 I specified in the Vagrantfile.

So i guess the main problem is my lack of network knowledge.

I also install apache-httpd on the guest and my naiv thinking was that I can access the apache from the hosts browser via 192.168.50.4:8080, which does not work... 127.0.0.1:8080 is working though

How is this possible to access the guests apache-httpd from the host bro

config.vm.define "qa" do |qa|
qa.vm.box = "hashicorp/precise32"
qa.vm.network :private_network, ip: "192.168.50.4"
qa.vm.network :forwarded_port, guest: 80, host: 8080
qa.vm.provider :virtualbox do |vb|
vb.name = "qa"
vb.memory = 1024
end
qa.vm.provision "shell" do |s|
s.inline = "sudo apt-get install -y apache2"
s.name = "apache"
end
end

Andreas J

unread,
Aug 6, 2015, 7:53:43 AM8/6/15
to Vagrant
what I actually like to achieve is to define multiple vms in the Vagrantfile and access them via different ips from the host...

Alvaro Miranda Aguilera

unread,
Aug 6, 2015, 5:27:08 PM8/6/15
to vagra...@googlegroups.com
On Thu, Aug 6, 2015 at 11:45 PM, Andreas J <siele...@gmail.com> wrote:
> "192.168.50.4"

Hello Andreas

Apache usually runs on port 80

So you should be able to see the webpage on

http://192.168.50.4:80


localhost:8080 works because you have a port forward for that:
qa.vm.network :forwarded_port, guest: 80, host: 8080


What I do is create port fwd that make sense

ie


vm1.vm.network :forwarded_port, guest: 80, host: 8081
vm2.vm.network :forwarded_port, guest: 80, host: 8082
vm3.vm.network :forwarded_port, guest: 80, host: 8083
vm4.vm.network :forwarded_port, guest: 80, host: 8084

and for IP you can use

192.168.50.11
192.168.50.12
192.168.50.13
192.168.50.14

etc

make sense?


Alvaro
Reply all
Reply to author
Forward
0 new messages