Reputation: 5174
I have a postgresql server running on my ubuntu pc at home.
I have already set up the server to post-forward to accept external connections.
But for some reason, I can only connect to it on my local pc, I can't seem to connect to it from external connections.
Here are my settings for /etc/postgresql/12/main/pg_hba.conf
,
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all password
# IPv4 local connections:
host all all 127.0.0.1/32 password
# IPv6 local connections:
host all all ::1/128 password
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all password
host replication all 127.0.0.1/32 password
host replication all ::1/128 password
Here are the settings for /etc/postgresql/12/main/postgresql.conf
,
listen_addresses = '*'
port = 5432
I have set up my external port to be 2345
, and done the port forwarding on my router.
When I run, psql -h 127.0.0.1 -p 5432 -d postgres -U postgres
, I can connect to the server.
But when I run, psql -h xxx.xx.xx.xx -p 2345 -d postgres -U postgres
(ip address hidden), I get the following error
psql: error: could not connect to server: could not connect to server: Operation timed out
Is the server running on host "xxx.xx.xx.xx" and accepting
TCP/IP connections on port 2345?
I don't think there's anything wrong with my router either because I'm using it to forward SSH connections and I can connect from external connections fine.
What's wrong with my settings?
Upvotes: 0
Views: 598
Reputation: 2405
Had a conversation with @anarchy he had Uncomplicated Firewall (uwf) enabled. adding a rule to the firewall worked.
To inspect check what ports are opened using network utility
netstat -lntu
To check if UFW is running
sudo uwf status
if it is enabled add the port you want to open
sudo ufw allow 22
and then reload firewall
sudo ufw reload
Upvotes: 1