I want to configure PostgreSQL to accept connections only from a specified IP. It should not accept requests from any other IP.
Configure PostgreSQL to work for only LOCALHOST or specified ip + port
55.9k views Asked by Ankur Loriya At
3
There are 3 answers
1
On
Check the pg_hba.conf file in the data folder of PostgreSQL. This is the client authentication configuration file.
# TYPE DATABASE USER ADDRESS METHOD
host testdb testuser 192.168.1.1 md5
local testdb all md5
Add the above to the pg_hba.conf file
0
On
The easiest way is to make PostgreSQL listen only on localhost
for incoming connections. The relevant parameter is listen_addresses
in postgresql.conf
. The doc is here.
The following example pg_hba.conf allows local and a specified IP to have privileged login, but rejects others.