配置PostgreSQL仅适用于LOCALHOST或指定的ip +端口

Ank*_*iya 20 postgresql configuration ipconfig

我想配置PostgreSQL只接受来自指定IP的连接.它不应接受来自任何其他IP的请求.

fra*_*ncs 23

以下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 
Run Code Online (Sandbox Code Playgroud)


A.H*_*.H. 12

最简单的方法是使PostgreSQL仅监听localhost传入连接.相关参数listen_addressespostgresql.conf.文件在这里.


Jac*_*rge 5

检查PostgreSQL数据文件夹中的pg_hba.conf文件.这是客户端身份验证配置文件.

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    testdb           testuser      192.168.1.1               md5
local   testdb           all                                     md5
Run Code Online (Sandbox Code Playgroud)

将以上内容添加到pg_hba.conf文件中

  • 请注意,PostgreSQL仍然会通过它通过postgresql.conf中的“ listen_addresses”绑定到的任何接口接受TCP套接字连接到其端口,只是不允许它们进行身份验证。如果要防止TCP握手,则需要使用iptables。 (2认同)