将 PostgreSQL 配置为仅适用于 LOCALHOST 或指定的 ip + 端口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11753296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Configure PostgreSQL to work for only LOCALHOST or specified ip + port
提问by Ankur Loriya
I want to configure PostgreSQL to accept connections only from a specified IP. It should not accept requests from any other IP.
我想将 PostgreSQL 配置为仅接受来自指定 IP 的连接。它不应接受来自任何其他 IP 的请求。
回答by francs
The following pg_hba.conf allows local and specified Ip have privilege login, but reject others。
下面的 pg_hba.conf 允许本地和指定的 Ip 有权限登录,但拒绝其他人。
# 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
回答by A.H.
回答by Jacob George
Check the pg_hba.conffile in the data folder of PostgreSQL. This is the client authentication configuration file.
检查PostgreSQL 数据文件夹中的pg_hba.conf文件。这是客户端身份验证配置文件。
# 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
将以上内容添加到 pg_hba.conf 文件中