As I can, configure the firewall of ubuntu server for the server to accept connections of the terminals through PostgreSQL port 5432 - linux

Configuration: Server: Ubuntu server 16.04 LTS using webmin
Terminal: Windows 7 Using PgAmin III
I was unable to establish the connection between my terminal and my server through pgAdmin III on port 5432.
On my server I added:
in file postgresql.conf I edited
in #Connection Settings
listen_addresses = '*'
in file pg_hba.conf I added
in #IPv4 local connections
host all all 172.x.x.x/32 md5 //this is IP Terminal (Hidden x)
I checked the port, this is 5432 default and user is postgres
When I try to establish the connection on PgAdmin III:
Host: //My Server IP (Ping console successful)
Port: 5432
username: postgres
password: //My password
Show me the following message:
Server doesn't listen
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "Mi SERVER IP Hidden" and accepting TCP/IP connections on port 5432?
If you encounter this message, please check if the server you're trying to contact is actually running PostgreSQL on the given port. Test if you have network connectivity from your client to the server host using ping or equivalent tools. Is your network / VPN / SSH tunnel / firewall configured correctly?
For security reasons, PostgreSQL does not listen on all available IP addresses on the server machine initially. In order to access the server over the network, you need to enable listening on the address first.
For PostgreSQL servers starting with version 8.0, this is controlled using the "listen_addresses" parameter in the postgresql.conf file. Here, you can enter a list of IP addresses the server should listen on, or simply use '*' to listen on all available IP addresses. For earlier servers (Version 7.3 or 7.4), you'll need to set the "tcpip_socket" parameter to 'true'.
You can use the postgresql.conf editor that is built into pgAdmin III to edit the postgresql.conf configuration file. After changing this file, you need to restart the server process to make the setting effective.
If you double-checked your configuration but still get this error message, it's still unlikely that you encounter a fatal PostgreSQL misbehaviour. You probably have some low level network connectivity problems (e.g. firewall configuration). Please check this thoroughly before reporting a bug to the PostgreSQL community.

Related

Postgres remote connection fails, 'psql: error: connection to server at {server}, port 5432 failed: Connection timed out'

I have a postgres database currently working on my PC. I am deploying a flask app which uses said database onto a linux server, and need to remotely connect to my database from the linux machine. The command I am using on the linux machine to do this is
psql -h 12.345.678.901 -p 5432 -U postgres
where 12.345.678.901 is my local PC ip address. When I do this, I get the error
psql: error: connection to server at "12.345.678.901", port 5432 failed: Connection timed out
Is the server running on that host and accepting TCP/IP connections?
I would like to emphasize that the connection is not being 'refused', it is just timing out (unlike many of the questions related to this topic). I'm not sure if this helps identify the underlying issue or not. I understand that this is an extremely common issue, but no solutions have worked for me. Among these solutions are updating the pg_hba.conf, postgresql.conf, firewall configuration, and many others. I have done this. My pg_hba.conf file looks like this
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all scram-sha-256
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::1/128 scram-sha-256
host all all ::0/0 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all scram-sha-256
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
host all all 0.0.0.0/0 md5
and my postgresql.conf looks like this
# - 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)
These files are located in C:\Program Files\PostgreSQL\14\data. I have manually checked that these changes are saved and implemented with the psql shell. I also restarted postgres after all changes to these files.
Other fixes I have implemented:
Set firewall rules on local PC to open port 5432 to inbound and outbound TCP/IP connections with Windows Defender Firewall
Set remote linux PC firewall to allow connections through port 5432 with the lines
'sudo ufw allow 5432/tcp' &
'sudo ufw allow postgres/tcp'
Tried both local PC IPv4 address and default gateway address (I am not sure which one to use to be honest)
Set a rule for my physical router to allow connections to port 5432
I cannot figure this out to save my life. Any help would be greatly so utterly appreciated.
To anyone else struggling with this question, after many weeks of digging I finally found the solution. The ip address you must use in the postgres configuration files is the ip address of your ROUTER. I tried every single ip address on my computer and none worked. Only when I got on my internet providers app and found my router ip is when I was finally able to connect. The biggest tell of this was that when I would ssh into my remote server, it would say 'connection from {router ip address}'. Hope this helps.

