skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. This may have many sources 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search