3

There are similar questions but nothing worked for me. I have already added this line to my pg_hba.conf:

host all all all trust

And this one to my postgresql.conf:

listen_addresses = '*'

My networking settings in the Vagrantfile are:

config.vm.network "private_network", ip: "10.0.0.0"
config.vm.network :forwarded_port, guest: 3000, host: 3000, auto_correct: true

When I try to connect from the host, I get:

$ psql -h 10.0.0.0 -U <username> -d <database>
psql: could not connect to server: Permission denied
    Is the server running on host "10.0.0.0" and accepting
    TCP/IP connections on port 5432?

The same command from the guest works with no problems. What am I missing??

[UPDATE]

I changed the private network ip to "192.168.1.77" (got it from a working example) and it worked. Still don't know why 10.0.0.0 wasn't good though, since it is in the reserved private address space, so I'll leave the question unanswered.

1
  • it tells you if the port is opened for 5432 but you did not forward in your vagrantfile Commented Aug 25, 2015 at 16:17

3 Answers 3

4

You need to forward the postgres port, you're only forwarding 3000, not 5432.

Sign up to request clarification or add additional context in comments.

3 Comments

So, from what I think I understand about networking, I can either use port forwarding or simply create a private network so I can access any port without having to specify each of them in my Vagrantfile. If I forwarded, say, port 5433 in the host to 5432 in the guest, I'd be able to connect to the PostgreSQL server with psql -h localhost -p 5433 -U <username> -d <database>. But since I have a private network and the static ip 10.0.0.0 is assigned to the guest, I shouldn't need to do any port forwarding. I should be able to connect to 10.0.0.0 (port 5432 by default) instead of localhost:5433.
Just did the experiment and confirmed: by using port forwarding instead of private network, I managed to connect. I still don't know why I can't connect through the private network though, so I'll leave the question unanswered.
Dmitri you need to set the ip of your host in the postgresql config file.. Otherwise the server will reject connections from external ips.
3

In addition to forwarding port 5432 to another port on my host machine in my Vagrantfile, I added the following to my pg_hba.conf file in my vagrant machine, restarted postgresql, and it finally allowed me to connect from the host:

host    all             all             0.0.0.0/0                md5

I found the suggestion here: https://github.com/laravel/framework/issues/11339

Comments

2

I believe the reason you could not connect is that technically 10.0.0.0 is the network address of the range 10.0.0.0/8 (and 10.255.255.255 is the broadcast address and should also not work). The first address of each range is the network address and is not allowed to be a routable host (similarly 192.168.0.0 should fail in the same way since it's a 16-bit block).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.