How to Access to PostgreSQL in VirtualBox Guest OS from Windows Host

Here’s a tips to connect PostgreSQL in VirtualBox guest OS, from Windows. The article suppose host OS is Windows, but theoretically it is also the same way in other host OS.


I installed VirtualBox in Windows, and installed Ubuntu as guest os. After that, I installed PostgreSQL server into guest Ubuntu.


  • Windows 10


  • Ubuntu 17.10
  • PostgreSQL 9.5

Guest OS was connected with NAT system, and I configured port forwarding. If you have guest os connected through NAT, it is needed to build port forwarding connecting to the guest os PostgreSQL, TCP 5432.

Example of Port Forwarding

Change Settings

To connect PostgreSQL in the guest OS from the host OS, you have to change PostgreSQL configuration.

Listen Addresses

In /etc/postgresql/9.5/main/postresql.conf, there’s listen_addresses description. At first, it is commented out. Set '*' to listen_addresses.

Authentication Configuration

In /etc/postgresql/9.5/main/pg_hba.conf, host which can connect to the database is filtered.Add the following line into IPv4 section.