포트를 변경하고 원격에서 접속할 수 있도록 설정합니다.
# Check status of firewall
$ sudo ufw status
To Action From
-- ------ ----
12300 ALLOW Anywhere
12300 (v6) ALLOW Anywhere (v6)
$ sudo netstat -ntlp | grep postgres
tcp 0 192.168.0.0:5432 0.0.0.0:* LISTEN 22700/postgres
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)
...
$ systemctl restart postgresql
$ sudo netstat -ntlp | grep postgres
tcp 0 0 0.0.0.0:4444 0.0.0.0:* LISTEN 22700/postgres
$ sudo ufw allow 4444
Rule added
Rule added (v6)
$ sudo ufw status
Status: active
To Action From
-- ------ ----
4444 ALLOW Anywhere
4444(v6) ALLOW Anywhere (v6)