Unable to connect to Vagrant Apache on one computer - apache

I have a project that includes a vagrant dev box, that works great on two (win7) computers at the office. However when I try it at home (win8.1) I can't connect to apache from the host.
Here's the blow by blow:
The project, including vagrantfile and apache config is stored in git
the VM boots fine, with no errors, I have tried reloading, and restarting the host
SSH to the VM works fine
shared folders between VM and host work
VM box is chef/centos-6.5
VM selinux is set to permissive
sudo service iptables status says firewall is disabled
disabling windows firewall does not fix the issue
a wget on the VM to itself gets the expected response
I normally use the address mydomain.127.0.0.1.xip.io:65000 to connect, but 127.0.0.1:65000 doesn't work either
the failure to get to webpage is quick (< 2s), and is ERR_CONNECTION_REFUSED in chrome
on my work pc I can telnet to port 65000, but at home I get connection refused
reload output:
C:\HashiCorp\Vagrant\bin\vagrant.exe reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'chef/centos-6.5' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 80 => 65000 (adapter 1)
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
GuestAdditions 4.3.12 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => F:/Work/sites/4.0
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.
I am leaning towards it being something to do with the host, as the VM/apache config should be identical with it coming via git; but I am at a complete loss as to what it could be.
Update - Extra Detail:
Running curl from windows host :
$ curl -Iv --connect-timeout 10 http://127.0.0.1:65000/robots.txt
* STATE: INIT =CONNECT handle 0x60002e1b0; line 1028 (connection #-5000)
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* STATE: CONNECT =WAITCONNECT handle 0x60002e1b0; line 1076 (connection #0)
* Connection timed out after 10000 milliseconds
* Closing connection 0
* The cache now contains 0 members curl: (28) Connection timed out after 10000 milliseconds
Disabling windows firewall, does not fix the issue.
And from the the VM it works :
[vagrant#localhost ~]$ time curl -Iv http://127.0.0.1/robots.txt
* About to connect() to 127.0.0.1 port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> HEAD /robots.txt HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 127.0.0.1
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Sat, 02 Aug 2014 16:26:29 GMT
Date: Sat, 02 Aug 2014 16:26:29 GMT
< Server: Apache/2.2.15 (CentOS)
Server: Apache/2.2.15 (CentOS)
< Last-Modified: Sat, 26 Jul 2014 16:20:14 GMT
Last-Modified: Sat, 26 Jul 2014 16:20:14 GMT
< ETag: "3f-278-4ff1b10953009"
ETag: "3f-278-4ff1b10953009"
< Accept-Ranges: bytes
Accept-Ranges: bytes
< Content-Length: 632
Content-Length: 632
< Connection: close
Connection: close
< Content-Type: text/plain; charset=UTF-8
Content-Type: text/plain; charset=UTF-8
IP tables
[vagrant#localhost ~]$ sudo service iptables status
iptables: Firewall is not running.
vagrant#localhost ~]$ sudo iptables -L Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT) target prot opt source
destination
Chain OUTPUT (policy ACCEPT) target prot opt source
destination

1st, check if the port 80 is correctly binded by apache, run the following within the VM to confirm.
netstat -nap | grep :80
Check if any iptables rules are in place
iptables -L
2nd, if you have Cygwin on Windows, run the following and see what you get. I reckon Windows firewall may be playing dirty ;-D
curl -Is http://127.0.0.1:65000
If you don't want to troubleshoot further and just want the service to be accessible from the host, an easy workaround may be to add a 2nd NIC (network interface) using bridge mode (public network in Vagrant) and do a vagrant reload. Once it is up, vagrant ssh into it and get the IP address (should be in the same network as the host). You should be able to access the service by using PUBLIC_IP:PORT
Vagrant.configure("2") do |config|
config.vm.network "public_network"
end

I have given Terry the accepted answer because that suggestion worked, and I believe will help most people.
However in my case I believe the culprit was some combination of skype, pending windows updates, and my preference to hibernate my PC rather than shutting down. I have had various networking issues since, and all of them have been solved by disabling skype from autoloading, and installing any windows updates pending at the time I have the error and restarting!
Even if I haven't used skype in days it still seems to gum up my system in between restarts / proper shutdowns.
Not the most high brow contribution to a Stack Exchange site ever, and dangerously close to superstition, but I am convinced of the connection.

Here's an off the wall answer. Check your DHCP server for another machine taking that IP address before your vagrant box. You may actually be connecting to some friend's phone or laptop instead.

It worked for me after using auto_correct: true. Just follow the tutorial in Hashicorp docs
config.vm.box = "ubuntu/trusty64"
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.network :forwarded_port, guest: 80, host: 4567,
auto_correct: true

Related

"SSH auth method: private key" vagrant problem

i want to setup a webserver using vagrant and i have problem with the command "vagrant up":
First i work on a virtual machine (Virtualbox) and i have to build my vagrant project inside virtualbox so I created a Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty32"
config.vm.network "private_network", ip: "192.168.68.8"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
end
config.vm.provision :shell, :path => ".provision/bootstrap.sh"
end
Then when i execute the command "vagrant up" it hangs on the last line:
zakaria#server:~/webserver$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 80 (guest) => 8080 (host) (adapter 1)
default: 80 (guest) => 8080 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
and the gui stucks too :
This is the picture knowing that i am already enabled VT-X in virtualbox settings.
One thing I encourage you to look is if you have HyperV on, Vagrant docs specifically say to disable it: https://www.vagrantup.com/docs/installation#windows-virtualbox-and-hyper-v
I suffered a similar problem and mine was related (mostly) to Docker Desktop Client for Windows.
I took the nuclear option and removed Docker and disabled a ton of features relating to containers and virtualisation (incl. most specifically Hyper-V) for Windows 10 and it worked (I no longer the get SSH auth method: private key timeout; I am slowly piecing back all the pieces I disabled to see which specific feature is a no-go for a working solution).
Until I removed all the features, my CPU was not recognising VT-x and Extended Page Tables ... once I made the above changes, Intel Processor Identification Utility and CPU-Z confirmed the CPU supported these, and I found that I was once again able to SSH without any timeout issues.

Access my AWS EC2 server index.html from external browser

I've been setting up an AWS EC2 server this week, and I'm almost there with what I want to do. But opening up as a web server is proving to be a stumbling block.
MY SETUP
I have an AWS EC2 instance running Red Hat EL7.
I have an Apache server running on my instance:
[ec2-user#ip-172-xx-xx-xx ~]$ ps -ef | grep -i httpd
root 18162 1 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18163 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18164 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18165 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18166 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18167 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
ec2-user 21345 20507 0 19:03 pts/1 00:00:00 grep --color=auto -i httpd
It seems to be listening on port 80:
[root#ip-172-xx-xx-xx ~]# netstat -lntp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18162/httpd
I added inbound rules to the "launch-wizard-1" security group (which is shown as the security group for the instance) for port 80 (HTTP) and 443 (HTTPS) with sources of "0.0.0.0/0" and "::/0"
And finally, for testing my setup, I created an index.html file in my document root (/var/www/html):
<html>
<h1>TEST!</h1>
</html>
THE PROBLEM
From my chrome browser on my computer, when I try to hit:
http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com/index.html
I just get:
This page isn’t working
ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com didn’t send any data.
ERR_EMPTY_RESPONSE
(I get the same when I hit one of my domain names which I've set up on there, which is what I'm really trying to do of course!)
I've tried connecting from Chrome on 2 different computers, and from Safari on my phone ("Safari cannot open the page because it could not connect to the server")
CHECKS I'VE PERFORMED
I don't believe I have any server firewall preventing this:
[root#ip-xx-xx-xx-xx conf]# /sbin/iptables -L -v -n
Chain INPUT (policy ACCEPT 3575 packets, 275K bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 2215 packets, 350K bytes)
pkts bytes target prot opt in out source destination
Testing with telnet from a terminal session on my mac, port 80 appears to be open. Firstly using the IPv2 Public IP:
telnet 18.xxx.xxx.xx 80
Trying 18.xxx.xxx.xx...
Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com.
Escape character is '^]'.
Connection closed by foreign host.
and using the Public DNS (IPv4):
telnet ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com 80
Trying 18.xxx.xxx.xx...
Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com.
Escape character is '^]'.
Connection closed by foreign host.
And again, the same goes for my domain names - telnet to port 80 shows "Connected".
- Is the fact that the "foreign host" closes the connection immediately significant? Should it stay open if everything is working as it should?
Running curl on the host correctly returns my simple index.html file:
[ec2-user#ip-172-xx-xx-xx ~]$ curl localhost
<html>
<h1>TEST!</h1>
</html>
However, running a curl on my local computer - to the server - returns:
curl -v http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com:80
* Rebuilt URL to: http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com:80/
* Trying 18.xxx.xxx.xx...
* Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com (18.xxx.xxx.xx) port 80 (#0)
> GET / HTTP/1.1
> Host: ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com
> User-Agent: curl/7.43.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com left intact
curl: (52) Empty reply from server
I also tested the webserver "internally" by running google chrome (headless) on the server to create a screenshot, downloaded to my local computer and it shows TEST! (i.e. its working):
google-chrome-stable --headless --disable-gpu --screenshot http://localhost
One more thing to add - when I attempt the hit the webserver from my local machine, nothing shows in the webserver logs (error_log or access_log) on the server.
So, my opinion is that the web server is up and running, works locally, but is not working correctly for anything coming from "outside". I'm stumped now though.
Doh! I rebooted the instance and.. all working now!
22 years working with computers and it took me 22 hrs to resort to a reboot. Fool!
Connect to your EC2 instance using ssh on terminal
Install python if not installed
Start a python server using nohup to continuously use the server
nohup python -m http.server &
This usually open port 8000, goto EC2 Security Group Make source anywhere or as needed.
Navigate to the folder having index.html, file path will look like below
http://ec2---.compute-1.amazonaws.com:8000/folder/website/
You will be able to develop and see your changes as needed.

Vagrant up on Laravel/Homestead stuck on ssh auth method

Can anyone help me, the vagrant up stops every time at SSH auth method. I have been stuck for 4 days. Please guys help me.
Vagrant Version is 1.9.2
Virtual Box Version is 5.0.16
Sam#sam-PC MINGW32 /c/www/Homestead (master)
$ vagrant up
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...
==> homestead-7: Clearing any previously set forwarded ports...
==> homestead-7: Clearing any previously set network interfaces...
==> homestead-7: Preparing network interfaces based on configuration...
homestead-7: Adapter 1: nat
homestead-7: Adapter 2: hostonly
==> homestead-7: Forwarding ports...
homestead-7: 80 (guest) => 8000 (host) (adapter 1)
homestead-7: 443 (guest) => 44300 (host) (adapter 1)
homestead-7: 3306 (guest) => 33060 (host) (adapter 1)
homestead-7: 5432 (guest) => 54320 (host) (adapter 1)
homestead-7: 8025 (guest) => 8025 (host) (adapter 1)
homestead-7: 27017 (guest) => 27017 (host) (adapter 1)
homestead-7: 22 (guest) => 2222 (host) (adapter 1)
==> homestead-7: Running 'pre-boot' VM customizations...
==> homestead-7: Booting VM...
==> homestead-7: Waiting for machine to boot. This may take a few minutes...
homestead-7: SSH address: 127.0.0.1:2222
homestead-7: SSH username: vagrant
homestead-7: 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.
Here is my YAML File
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/www/Sites
to: /home/vagrant/Sites
sites:
- map: test.app
to: /home/vagrant/Sites/Test
databases:
- homestead
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
Can anyone help me, the vagrant up stops every time at SSH auth method. I have been stuck for 4 days. Please guys help me.
Vagrant Version is 1.9.2
Virtual Box Version is 5.0.16

Vagrant SSH connection failure

I have an Ubuntu 16.04 LTS and three Vagrant/VirtualBox VMs that need to be turned on at the same time
When I installed Vagrant with VirtualBox, the first day, SSH connection was going correctly. At the following day I obtained this at the three machines (Here is an example of one of them):
xxxx-callserver#xxxxcallserver-Precision-WorkStation-T5400:~/VM$ vagrant up vvs --provision
Bringing machine 'vvs' up with 'virtualbox' provider...
==> vvs: Checking if box 'dmservices/fedora17-x86_64' is up to date...
==> vvs: Clearing any previously set forwarded ports...
==> vvs: Clearing any previously set network interfaces...
==> vvs: Preparing network interfaces based on configuration...
vvs: Adapter 1: nat
vvs: Adapter 2: hostonly
==> vvs: Forwarding ports...
vvs: 22 (guest) => 2222 (host) (adapter 1)
==> vvs: Running 'pre-boot' VM customizations...
==> vvs: Booting VM...
==> vvs: Waiting for machine to boot. This may take a few minutes...
vvs: SSH address: 127.0.0.1:2222
vvs: SSH username: vagrant
vvs: SSH auth method: password
vvs: Warning: Remote connection disconnect. Retrying...
vvs: Warning: Authentication failure. Retrying...
Until it triggers a Time Out
And when I try to vagrant ssh vvs, with or without --plain:
==> vvs: The machine you're attempting to SSH into is configured to use
==> vvs: password-based authentication. Vagrant can't script entering the
==> vvs: password for you. If you're prompted for a password, please enter
==> vvs: the same password you have configured in the Vagrantfile.
Permission denied (publickey).
This the part of the Vagrantfile for that machine (the only differences between the three machines is the name, the ip (inside the same network 192.168.33.0/24) and that the other two are debian/jessie64):
Vagrant.configure("2") do |config|
...
...
config.vm.define "vvs" do |vvs|
vvs.vm.hostname = "vvs"
vvs.vm.box = "dmservices/fedora17-x86_64"
vvs.vm.network "private_network", ip: "192.168.33.4"
vvs.ssh.username = "vagrant"
vvs.ssh.password = "vagrant"
vvs.vm.synced_folder "/home/xxxx-callserver/NetBeansProjects", "/NetBeansProjects", create: true, type: "virtualbox"
vvs.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
v.customize ["modifyvm", :id, "--vram", "64"]
end
end
Thanks in advance and ask me for more info if needed
EDIT: Output of vagrant ssh-config
Host avaya
HostName 127.0.0.1
User vagrant
Port 2201
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/xxxx-callserver/VM/.vagrant/machines/avaya/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
Host videogateway
HostName 127.0.0.1
User vagrant
Port 2200
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/xxxx-callserver/VM/.vagrant/machines/videogateway/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
Host vvs
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentitiesOnly yes
LogLevel FATAL
Please check whether you explicitly forwarding each of your Vagrant guest port 22 to different host port. I am not familiar with vagrant script, but you really need a line to explicitly specify different port, because default Vagrant always map 22 to 2222. For multiple VM. This mean only the first vagrant VM will map it correct, the rest will failed. In Vagrantfile, you need something like this for each guest machine.
# avaya
config.vm.network :forwarded_port, id: 'ssh', guest:22, host: 2201,
# videogateway
config.vm.network :forwarded_port, id: 'ssh', guest:22, host: 2200,
# vvs
config.vm.network :forwarded_port, id: 'ssh', guest:22, host: 2222,
Since you already have the first VM setup the port forwarding from 22 to 2222, all the 3 VM will failed change the port forwarding map. Perhaps you should consider change host vvs forwarding to different host port, so it will not conflict with future adhoc vagrant startup that use the default power forwarding.

Cannot ssh into newly created vagrant box

Just created a new vagrant box with minimal centos 7.
I followed this guide. https://blog.engineyard.com/2014/building-a-vagrant-box
Also I have everything in place as mentioned in official vagrant guides here and here
However when I try to do vagrant up. It timeouts when trying to ssh into the box.
What might be causing this?
My network adapter in the VM is NAT.
I tried to set private network ip
config.vm.network "private_network", ip: "192.168.50.4"
I was able to ssh using this ip and vagrant as username and password. I wonder why vagrant is not able to ssh?
Here is the output of vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'my'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: my_box_default_1475351710988_24744
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
And after a long time it gives this error.
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.
ssh keys set using the following commands
mkdir -p /home/vagrant/.ssh
chmod 0700 /home/vagrant/.ssh
wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant:vagrant /home/vagrant/.ssh
There was a bug in 1.8.5 that can explain this.
can you please upgrade to 1.8.6 ?
Have you tried using
vagrant ssh
This might help someone.
Try running ip addr command and if the network interface has no IP address assigned to it then you need to set ONBOOT to yes.
[root#localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
Then change ONBOOT=no to ONBOOT=yes
Restart the machine and run ip addr to make sure that network is started properly and an IP address is assigned to the network interface.