IT/postgresql

postgresql 특정ip만 접근 허용

bepuri 2022. 12. 8. 09:53
728x90

구글링해보면 자료가 좀 나온다.

근데 대부분 public하게 모든 ip에 대해서 허용하는 방법에 대해 질의하거나,

ubuntu 20.04기준으로 제대로 작동하지 않는 예제가 다수였다.

 

postgresql.conf 내 관련코드 주석해제 후 모든 ip에 대해서 열면됨.
listen_addresses = '*'

 

pg_hba.conf
원하는 ip를 xxx.xxx.xxx.xxx대신 입력.
#Add code
#Allow All user
# TYPE DATABASE USER ADDRESS METHOD
host all all xxx.xxx.xxx.xxx/0 md5
# Allow replication connections from xxx.xxx.xxx.xxx, by a user with the
host replication all xxx.xxx.xxx.xxx/0 md5

 

특정 ip address에 대해 모든 db를 여는 설정코드이다.

listen_addresses = 'xxx.xxx.xxx.xxx, aaa.aaa.aaa.aaa' 이런 식으로도 설정이 가능하다는데,

내 경우는 아무리 해봐도 postgres가 해당 주소를 LISTEN하고 있지 않더라..

 

정상적으로 수신 대기 상태인지는 아래 명령을 통해 확인가능하다.

sudo lsof -n -u postgres |grep LISTEN
728x90