How To Allow PostgreSQL Connection From Remote IP

sudo vi /etc/postgresql/15/main/pg_hba.conf

In the last line, add the following details:

host    all             all             10.116.0.0/20           scram-sha-256

Open postgresql.conf

sudo vi /etc/postgresql/15/main/postgresql.conf

Find #listen_addresses = 'localhost', then uncomment and replace with the following values: listen_addresses = '*' and save the file.

What this does is, it opens connection for all IP range inside 10.116.0.0/20 subnet only.

sudo systemctl restart postgresql.service

Next, let’s restart PostgreSQL service.

Leave a Comment

Scroll to Top