Ubuntu PostgreSQL 설정

N'CHE·2021년 10월 19일
0

포트를 변경하고 원격에서 접속할 수 있도록 설정합니다.

1. 방화벽 설정 확인

  • 열고싶은 포트가 열려있는지 확인합니다.
# Check status of firewall 
$ sudo ufw status
To                         Action      From
--                         ------      ----
12300                      ALLOW       Anywhere
12300 (v6)                 ALLOW       Anywhere (v6)

2. PostgreSQL의 포트 확인

  • listening port로 postgresql의 기본 포트 5432가 설정되어 있습니다.
$ sudo netstat -ntlp | grep postgres
tcp        0      192.168.0.0:5432            0.0.0.0:*               LISTEN      22700/postgres

3. 허용 IP와 port 변경

  • pg_hba.conf의 IPv4 IP 설정을 변경하여 모든 대역을 허용합니다.
$ sudo vi /etc/postgresql/13/main/pg_hba.conf

...
# IPv4 local connections:
host    all             all             0.0.0.0/0               md5
...
  • postgresql.conf의 listen_address, port 설정을 변경합니다.
$ sudo vi /etc/postgresql/13/main/postgresql.conf

...

# - Connection Settings -

listen_addresses = '0.0.0.0'            # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 4444                             # (change requires restart)

...

4. 서비스 재시작

  • 변경된 설정값을 적용하기 위해 postgresql 서비스를 재시작 합니다.
$ systemctl restart postgresql

5. 변경사항 확인

$ sudo netstat -ntlp | grep postgres
tcp        0      0 0.0.0.0:4444            0.0.0.0:*               LISTEN      22700/postgres

6. 방화벽 포트 허용

$ sudo ufw allow 4444
Rule added
Rule added (v6)

7. 방화벽 포트 설정 확인

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
4444                      ALLOW       Anywhere
4444(v6)                  ALLOW       Anywhere (v6)

0개의 댓글