大网数据广告活动
服务器运维问答

Changing pg_hba.conf network range prevents restart

· 52CE 我爱测

I have a pgsql9.4 server running on centos with a pg_hba.conf to accept md5 connections from a certain range of IPs. With IPs redacted, my pg_hba.conf file looks like the following: # TYPE DATABASE USER ADDRESS METHOD # "local" i…

问题原文

原帖链接 · Robert Townley · CC BY-SA 3.0

I have a pgsql9.4 server running on centos with a pg_hba.conf to accept md5 connections from a certain range of IPs. With IPs redacted, my pg_hba.conf file looks like the following:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

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

This configuration works great for IPs in the range of xxx.xx.xx.0 through xxx.xx.xx.24. However, when I try to increase it to accommodate access from a server on a higher IP number (112) and try to restart the postgres service, the service fails on restart.

I tried creeping the number up from 0/25 and made it up to a number which runs our puppet server.

I also tried adding a second, identical record to encompass just the IP range 111/112 but to no avail.

Anyone have any ideas as to why Postgres might consider these to be an invalid pg_hba.conf?

EDIT: Forgot to mention that listen_addresses is set to '*' so that access can be controlled user-by-user inside of pg_hba.conf

已采纳解答

原帖链接 · MatheusOl · CC BY-SA 3.0

That host information is the CIDR notation, when you use 172.16.33.0/24 you are not giving the range from 0 to 24, you are, in fact, giving the range from 172.16.33.1 to 172.16.33.254 (read CIDR blocks to understand better why). ipcalc tool can help you identify that:

$ ipcalc 172.16.33.0/24
Network:    172.16.33.0/24
Address space:  Private Use
Address class:  Class B
Netmask:    255.255.255.0 = 24
Broadcast:  172.16.33.255

HostMin:    172.16.33.1
HostMax:    172.16.33.254
Hosts/Net:  254

So, 172.16.33.0/24 already includes 172.16.33.111` and172.16.33.112, meaning you don't need to do anything else inpg_hba.confbut add the line with172.16.33.0/24`.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。