Setting subnet mask In vagrant for public network - networking

I need to run some services in vagrant, so that its accessible in browser. By giving network type as public_network in Vagrantfile, I am getting a vagrant Ip (10.251.70.201).
Now, using this vagrant Ip am able to get these service in other device's browser (which are in the same network: 10.251.70.*). Now I need to expand the visibility of the vagrant Ip in other networks (like 10.251.*.*). How can I achieve this?

I assume you are using Virtualbox provider. As an example:
config.vm.network "public_network", :netmask => "255.255.0.0"

This is example of using Virtualbox provider for Vagrant version 2 config file:
config.vm.network "public_network", bridge: "eth0", ip:"192.168.1.20", netmask:"255.255.0.0"

Related

Vagrant Private Networking

I am trying to create a Kubernetes cluster with Vagrant using an Ansible playbook that works perfectly on real (linux) servers. I am having a problem with the kubeadm join with vagrant.
I am using the following command to join a node to the cluster.
kubeadm join --token={{ kube_token.stdout }} {{ hostvars[groups['kubemaster'][0]].ansible_default_ipv4.address }}
The problem with vagrant is that it interprets:
hostvars[groups['kubemaster'][0]].ansible_default_ipv4.address
as the enp0s3 address which seems to always be 10.0.2.15 on all machines in my cluster.
I have tried explicitly setting the ip of my machines using:
machine.vm.network :private_network, ip: < ip >, auto_config: false
but this sets the enp0s8 address so it still doesn't work.
How do I make the hostvars[groups['kubemaster'][0]].ansible_default_ipv4.address different on all the machines in my vagrant setup?
you can use hostvars[groups['kubemaster'][0]].ansible_eth1.ipv4.address
assuming that your eth1 is your actual ip you want. as noted by Frederic, it uses the default as the first. you can do ip addr to find your interfaces on a machine.

vagrant Multipe networking

I have installed magento 2 in vagrant with in docker machine, this docker machine have port forwarding concepts, I set private network, with nat and host-only, Now only access magento 2 in hostmachine.
I need to access locally connected remote machine also so, i try to change private network to public network with bridge.
Vagrant File:
Vagrant.configure("2") do |config|
config.vm.box = "machine"
config.ssh.username = "vagrant"
config.vm.hostname = "www.myhost.net"
config.ssh.forward_agent = "true"
config.vm.network "public_network", ip: "192.168.56.40"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
if Vagrant::Util::Platform.windows?
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777", "fmode=777"]
else
config.vm.synced_folder ".", "/vagrant", :nfs => { :mount_options => ["dmode=777", "fmode=777"] }
end
end
But, throw
NFS requires a host-only network to be created.
Please add a host-only network to the machine (with either DHCP or a
static IP) for NFS to work.
I need to add Multiple Network to vagrant
nat
host-onloy(for nfs)
bridge (for access remote machine)
Suggest me How to resolve this.
You need to change your public_network to private_network for nfs to work
If you are using the VirtualBox provider, you will also need to make sure you have a private network set up. This is due to a limitation of VirtualBox's built-in networking. With VMware, you do not need this.
so :
you can change to VMWare (but you have some additional fees)
you do not use nfs
you can setup another network interface for bridge and use this network interface if you need to connect to the remote machine, you should be able to ping (ping -I ethX mylocalmachine) but I am not sure how to work to get connection in

Vagrant::Errors::NetworkCollision: The specified host network collides with a non-hostonly network

I'm using vagrant with multiple machine, it's ever worked normally, but then it just doesn't work again.
My part of Vagrantfile that defining the network:
config.vm.define "app" do |layer|
layer.vm.provision "chef_solo", id:"chef" do |chef|
.....
end
# Forward port 80 so we can see our work
layer.vm.network "forwarded_port", guest: 80, host: 9999
layer.vm.network "private_network", ip: "10.10.10.10"
end
It's a standar configuration and I only have that vm. But when I tried to vagrant up, it shows error:
Vagrant::Errors::NetworkCollision: The specified host network collides with a non-hostonly network!
This will cause your specified IP to be inaccessible. Please change
the IP or name of your host only network so that it no longer matches that of
a bridged or non-hostonly network
How to fix it?
Apparently my office just changed the network configuration. By changing 10.10.10.10. to other blok (e.g 10.0.0.100), it workedagain. Sorry.

Vagrant with VPN connection over host computer

I'm trying to get my Vagrant CentOS box connected to VPN thru my host computer. I followed this: https://gist.github.com/mitchellh/1277049
but I still can't connect to the VPN only hosts.
I'm on Vagrant version 1.3.5 and CentOS release 6.4.
Vagrant configs: config.vm.network :public_network and, as noted by the link above, I have
vb.cusotomize["modifyvm", :id, "--natdnshostresolver1", "on"]
With this setup I don't get any errors, it just doesn't seem to be working. I can reach hosts on my host machine but not thru my VM. When the VM is booting I choose my 2) en0: Ethernet 1 connection.
As Terry Wang answered, remove public_network and as then follow this answer https://superuser.com/questions/542709/vagrant-share-host-vpn-with-guest
The newer versions of Vagrant will only use host as dns with this:
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
The Gist 1277049 is using default NAT networking for the Vagrant box.
However, you are using Public Network (Bridged) with your en0. That's why it is NOT working.
NOTE: I don't think you can bridge to a VPN connection (virtual adaptors, no driver). By using NAT, you are able to access the systems on the other side of the VPN connection.
To fix, just comment out the config.vm.network :public_network line. By default it'll use NAT and the box should be able to access whatever the host is capable of.

browser in host can not see vagrant box, portforward does not work

I have installed Vagrant in my Window XP, and in my Vagrantfile I have:
Vagrant::Config.run do |config|
# Setup the box
config.vm.box = "lucid32"
config.vm.forward_port 80, 8080
config.vm.network :hostonly, "192.168.10.200"
end
But I see no sign of my vagrant box when I type "http://192.168.10.200:8080" in browser.
IP address of the virtual box is correct, because from within the vbox, I have:
vagrant#lucid32:~$ ifconfig
....
eth1 Link encap:Ethernet HWaddr 08:00:27:79:c5:4b
inet addr:192.168.10.200 Bcast:192.168.10.255 Mask:255.255.255.0
There seem to be no firewall problem because if I type
vagrant#lucid32:~$ curl 'http://google.com'
it works fine.
I have read Vagrant's port forwarding not working
and tried:
vagrant#lucid32:~$ curl 'http://localhost:80'
curl: (7) couldn't connect to host
and also
vagrant#lucid32:~$ curl 'http://localhost:8080'
curl: (7) couldn't connect to host
So, looks like port forward is not working...
If you know what I can do so I can access my vbox from host browser, can you help me?
Thanks in advance
If you just started a Vagrant box with this Vagrantfile, there is nothing more than an empty Ubuntu Lucid, which does not run any service yet. So there is nothing served on port 80, this is why there is nothing to see either from inside the box on port 80 or the host machine on 8080.
For you Vagrant machine to provide some services (such as a web server on port 80), you have to do some provisioning. You can do it manually or using Chef or Puppet which are hooked into Vagrant's up process.
I had a similar problem. Sometimes using port forwarding for ports below 2000 is a problem. What worked for me is choosing ports that are above 2000. So my vagrantfile now looks like:
config.vm.network :forwarded_port, host: 4500, guest: 9000
Typing localhost:4500 on my host machine now just works fine. It seems like you are on an older version of vagrant than mine, so you can edit your vagrant file to something like
config.vm.forward_port 9000, 4500
Now typing localhost:4500 on your host machine should work fine.
Good luck,

Resources