When I try to connect from a PostgreSQL client on the host system to the PostgreSQL server on a VirtualBox guest system, I get a "connection attempt failed" message.
The host system is Windows XP. I'm running VirtualBox 3.1.2. The guest system is Ubuntu 9.10 Karmic Koala with PostgreSQL 8.4.
I've forwarded port 5432 in VirtualBox as described in the manual and this post. When I run vboxmanage getextradata vmname enumerate
, I get these entries (among others):
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/pgsql/GuestPort, Value: 5432
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/pgsql/HostPort, Value: 5432
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/pgsql/Protocol, Value: TCP
I configured PostgreSQL security in /etc/postgresql/8.4/main/pg_hba.conf with these entries:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 192.168.1.0/24 md5
host all all 10.0.2.2/32 md5
Then I reloaded PostgreSQL with sudo /etc/init.d/postgresql-8.4 reload
.
For diagnostic purposes only, I've disabled my Windows firewall and my Ubuntu firewall (sudo ufw disable
).
Anybody know what steps I've missed?
OK, I found the missed step thanks to this post.
I had forgotten to set the listen_addresses setting in postgresql.conf. I'm using this value, but it could be more restricted:
Just to clarify, when you connect to PostgreSQL from the host, use localhost as the server and 5432 as the port. VirtualBox will forward that port to the guest.
I also realized that some settings require you to restart PostgreSQL instead of just reloading it. The command is: