centosvagrantvirtualboxvagrantfilevagrant-provision

telnet: connect to address 192.168.33.x: Connection refused - over Vagrant centos machine


I have created a centos machine and installed nexus service over it. Nexus service is running on 8081 port which i have opened from the vagrant file using below command inside the vagrant file.

    machine1.vm.network "private_network", ip: "192.168.33.x"
    machine1.vm.network "forwarded_port", guest: 80, host: 80
    machine1.vm.network "forwarded_port", guest: 8080, host: 8080
    machine1.vm.network "forwarded_port", guest: 8081, host: 8081

The nexus service is running fine on the centos machine but the telnet to the port from the same server as well as server from its network is failing. The port is not reachable from the host windows machine as well.

The server IP is reachable from its network machines, here all 3 network machines are created from vagrant file

I have tried to see and confirm the nexus service is actually running on 8081 port, and its running

I have tried to open a port 8081 to ensure firewall is not blocking using below command

iptables -A INPUT -p tcp -m tcp --dport 8081 -j ACCEPT

I have browsed through multiple forum to see if any solution works, I acknowledge this is very generic error even i have faced in past, but in this case not able to identify the root cause. I doubt if its related to vagrant specific configuration

Also, i tried to curl the service from centos server and host server, it doesnt work:

]$ curl http://localhost:8081
curl: (7) Failed connect to localhost:8081; Connection refused

netstat command doesnt give any result:

netstat -an|grep 8081
[vagrant@master1 bin]$

however the nexus service is up and running on the server with the same port

Here is vagrant file code

   config.vm.define "machine1" do |machine1|
    machine1.vm.provider "virtualbox" do |host|
      host.memory = "2048"
      host.cpus = 1
    end
    machine1.vm.hostname = "machine1"
    machine1.vm.network "private_network", ip: "192.168.33.x3"
    machine1.vm.network "forwarded_port", guest: 80, host: 80
    machine1.vm.network "forwarded_port", guest: 8080, host: 8080
    machine1.vm.network "forwarded_port", guest: 8081, host: 8081
    machine1.vm.synced_folder "../data", "/data"
   end


      config.vm.define "machine2" do |machine2|
              machine2.vm.provider "virtualbox" do |host|
      host.memory = "2048"
      host.cpus = 1
    end
    machine2.vm.hostname = "machine2"
    machine2.vm.box = "generic/ubuntu1804"
    machine2.vm.box_check_update = false
    machine2.vm.network "private_network", ip: "192.168.33.x2"
    machine2.vm.network "forwarded_port", guest: 80, host: 85
    machine2.vm.network "forwarded_port", guest: 8080, host: 8085
    machine2.vm.network "forwarded_port", guest: 8081, host: 8090
   end

   config.vm.define "master" do |master|
      master.vm.provider "virtualbox" do |hosts|
        hosts.memory = "2048"
        hosts.cpus = 2
      end
      master.vm.hostname = "master"
      master.vm.network "private_network", ip: "192.168.33.x1"
   end

end

As the nexus service is running on port 8081, i should be able to access the service from my host machine using http://localhost:8081.


Solution

  • The issue is most likely the Vagrant networking as you guessed. If you just want to access the nexus service running on guest from the host, perhaps this can be useful. To workaround, you may try to make the Vagrant box available on public network and then access it using the public IP and for that, you will have to enable config.vm.network "public_network" in your Vagrant file and then just do a vagrant reload. Once done, try accessing http://public_IP_of_guest:8081

    Please let me know how it goes.