vagrant add an interface without setting an IP address - vagrant

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

Related

How do I create a isolated network on Vagrant?

I have started learning Vagrant.
What I want to do is create a private network with 2 guests :
ip private network: 192.168.3.0
ip guest #1 (centos8): 192.168.3.1
ip guest #2 (ubuntu20.o4): 192.168.3.2
So:
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.3.1"
end
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.3.2"
end
I thought that setting a network as "Private" no other guests on Vagrant were able to do ping to them or do ssh... Because I can do it.
What Must I do? to isolate that network from others guests.
The only solution I know is specific to the VirtualBox provider, using VirtualBox's internal network feature:
Internal Networking is similar to bridged networking in that the VM can directly communicate with the outside world. However, the outside world is limited to other VMs on the same host which connect to the same internal network.
https://www.virtualbox.org/manual/ch06.html#network_internal
In vagrant you would specify the internal network like this:
config.vm.network "private_network", ip: "192.168.100.4",
virtualbox__intnet: "isolatednet1"
Where isolatednet1 can be any name you want for the internal network. All VirtualBox VMs using the isolatednet1 network will be able to communicate with each other, but they won't be able to communicate with VMs outside the internal network.
Note that instead of a network name you can use a boolean value of true for virtualbox__intnet but in that case Vagrant will assign all VMs to the network "intnet". So if you want to achieve isolation you need to assign a unique internal network name for each group of VMs you want to isolate.

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.

Networking errors causing vagrant machine not to start up

I ran into the following error when I execute "vagrant up" command.
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.
Vagrant file:
Vagrant.configure("2") do |o|
o.vm.box="centos/7"
o.vm.network "private_network", ip: "192.168.1.13"
o.vm.provision "shell", :path=>"setup.sh"
end
setup.sh:
sudo yum -y update
sudo yum -y install vim,git,gedit,nmap
sudo systemctl restart httpd
Nothing is started but I see a machine in Virtual box and I double click and I start as usual. Could assign static IP but no network to outside world. Not sure where the things are going wrong.
Any help would be very much appreciated.
Thanks
Jim
I'm not sure I've seen that particular error before. However I do have some Vagrant (VirtualBox) VMs that use both a private network to talk to each other, and NAT to talk to the wider world.
I make sure these don't conflict by specifying different private IPv4 network ranges for each. For example:
Vagrant.configure(2) do |config|
# host-only interface address
config.vm.network "private_network", ip: "192.168.0.2"
# NAT interface address range
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--natnet1", "172.16.0.0/12"]
end
end

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 access Vagrant Box in public network

I had created on e box inside vagrant. In the Vagrantfile, I had given the network as
Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network :private_network, ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
config.vm.network :public_network
I can't access the VagrantBox outside the VLAN. I need to access the Vagrant Box in public network. How to configure vagrantfile in such a way that I need to access in public network?
Uncomment the line in Vagrantfile
config.vm.network :public_network
The file will look like below
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "box_name"
config.vm.network :public_network
end
Save it, restart the VM by using vagrant reload.
For VirtualBox, it'll use Bridged mode for networking. Which means the VM will acquire an IP address from the DHCP server for the VLAN.
You can also set the VLAN IP with: config.vm.network :public_network, ip: "192.168.0.160"
Refer to => Public Network
By default, vagrant deletes the default (working) route on additional bridged networks inside the VMs. My problem which was specific for DHCP could only be solved by configuring the bridged network as follows:
config.vm.network :public_network, :bridge => 'em1',:use_dhcp_assigned_default_route => true
Courtesy of https://groups.google.com/forum/#!msg/vagrant-up/yNhWV42pcgk/NbOck1xqtFQJ
There maybe an equivalent for static IPs.
I was unable to figure this out using anything I read (which was hours and hours of research). Instead, this is how I figured it out:
Below is my Vagrantfile. The important part for me was config.vm.network :public_network. After reloading vagrant with vagrant reload, I chose the first option of the 4 available bridged network interfaces (I’m not sure if I chose the correct one by luck, or if any would have worked, I’ll experiment), then sshed into the vagrant box with vagrant ssh, did ifconfig, chose one of the 3 ip addresses that it output, pasted that into my browser, and it worked.
The thing no one else seemed to talk about was sshing into the vagrant box and finding one of the ip addresses there. I hope maybe this helps some other networking newb in the future.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "bahmni-team/bahmni"
config.vm.box_check_update = true
config.ssh.insert_key = false
config.vm.network :public_network
config.vm.synced_folder "..", "/bahmni", :owner => "vagrant"
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", 4092, "--cpus", 2, "--name", "Bahmni-RPM"]
end
end
Finally! This is years later but I couldn't find more current info. For me, the problem was that I not only had a private network defined, but also a forwarded port, and all that was working well. I then commented out the private_network, replaced it with public_network, and couldn't reach anything. Tried everything I found here and elsewhere, no go. It's only when I commented out the port forwarding that things started working again, without any of the manual bridging/dhcp configuration rigamarole suggested.
Single VM environment
you can use command: vagrant ssh
Multi VM environment
you can use command: vagrant ssh {hostname}

Resources