除非我还添加解析的 IP 地址,否则在 pg_hba.conf 中允许主机名访问将不起作用?

dav*_*vid 5 linux postgresql dns

我想允许从主机名而不是 IP 访问 postgres。我添加了从主机名到 pg_hba.conf 的访问,但是当查看错误日志时,似乎 DNS 将此主机名解析为 IP,除非我明确允许访问,否则不允许来自此 IP 的连接。这违背了使用主机名的全部目的,因为我的服务的主机名永远不会改变,而 IP 地址每天都会改变。

这个问题的解决办法是什么?也许我的conf不正确?

错误:

test@test FATAL:  no pg_hba.conf entry for host "10.81.128.90", user "test", database "test", SSL on[1]:
test@test DETAIL:  Client IP address resolved to "cannablrv2-locationserver-1.kontena.local", forward lookup not checked.
Run Code Online (Sandbox Code Playgroud)

添加对 pg_hba.conf 的访问权限的 shell 脚本

# Restrict subnet to docker private network
echo "host    all             all             172.17.0.0/16               md5" >> /etc/postgresql/9.5/main/pg_hba.conf

# Allow access from locationserver
echo "host    all             all             cannablrv2-locationserver.test.kontena.local               md5" >> /etc/postgresql/9.5/main/pg_hba.conf

# And allow access from DockerToolbox / Boottodocker on OSX
echo "host    all             all             192.168.0.0/16               md5" >> /etc/postgresql/9.5/main/pg_hba.conf

# Listen on all ip addresses
echo "listen_addresses = '*'" >> /etc/postgresql/9.5/main/postgresql.conf
echo "port = 5432" >> /etc/postgresql/9.5/main/postgresql.conf
Run Code Online (Sandbox Code Playgroud)

Lau*_*lbe 4

您会看到客户端 IP 地址解析为与您在 中输入的名称不同的名称pg_hba.conf,这就是连接失败的原因。

您阅读了文档吗?它详细解释了如何处理主机名。

您可能会侥幸使用.kontena.local来匹配名称后缀。