Not able to access vagrant box from host on windows 10 - windows

I have a vagrant box setup with below config
config.vm.hostname = "devops-sk-vm"
config.ssh.forward_agent = true
config.ssh.username = "vagrant"
config.vm.box = "generic/centos8"
I have a Jenkins running on VM however I am not able to access that from host machine. below are the ports forward and I didn't supply any specific IP. Running Jenkins on 9003.
for i in 9000..9100
config.vm.network :forwarded_port, guest: i, host: i
end
Box provider: Virtual box
version: 6.1.16
Vagrant version: 2.2.14
Host: Windows 10 Pro 2020
All inputs appreciated.

I have been able to solve this by checking the firewall service running on generic/centos8. firewalld service runs by default it seems and I had to whitelist the ports to get the traffic in.
Followed this guide to initially disable it and then open the ports.
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7

Related

Vagrantbox with Hyper-V not starting

I'm trying to setup a vagrantbox with Hyper-V on my local windows-10 mashine. My Workstation is running behind a proxy, but I configured a local cntlm proxy to get around these limitations. Proxy settings work fine since I was able to install a vagrant plugin and downloan a box image.
But now my guest linux does not start up and I am running out of ideas.
My vagrant file
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-18.04" # ubuntu 18.04 image with support for virtual box and Hyper-V
config.vm.hostname = "skywalker"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.provider "hyperv" do |hv|
hv.memory = "2048"
end
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'" # prevent tty errors
# install the vagrant plugin "vagrant-cachier" to cache downloaded artifacts
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end
# vagrant behing local cntlm proxy if plugin exists (= provinzial win10 workstation)
if !Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = "http://localhost:3128/"
config.proxy.https = "http://localhost:3128/"
config.proxy.no_proxy = "localhost, 127.0.0.1"
end
# --------------------------------------------------------------------------
# provision virtual mashine (basic setup) and install applications in VM
#config.vm.provision "shell", path: "scripts/install-ansible.sh"
config.vm.provision "shell", path: "scripts/install-ncdu.sh"
config.vm.provision "shell", path: "scripts/install-git.sh"
config.vm.provision "shell", path: "scripts/install-openjdk-11.sh"
config.vm.provision "shell", path: "scripts/install-maven.sh"
config.vm.provision "shell", path: "scripts/install-node-npm.sh"
config.vm.provision "shell", path: "scripts/install-docker.sh"
config.vm.provision "shell", path: "scripts/install-docker-compose.sh"
# npm webserver
config.vm.provision "shell", path: "apps/install-npm-apps.sh"
config.vm.network "forwarded_port", guest: 8000, host: 8000
# artifactory setup (start artifactory after vm startup)
config.vm.network "forwarded_port", guest: 8081, host: 8081 # artifactory from docker
config.vm.network "forwarded_port", guest: 8082, host: 8082 # artifactory from docker
# See README.md for Artifactory in Docker
end
Starting the box with this settings results in
C:\home\work\workspace\vagrant-boxes\skywalker (master -> origin)
λ vagrant up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Verifying Hyper-V is accessible...
==> default: Importing a Hyper-V instance
default: Creating and registering the VM...
default: Successfully imported VM
default: Configuring the VM...
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
default: Timeout: 120 seconds
default: IP: fe80::215:5dff:fe02:8b01
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: fe80::215:5dff:fe02:8b01:22
default: SSH username: vagrant
default: SSH auth method: private key
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
On a different mashine with VirtualBox as VM provider this Vagrantfile works fine. Sadly I cannot use any VM provider other than Hyper-V on my windows mashine due to limitations which are out of my control ...
I set up Hyper-V using Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All.
Any ideas? Thanks in advance and best regards. Sebastian
I went through this exercise last week and saw similar problems. I made lot of progress following these steps and the vm's get spun up at a reasonable time under windows 10 hyper-v. This is what i did.
Followed this blog and tried creating a vm successfully first.
https://win32.io/posts/Vagrant-Install-HyperV
Then i created a simple vagrantfile and got it to work successfully. Here is mine ,
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
config.vm.hostname = 'utility-server-1'
config.vm.network 'public_network', bridge: 'Internet'
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider "hyperv" do |vb|
vb.memory = "4024"
vb.cpus = 2
vb.vmname = 'utility-server-1'
end
end
Once this works, add more complex steps from your vagrantfile, like shell scripts and forwarded ports.

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.

Connecting my vagrant and another VM in VirtualBox

For my web development, I use a vagrant install to run a local instance of the website with the following config:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network :forwarded_port, host: 4567, guest: 80
config.vm.hostname = "some-website"
config.vm.synced_folder ".", "/var/www/public", :mount_options => ["dmode=777", "fmode=666"]
config.vm.provision :shell, path: "bootstrap.sh", :args => "some-website", privileged: false
end
This website is accessible in the browser on the specified IP.
However, I also have VM's for cross browser testing and these VM's don't have access to the IP address of the Vagrant box.
I need them to connect, because I want to do cross browser testing on that locally running vagrant box.
A couple of StackOverflow searches gave me the option of changing the private_network to a public_network, but then I can't access the IP anymore.
Also adding virtualbox__intnet: true doesn't work.
Would anyone be able to come up with a solution for this? It would be great if I could access the IP from the IE9 VM, directly into the Vagrant VM.
So, to clarify, currently:
Laptop can access Vagrant (laptop -> VM)
IE9 VM can't access Vagrant (VM -!> VM)
What I want:
Laptop can access Vagrant (laptop -> VM)
IE9 VM can access Vagrant (VM -> VM)
As Frédéric pointed out: the private_network is actually accessible from another VM on the same host.
My problem seemed to be WordPress itself and not related to Vagrant or the VM setup.

