如何配置 PostgreSQL 以接受所有传入连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3278379/
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
How to configure PostgreSQL to accept all incoming connections
提问by Fergal
I've got a PostgreSQL data base that I'd like to configure to accept all incoming connections regardless of the source IP address. How can this be configured in the pg_hba.conf file? I'm using postgreSQL version 8.4.
我有一个 PostgreSQL 数据库,我想将其配置为接受所有传入连接,而不管源 IP 地址如何。如何在 pg_hba.conf 文件中配置?我正在使用 postgreSQL 8.4 版。
回答by Frank Heikens
Just use 0.0.0.0/0
.
只需使用0.0.0.0/0
.
host all all 0.0.0.0/0 md5
Make sure the listen_addresses
in postgresql.conf
(or ALTER SYSTEM SET
) allows incoming connections on all available IP interfaces.
确保listen_addresses
in postgresql.conf
(或ALTER SYSTEM SET
)允许所有可用 IP 接口上的传入连接。
listen_addresses = '*'
After the changes you have to reload the configuration. One way to do this is execute this SELECT
as a superuser.
更改后,您必须重新加载配置。一种方法SELECT
是以超级用户身份执行此操作。
SELECT pg_reload_conf();
回答by Owen Pauling
0.0.0.0/0
for all IPv4 addresses
0.0.0.0/0
对于所有 IPv4 地址
::0/0
for all IPv6 addresses
::0/0
对于所有 IPv6 地址
all
to match any IP address
all
匹配任何IP地址
samehost
to match any of the server's own IP addresses
samehost
匹配任何服务器自己的 IP 地址
samenet
to match any address in any subnet that the server is directly connected to.
samenet
匹配服务器直接连接到的任何子网中的任何地址。
e.g.
例如
host all all 0.0.0.0/0 md5
回答by vvs14
Addition to above great answers, if you want some range of IPs to be authorized, you could edit /var/lib/pgsql/{VERSION}/data
file and put something like
除了上面的好答案之外,如果您想要授权一定范围的 IP,您可以编辑/var/lib/pgsql/{VERSION}/data
文件并放置类似的内容
host all all 172.0.0.0/8 trust
host all all 172.0.0.0/8 trust
It will accept incoming connections from any host of the above range. Source: http://www.linuxtopia.org/online_books/database_guides/Practical_PostgreSQL_database/c15679_002.htm
它将接受来自上述范围的任何主机的传入连接。来源:http: //www.linuxtopia.org/online_books/database_guides/Practical_PostgreSQL_database/c15679_002.htm
回答by trithucsv
Configuration all files with postgres 12 on centos:
在centos上用postgres 12配置所有文件:
step 1:search and edit file
第 1 步:搜索和编辑文件
sudo vi /var/lib/pgsql/12/data/pg_hba.conf
须藤vi /var/lib/pgsql/12/data/pg_hba.conf
press "i" and at line IPv4 change
按“i”并在行 IPv4 更改
host all all 0.0.0.0/0 md5
step 2:search and edit file postgresql.conf
第 2 步:搜索并编辑文件 postgresql.conf
sudo vi /var/lib/pgsql/12/data/postgresql.conf
须藤vi /var/lib/pgsql/12/data/postgresql.conf
add last line: listen_addresses = '*' :wq! (save file) - step 3: restart
添加最后一行:listen_addresses = '*' :wq! (保存文件) - 第 3 步:重新启动
systemctl restart postgresql-12.service
回答by Guest
Add this line to pg_hba.confof postgres folder
将此行添加到postgres 文件夹的pg_hba.conf
host all all all trust
"trust" allows all users to connect without any password.
“信任”允许所有用户无需任何密码即可连接。