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

喜夏-厌秋 提交于 2019-12-03 11:07:02

问题


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


回答1:


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 



回答2:


The most easiest way is to make PostgreSQL listening only on localhost for incoming connections. The relevant parameter is listen_addresses in postgresql.conf. The docu is here.




回答3:


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



来源:https://stackoverflow.com/questions/11753296/configure-postgresql-to-work-for-only-localhost-or-specified-ip-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!