将PostgreSQL pg_hba.conf IPv6本地连接设置从:1/128更改为我自己的临时IPv6地址不起作用



如果我坚持以下默认设置,我的postgresql连接就可以工作:

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     md5
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

现在,我正在尝试允许同一家庭中的另一台计算机连接到当前服务器,并尝试一些设置。我做的一个更改是对IPv6本地连接线,改为使用我的临时IPv6地址,因为如果我在谷歌上查看我的ip,那就是显示在那里的ip。

# IPv6 local connections:
host    all             all             1111:2222:a111:a11:b222:11a:abcd:efgs                md5

(注意此处使用的ip只是一个示例(

然而,这将导致postgresql日志中出现以下错误:

2021-11-21 12:26:40.508 PST [10356] LOG:  starting PostgreSQL 13.3, compiled by Visual C++ build 1914, 64-bit
2021-11-21 12:26:40.515 PST [10356] LOG:  listening on IPv6 address "::", port 5432
2021-11-21 12:26:40.517 PST [10356] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-11-21 12:26:40.529 PST [10356] LOG:  invalid IP mask "md5": Unknown host
2021-11-21 12:26:40.529 PST [10356] CONTEXT:  line 88 of configuration file "C:/current_dir/PostgresSQL/data/pg_hba.conf"
2021-11-21 12:26:40.531 PST [10356] FATAL:  could not load pg_hba.conf
2021-11-21 12:26:40.533 PST [10356] LOG:  database system is shut down

造成这个错误的可能原因是什么?非常感谢。

不能在pg_hba.conf中指定客户端IP地址,必须指定CIDR。根据文件:

使用标准数字表示法指定IP地址范围的起始地址,然后使用斜线(/(和CIDR掩码长度。掩码长度指示必须匹配的客户端IP地址的高阶位数。在给定的IP地址中,它右边的位应该为零。IP地址、/和CIDR掩码长度之间不得有任何空白。

因此条目必须看起来像:

host  all  all  fe80::8b0a:b1bf:4ce5:9a4a/128  md5

最新更新