vagrant provisioned virtualbox cannot access the internet when booted up with an active VPN connection on the windows 7 host - windows

I have a problem with networking while setting up a development virtual machine
The host environment is:
Windows 7x64
Vagrant 1.7.2
Virtualbox 4.3.20 r96997
has an active WLAN internet connections
can connect to a VPN
The relevant sections from the Vagrantfile are:
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.define 'crm' do |node|
node.vm.network :private_network, ip: '192.168.56.2'
end
end
With this, the guest machine has two network interfaces:
eth0: NAT
eth1: the private network
After a vagrant up the machine is always accessible through the private IP.
However, if at boot time the VPN connection
is active, then the guest machine cannot access the internet
is not active, then the guest machine can access the internet
On the host machine, with an active VPN connection, both public and VPN-restricted hosts are accessible.
Question: how should I modify the Vagrantfile to ensure that the guest machine always has internet access, regardless whether it was booted with an active VPN connection on the host machine or not?
Update:
adding
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
solves the internet connectivity issue, however, it brings the boot time of the guest machine to barely tolerable (many minutes)

ok. i had the same problem but i am using windows. i did fix it. what i did is that opened virtualbox.
go to settings
select network
change second adapter
select under " attached to: " ' Host-only Adapter'
under name. i selected " virtualbox host-only ethernet apdapter " do not select the name that have numbers at the end of the name example : #1, #2 and so on.
i went to my device manager and delete all the virtual network drivers "not your physical network drivers". again this was in windows 8.
i restart my pc
confirm my chance have applied
i vagrant up on my project directory and it was working

Related

VirtualBox networking using vagrant