How can I access a vagrant guest from another virtualbox guest?

The scenario is that my dev environment is on a Vagrant box on my laptop (host) and I would like to do browser testing in a vitualbox vm, so I need to see one vm from another.
The vagrant box's port is :8080 which is forwarded to the host on the same port :8080. So I can see the server from the host at localhost:8080
Which address should I be using for the browser testing vm?
The testing vm's default gateway?
The vagrant vm's ip?
The host's virtual network ip?
And should I be using a NAT or host only adapter on the browser testing vm?
That makes for a lot of combinations, all of which I believe I have tried. What else do I need to understand here?
In your use case, you should be using Bridged networking (Public Network in Vagrant). If the VMs reside on the same host, you can even use internal (Private Network in Vagrant).
If using Public Network, the VM's 2nd NIC will be able to obtain an IP address from the DHCP server in your network (e.g. your home router).
Simply add the following code block in your Vagrantfile and do a vagrant reload
Vagrant.configure("2") do |config|
config.vm.network "public_network"
end
You should be able to get the IP address by using vagrant ssh and ifconfig / ip addr show.
In case you don't want to go with public_network just like me then you should do the steps below using private_network:
Open Vagrantfile from your project root
Search for config.vm.network
Add this line config.vm.network "private_network", ip: "192.168.33.10". Remember this is not the IP of your base machine it's a virtual-box IP address and your machine IP should be different. You can say it's a fake IP address so change it to anything else like 192.168.30.20.
Reload your vagrant using vagrant reload.
Now go to your other virtual guest in my case it's the Windows Guest 2. My base is Linux Mint Vagrant box is on Ubuntu Guest 1. Open C:\Windows\System32\drivers\etc\hosts file as admin and do the above IP's entry in there like 192.168.33.10 local.youralias.com. And save the file, after that you can now browse the site now at http://local.youralias.com/.
In case your guest 2 is also Linux just edit this file sudo vi /etc/hosts, and add this line at top of it 192.168.33.10 local.youralias.com. Now save and exit and browse the URL :)
Enjoy! Happy coding.
Adding to accepted answer, you can actually set IP and specify which network interface to use.
My setup on linux box via wifi and static IP:
You can find your wifi interface name by running ifconfig command.
Vagrant.configure("2") do |config|
config.vm.network "public_network", :bridge => 'wlp8s0', ip: "192.168.1.199"
end
This may have many source cause. In my case, I use vagrant fedora boxe.
I tried:
First using the private_network that I attached to a host only adapter and launched httpd service to test the connection between guest and host
config.vm.network "private_network", type: "dhcp", name: "vboxnet2"
config.vm.network "forwarded_port", guest:80, host:7070
but I was not able to ping my guest machine from the host and could no telnet the httpd service opened
Second using public_network and launched httpd service to test connectivity
config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", use_dhcp_assigned_default_route: true
I could ping my guest from my host but I could not telnet the httpd service.
For this two use case, the issue was that the port 80 on the fedora guest host was blocked by the firewall. Here is what fixed the issue and get all working for both privat_network and public_ntwork:
firewall-cmd --permanent --add-port 80/tcp #open the port permanently
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --list-port # list to check if the port was opened
systemctl stop firewalld # stop and open the firewall service
systemctl start firewalld
Old question, new answer: [disclaimer: i am not a vagrant expert]
both solutions might work but the solution in the "vagrant way of thinking" is that some component in your guest (rinetd?) should forward any requests to unknown ports to the host. From the host the request could then be mapped (via vagrant port forwarding) to a services that is running in the other guest.
So, to resume:
1.in guest-1 we do localhost:1234. Guest-1 will detect that this port is not available and forward to host
2. the host will check the vagrant port forwarding and forward to guest-2
3. in guest-2 we have some nice service listening to post 1234
4. done.

Vagrant port forwarding not working. Cups not accesible from host

So I'm working with vagrant and I'm trying to use it as a printing server. I installed cups.
Internally everything works just fine. I can even make a quick curl to my localhost:631 (cups port inside my vagrant) and there's everything.
The thing is I cant access it in any way I try from the host machine.
Obviously I forwarded the port and I've tried with several ports. I've also tried with Debian squeeze and Ubuntu 12.04. Here is my current Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "guruDebian"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 631, host: 6363 ## HERE IS CUPS
end
Any ideas?
I think what you will find is that the default cups config file is locked down to only work from localhost for security reasons.
Inside your Vagrant VM open the /etc/cups/cupsd.conf file and change the following line:
Listen localhost:631
to
Listen 0.0.0.0:631
That should allow you to connect from any host.
Have you tried accessing port 8080 of guest to your host? if no, and the services inside guest are running. then its a firewall issue in guest.
Try to turn firewall temporarily
service iptables off
then try to access it again from host.

Resources