I'm trying to get remote access to postgresql, installed on a server with IP A.A.A.A. There are two servers which one them has IP A.A.A.A, where postgresql has been installed on; and the other one has IP B.B.B.B.
I've edited /etc/postgresql/10/main/pg_hba.conf
and added the following lines
host my_db db_user B.B.B.B/32 md5
host my_db db_user A.A.A.A/32 md5
I've also edited /etc/postgresql/10/main/postgresql.conf
and set listen_addresses
to '*'
, like this:
#---------------------------------------------------------------------
---------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
I have also allowed connections through port 5432 in ufw:
5432 ALLOW Anywhere
5432 (v6) ALLOW Anywhere (v6)
Now, if I am in server A (where postgres is installed) and do psql "postgresql://db_user:password@A.A.A.A:5432/my_db"
it connects fine. But if I do it from the server with IP B.B.B.B I get this error:
psql: FATAL: no pg_hba.conf entry for host "B.B.B.B", user "db_user", database "my_db", SSL on
FATAL: no pg_hba.conf entry for host "B.B.B.B", user "db_user", database "my_db", SSL off
I really don't understand where the mistake is. Both entries in pg_hba.conf
look the same, but one works and the other doesn't.