I need to configure a vm into using vagrant and virtualbox as provider. The issue is related to how to allow network comunication between the virtual machine and the host machine.
Concretly, I need:
Each developer is using a log viewer in his host machine in order to be able see the log messages generated into vm applications. So I need to send log messages to an network address(host) from guest.
Each developer machine has its own ip address, so I'm not able to reference to a single ip since each developer has its host ip address.
Any ideas?
This is how I've set up my VMs lately, hopefully it points you in the right direction.
My requirements were:
enable internet access on a single guest basis
enable access guest to guest
enable access host to guest
avoid IP changes when changing physical network (lan home, lan work, random wlans)
avoid IP clash with various clients VPNs
avoid showing machines on the physical network
To do this use 2 network interfaces on all guests.
Default NAT, enables internet access;
HostOnly network, enables communication host-to-guest and guest-to-guest.
Steps:
Create hostonly network with DHCP (Virtualbox comes with a default one, I customized it)
hostonly network setup
hostonly network DHCP
add network adapters to the guest
NAT(default)
hostonly-network
Start the VM, check with ip a and ip r:
ip addr
ip route (has docker installed too, ignore that)
Create Vagrantfile to provision VM configured like above (I'm using bento/ubuntu-20.04).
NAT is on by default
join the hostonly-network with "modifyvm" (avoid :private_network as it creates a new network that will clash with the one already available), add to Vagrantfile:
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--nic2", "hostonly"]
vb.customize ["modifyvm", :id, "--hostonlyadapter2", "vboxnet1"] #use proper network name here
vb.customize ["modifyvm", :id, "--cableconnected2", "on"]
end
vagrant up
vagrant ssh
ip a will show eth1 as down
try sudo ifup eth1, in my case this failed
edit /etc/network/interfaces and add this:
allow-hotplug eth1
iface eth1 inet dhcp
sudo ifup eth1 should work now and get an ip from the DHCP of the host-only network
Probably these last steps could be added to vagrant shell provisioning but I'm still new to it.
Edit: add this section to Vagrantfile for the steps above:
config.vm.provision "shell", inline: <<-SHELL
if ! ifquery eth1 > /dev/null 2>&1; then
sudo echo "allow-hotplug eth1" >> /etc/network/interfaces
sudo echo "iface eth1 inet dhcp" >> /etc/network/interfaces
sudo ifup eth1
ip -4 a show dev eth1
fi
SHELL
At this point the vagrant vm should be accessible, able to access the web, able to access the hostonly network (other guests and the host through the configured ip, 192.168.178.1 in my case), these should all work:
ping 8.8.8.8 #web
ping 192.168.178.1 #host
ping 192.168.178.3 #other guest
Final result
Hopefully this enables all relevant communication for your use case also.

How can I configure private network in vagrant box

Setup:
On my laptop, I have windows 10 pro install. On that, I have installed latest virtualbox 5.1.2, latest vagrant 1.9.1 and latest packer 0.12.1. My laptop is highend and with strong configuration. I am on wifi.
Purpose:
I want to have three vagrant boxes running Windows 2012 r2 so that I can install SQL server on one, and two different web applications on others.
Success:
Till now I have managed to create vagrant boxes without any hassles. If I use forwarded port method, I am even able to rdp into those machines.
Failure:
My plan is to configure private network for these machines so that they can have their own ip addresses and can communicate with each other. But so far I am unable to achieve so. The private network settings as recommeded on vagrantup.com and other websites do not seem to work for me somehow, as I am sure I am doing some mistake somewhere.
can somebody please help me on how to go about this? I have searched a lot on this site also and gone through many suggestions but none seem to help.
Below is my vagrant file that I am using.
Vagrant.configure(2) do |config|
config.vm.box = "xxxx.box"
config.vm.communicator = "winrm"
config.vm.hostname = "xxxserver"
# Admin user name and password
config.winrm.username = "vagrant"
config.winrm.password = "vagrant"
config.vm.guest = :windows
config.windows.halt_timeout = 600
config.vm.network "private_network", ip: "192.168.50.4"
end
And below is the error message that I get when I run vagrant rdp
*
==> default: Detecting RDP info... RDP connection information for this machine could not be detected. This is typically caused when we can't
find the IP or port to connect to for RDP. Please verify you're
forwarding an RDP port and that your machine is accessible.
*
But if I replace
config.vm.network "private_network", ip: "192.168.50.4"
with
config.vm.network "forwarded_port" , host: 33390 , guest: 3389
and then reload the box then vagrant rdp works fine and I am able to loginto it. I want to use static ips for my vms.
Kindly guide..
thanks.
I also use a private_network with a static ip. Only adding (not replacing) the line config.vm.network "forwarded_port" , host: 33390 , guest: 3389 works.
$ vagrant rdp
==> fe: Detecting RDP info...
fe: Address: 127.0.0.1:33389`enter code here`
fe: Username: vagrant
==> fe: Vagrant will now launch your RDP client with the connection parameters
==> fe: above. If the connection fails, verify that the information above is
==> fe: correct. Additionally, make sure the RDP server is configured and
==> fe: running in the guest machine (it is disabled by default on Windows).
==> fe: Also, verify that the firewall is open to allow RDP connections.

Can't enable port forwarding due to No base MAC address error

I am trying to enable port-forwarding so i can access my vagrant box from my local machine, but whenever i run my vagrant box i get this error,
No base MAC address was specified. This is required for the NAT networking
to work properly (and hence port forwarding, SSH, etc.). Specifying this
MAC address is typically up to the box and box maintainer. Please contact
the relevant person to solve this issue.
But when I re-run vagrant up command, it works just fine except that I can't ping it from my host machine.
I am using the following line in my Vagrantfile to enable port forwarding,
config.vm.network :forwarded_port, guest: 80, host: 4567
and I am trying to ping it in my host machine as follows,
ping 127.0.0.1:4567
Can someone please tell me how can I fix this mac error issue so that I can ping and access my box from my local machine ?
EDIT:
I have tried this code to set the MAC address but its not doing anything either.
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--macaddress1", "auto"]
end

How to set eth0 MAC address in Vagrant with the VMware provisioner?

Vagrant relies on VMware (Workstation and Fusion) to generate the MAC address of eth0 (the first and default ethernet interface) on a guest being deployed from a box.
I would like to fix this MAC address so it is static and not regenerated each time the VM is recreated so that the VMware DHCP service can assign it the same IP address each time.
First make sure that the VMware DHCP service will assign an IP address to a specified MAC address by editing vmnetdhcp.conf which has different locations depending on OS. Place an entry at the end of the file replacing the hostname, MAC and IP with desired values:
host hostname {
hardware ethernet 00:0A:AA:AA:AA:AA;
fixed-address 192.168.1.1;
}
Restart the VMware DHCP service to load these changes.
In your Vagrantfile use the following settings to configure the default network interface:
Vagrant.configure("2") do |config|
config.vm.define 'hostname' do |hostname|
hotname.vm.box = box
hostname.ssh.host = '192.168.1.1'
puppet.vm.provider :vmware_fusion do |v, override|
v.vmx['ethernet0.addressType'] = 'static'
v.vmx['ethernet0.address'] = '00:0A:AA:AA:AA:AA'
end
puppet.vm.provider :vmware_workstation do |v, override|
v.vmx['ethernet0.addressType'] = 'static'
v.vmx['ethernet0.address'] = '00:0A:AA:AA:AA:AA'
end
end
end
Next time the virtual machine is brought up with vagrant up it will assigned the static MAC and recieve the same IP address from DHCP.
Other vmx keys could also be manipulated for ethernet0 using this method.

vagrant add an interface without setting an IP address

I'm working through the puppet openstack instructions, and one of the requirements is as follows:
Each of the machines running the Openstack services should have a minimum of 2 NICS.
One for the public/internal network. This nic should be assigned an IP address
One of the virtual machine network. This nic should not have an ipaddress assigned
I've tried to specify a private network in Vagrant without an address, but hit the following error when calling vagrant up:
* An IP is required for a private network.
My first thought is to run a provision script to set the network, but there are warnings not to modify the network configuration files (the box is CentOS):
[vagrant#localhost ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth2
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.55.5
NETMASK=255.255.255.0
DEVICE=eth2
PEERDNS=no
#VAGRANT-END
Any ideas will be appreciated!
In the end, I created an 'unmanaged' network card by adding a virtualbox internal network:
vb.customize ["modifyvm", :id, "--nic2", "intnet"]
This works:
config.vm.network :private_network, ip: ""
You can try this:
node.vm.network :private_network, "ip": '0.0.0.0', auto_network: true

Resources