0

I have a virtualbox VM running elasticsearch on port 9200 which I'm trying to connect to my localhost. However every time I try to access the port, I get hit with

curl -v localhost:9200
* Rebuilt URL to: localhost:9200/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9200 (#0)
> GET / HTTP/1.1
> Host: localhost:9200
> User-Agent: curl/7.54.0
> Accept: */*
> 
* Recv failure: Connection reset by peer
* stopped the pause stream!
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer

Here is my vagrant file. I'm not really sure what I need to fix.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"

  config.vm.synced_folder "~/workspace", "/home/vagrant/projects"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "8096"
  end
  config.vm.network "forwarded_port", guest: 9200, host: 9200
  config.vm.network "private_network", ip: "192.168.50.4"
  config.vm.provision "file", source: "~/.ssh/id_rsa", destination: "~/.ssh/id_rsa"
  config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "~/.ssh/id_rsa.pub"
end

this is the printout for when I run vagrant reload

==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: A newer version of the box 'ubuntu/trusty64' for provider 'virtualbox' is
==> default: available! You currently have version '20180627.0.1'. The latest is version
==> default: '20180709.0.1'. Run `vagrant box update` to update.
==> 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: 9200 (guest) => 9200 (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
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.3.36
    default: VirtualBox Version: 5.2
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/gyeongbae.jung/Projects
    default: /home/vagrant/projects => /Users/gyeongbae.jung/workspace
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

2 Answers2

1

I had this problem. I start 8080 port in my virtualbox, and forward this port to my laptop(the host where is running this virtualbox). when I access this port from Firefox browser on my laptop, it return the 'connect reset by peer' error.

After some search on internet, I found the answer: Connection Reset when port forwarding with Vagrant

The root cause is:

I start the 8080 port in my virtualbox was listening 127.0.0.1 but not 0.0.0.0. if I change the listening ip from 127.0.0.1 to 0.0.0.0 then my problem was fixed.

In my case, I used kubectl port-forward function to start the port:

Problem command:

root@myhost:~# kubectl port-forward service/my-api 8080 -n test

Forwarding from 127.0.0.1:8080 -> 8085 Forwarding from [::1]:8080 -> 8085

Problem fixed command:

root@myhost:~# kubectl port-forward service/my-api 8080 --address 0.0.0.0 -n test
Forwarding from 0.0.0.0:8080 -> 8085

It means if you use other service to start the port, you need to configure this service to listen 0.0.0.0 rather than 127.0.0.1. Then this problem would be fixed.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
kain
  • 214
  • 2
  • 4
0

Could you post the specific version of VirtualBox you are using? I can only see you are using 5.2 but not which patch version and revision. And what operating system are you running on?

This issue seems to have happened a few times previously based on bad versions of VirtualBox and OSX: i.e. this report

Regardless, try downgrading to a known good version of VirtualBox, 5.1.6 and 5.1.10 seem to be good versions.