Access PostgreSQL server from LAN (Linux Lubuntu / OSGeo)

First, edit the postgresql.conf file, and set listen_addresses. The default value of ‘localhost’ will only listen on the loopback adaptor. You can change it to ‘*’, meaning listen on all addresses, or specifically list the IP address of the interfaces you want it to accept connections from. Note that this is the IP address which the interface has allocated to it, which you can see using ifconfig or ip addr commands.

You must restart postgresql for the changes to listen_addresses to take effect.

Next, in pg_hba.conf, you will need an entry like this:

# TYPE  DATABASE     USER     ADDRESS                 METHOD
host    {dbname}     {user}   192.168.1.0/24          md5

{dbname} is the database name you are allowing access to. You can put “all” for all databases.

{user} is the user who is allowed to connect. Note that this is the postgresql user, not necessarily the OS user.

The ADDRESS part is the network address and mask that you want to allow.

You can also write all to match any IP address, samehost to match any of the server’s own IP addresses, or samenet to match any address in any subnet that the server is directly connected to.

The METHOD part is the authentication method to use. There are a number of options there. md5 means it will use an md5 hashed password. ‘trust’ means no authentication at all – this is definitely not recommended.

Changes to pg_hba.conf will take effect after reloading the server.




Leave a Reply

Your email address will not be published. Required fields are marked *