Janton Zeng
Janton Zeng

Reputation: 11

psql - Mac trying to connect postgreSQL in Ubuntu system installed in a virtual machine in remote server

Apologize in front, maybe the situation here is a bit complicated. I searched everywhere online but couldn't find a perfect solution, plus I have tried almost all the solutions mentioned in other posts.

So I have a postgreSQL database installed in a Ubuntu system. The system is actually a virtual machine on the VMware workstation 12, which is installed on Windows 7 professional. Now I am trying to remotely access the postgreSQL database through my MacBook pro 2013.

In the Mac terminal, the command line I tried is:

psql -U postgres -h xxx.xxx.xxx.xx

"xxx.xxx.xxx.xx" represents the IP address of the Windows 7 machine. The result is a failure:

psql: could not connect to server: Operation timed out Is the server running on host "169.254.121.2" and accepting TCP/IP connections on port 5432?

host all all 0.0.0.0/0 md5

  1. Edited the postgresql.conf to include

listen_addresses='*'

  1. Restarted postgres service.
  2. Disabled firewall on the host.
  3. I checked by running the psql command locally and it worked. Also, on the same VMware I have other Ubuntu systems. They are all fine to connect and access the data in this Ubuntu system.
  4. Running Nmap, the output is

PORT STATE SERVICE

5432/TCP open postgresql

Upvotes: 0

Views: 618

Answers (1)

Janton Zeng
Janton Zeng

Reputation: 11

Somehow managed to get it working..

So when I ran "Nmap" on the other Ubuntu system towards this one, it does shows

PORT STATE SERVICE

5432/TCP open postgresql

However, when I ran "Nmap" on my Mac, it's a different port, 3389, which is mainly used for Windows remote desktop. So what I did was to check the network configuration of this Ubuntu virtual machine from "bridged" to "NAT" and did a port forwarding to 5432. It is working fine now..

I read in some places saying that VMware favors bridged whereas VirtualBox favors NAT+port forwarding. I am quite confused as it is certain not the case in my situation. Maybe I am wrong.

Upvotes: 0

Related Questions