Configure PostgreSQL to work for only LOCALHOST or specified ip + port

Ankur Loriya picture Ankur Loriya · Aug 1, 2012 · Viewed 41.2k times · Source

I want to configure PostgreSQL to accept connections only from a specified IP. It should not accept requests from any other IP.

Answer

francs picture francs · Aug 1, 2012

The following pg_hba.conf allows local and specified Ip have privilege login, but reject others。

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     trust
host    testdb          testuser      192.168.1.1/32             md5
host    all             all           0.0.0.0/0                 reject