Hi Dennis,

Thank you for looking at my question.

When I researched this problem on the Internet, it sounded as though people 
were saying that the issue is that a Vagrant VM listens to traffic from the 
"outside" (for lack of a better term) on one port and then passes that 
traffic to another port on its "inside", almost like Vagrant is a container 
with external and internal ports.  I don't understand how Vagrant works 
internally but this sounded plausible so initially I did this in my 
Vagrantfile:

  config.vm.define "db" do |db|
    ...
    db.vm.network :private_network, ip: "192.168.2.101"
    db.vm.network :forwarded_port, guest: 5432, host: 5432
    ...
  end


However, this forwarded_port directive resulted in Vagrant raising this 
error whenever I would do Vagrant up or Vagrant reload:


Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 5432 is already in use
on the host machine.


To fix this, modify your current project's Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:


  config.vm.network :forwarded_port, guest: 5432, host: 1234

This is what caused me to revert to creating two separate ports, and 
outside port 15432 and the 5432 port that PostgreSQL is actually listening 
on inside the VM.

I've just now tried disabling this forward port and reloading vagrant:

db.vm.network :forwarded_port, guest: 5432, host: 5432, disabled: true

I also edited the postgresql.conf file on my db server and restarted 
postgresql:

# postgresql.conf
port = 5432

$ psudo service postgresql restart

So, to re-cap


   1. I'm no longer doing a port forwarding on the database virtual machine
   2. PostgreSQL is listening on port 5432 on the DB VM.
   3. The PostgreSQL pg_hba.conf file's last line is:  host all all 
   0.0.0.0/0 trust
   4. I've disabled all firewall rules.

Even after all of these changes, when I try to run a psql command on my web 
VM to the database VM, I still get the "Connection refused" message.



On Tuesday, June 4, 2019 at 9:17:36 AM UTC-7, Dennis Chang wrote:
>
> Hi Robert,
>
> So if you look at your Vagrantfile, you have the db00 host performing 
> port_forwarding from the host 15432 to the guest 5432.
> However, judging by your netstat output (from within your db00 VM) it 
> looks like Postgres is listening on 15432.
>
> So there is no way web00 nor the host will be able to reach db00 
> (postgres).
>
> Port forwarding is for the benefit of the host (you don't need it if you 
> only care about web00 to db00 connectivity (the private network will 
> suffice).
> So if postgres is listening on 15432 (and will accept connections from 
> 0.0.0.0), then from web00 you can do 'telnet 192.168.2.101 15432' and it
> should allow a connection.
>
>

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vagrant-up/ae3d9ce2-ed92-4977-85c5-42db31733abc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to