Docker Postgresql can't connect remotely

I can connect my docker postgresql in my local server windows via ip or localhost. When I try to connect it remotely from my personal windows I have timeout error. Thinking about 5432 port is blocked or not listening.
I have changed pg_hba.conf & postgresql.conf files for remote connection and also checked for firewall but it was disabled.
Answer is I should have checked my server's firewall conf also, just dockerVM is not enough :)

Cannot connect to neo4j running in droplet but using lynx to navigate to localhost:7474 works, ufw & digital ocean firewall configured

I'm running a brand new droplet in digital ocean running on Ubuntu 18.04.3 (LTS) x64, neo4j status is active and remote interface available on port 7474.
Using lynx via ssh to browse to localhost:7474 works, neo4j is alive and active.
Pinging works
Firewall asigned to allow all traffic but also specifically those ports
Browsing to the ip address on any port does not work
Used ufw to manually add port 80, 443, 7474 to allow access
Cannot connect via browser to the droplet on any port
Firewall configuration:
UFW Status:
Can you make sure the following line in your neo4j.conf file is uncommented :
# With default configuration Neo4j only accepts local connections.
# To accept non-local connections, uncomment this line:
dbms.connectors.default_listen_address=0.0.0.0

Failed to reach erlang port mapper (server ports open and connecting via Telnet)

I am trying to add a new server to an existing cluster. I am using community version 2.1.1 on both ubuntu servers on windows azure. I tried to add new server via web interface and via command line. But i am getting following error.
***"Failed to reach erlang port mapper. Timeout connecting to "xx.xx.xx.xx" on port "4369". This could be due to an incorrect host/port combination or a firewall in place between the servers.']***
Port 4369 is open on both servers and iam able to connect to 4369 port on other server using telnet
Got the same error when used the following command.
/opt/couchbase/bin/couchbase-cli server-add --cluster=xx.xx.xx.xx:8091 -u user -p password --server-add=yy.yy.yy.yy:8091 --server-add-username=Administrator --server-add-password=password
ERROR: unable to server-add yy.yy.yy.yy:8091 (400) Bad Request
[u'Prepare join failed. Failed to reach erlang port mapper. Timeout connecting to "xx.xx.xx.xx" on port "4369". This could be due to an incorrect host/port combination or a firewall in place between the servers.']
root#xx.xx.xx.xx:/home/azureuser/project# telnet yy.yy.yy.yy 4369
Trying yy.yy.yy.yy...
Connected to yy.yy.yy.yy.
Escape character is '^]'.
^]q
telnet> q
Connection closed.
What will be the issue? Please help me sort this out.
There are a number of ports required to be open between cluster nodes (in addition to 4369) - I'd suggest ensuring all of the ports listed in the Couchbase Installation Guide - Network ports are open and accessible.

Unable to connect to PostgreSQL server: could not connect to server: Permission denied

Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "10.0.1.201" and accepting TCP/IP connections on port 5432?
This is the error i am getting when trying to connect to remote database from linux based server
Though i am able to connect to it from localhost
Can anyone help me in this
One possible scenario/solution that worked for me (for the very same problem) is here:
service httpd stop
service postgresql stop
setsebool -P httpd_can_network_connect 1
service httpd start
service postgresql start
Here we're basically allowing HTTPD to connect to PostgreSQL over network by setting SELinux bool equals to 1 (true).
Check the listen_addresses setting in postgresql.conf. If it is set to localhost, then only loopback connections will be accepted, and remote connections will get a "connection refused" error. Set listen_addresses to "*" to enable listening on all interfaces.
In PostgreSQL you have to configure client authentication in pg_hba.conf on the remote server.
Read more about pg_hba.conf # http://developer.postgresql.org/pgdocs/postgres/auth-pg-hba-conf.html , otherwise you'll never connect to that server :).
Hope it will help,
Stefan

Resources