How to connect from one server to another server`s postgresql database by configuring firewall - postgresql

I am trying to connect from Ubuntu 16.04 server to Gentoo server`s Postgresql database. But i cannot connect to it. Ubuntu server has internet with static Ip: 93.154.53.88. In my Gentoo server has Ip: 192.168.0.104. I configured my pg_hba.conf also to Ip address of Ubuntu server. But anyway it cannot connect to it. My pg_hba.conf is like below:
host all all 93.154.52.85/32 trust
host all all 93.154.53.88/32 md5
When i ping to my Gentoo Server like below it is not going. I think I should configure some firewall settings.
ping 93.154.53.88
But When i connected my Gentoo Server`s database from second Linux server it can connect which has Ip address: 93.154.52.85. But Ubuntu server cannot connect to it. I read some post in which iptables need to be configured Please Help me What to configure and how to do it. Any help is appreciated.

Related

Having problem in connecting to remote MongoDB Server

I tried to connect a remote MongoDB Server running on Ubuntu using MongoDB Compass on Windows. But I have problems connecting always as the IP of the Windows machine changes every day.
I did the following things to connect to the remote server-
Got the IP of the Client Machine, then allowed that IP on the firewall of the server machine on port 27017.
sudo ufw allow from client_machine_ip to any port 27017
Note: The ufw status looked okay.
Got the IP of the Server Machine, then on the MongoDB configuration file on the server, I modified the bindIp.
bindIp: 127.0.0.1,server_machine_ip
Note: I restarted mongod and it was okay too.
I was able to connect the remote MongoDB Server using MongoDB Compass successfully for the first time. Then I saw, the IP of the client machine was changing every day. So, every time, the client IP changes, I need to allow that IP on the firewall of the server machine (in which I am using the MongoDB Server) on port 27017. Could you help to solve this? Thanks in advance.
You can update the firewall for port 27017 to allow from anywhere since client machine IP is not static.
sudo ufw allow 27017 #(this will allow from any IP)

Access Odoo database from outside while Odoo deployed in AWS lightsail

I have installed AWS in a Linux VM at AWS Lightsail. Now need to access database using a DB client from my laptop. Somehow I am not able to connect the DB via port 5432.
I can access port 22 ftp after add a rule in AWS networking but not port 5432.
I tried to enable Linux VM firewall, but it did break all my connections.
Any advice would be appreciated. Thank you !
Did you change listen_addresses in postgresql.conf already?

Connect to localhost PgAdmin server from remote computer

I have a PgAdmin server running on localhost and I'm trying to connect to it from another computer on the same network (they have the same IPv4 address).
I've gone through a lot of questions but all of them explain how to connect to a remote server, which I assume is running on an available host.
I've tried:
adding listen_addresses = '*' to postgresql.conf (on both computers)
adding host all all 0.0.0.0/0 md5 to pg_hba.conf (on both computers, replacing 0.0.0.0/0 with a variety of ip addresses)
some other things I saw in tutorials but don't remember
What I'm trying to understand is:
Is it possible to connect remotely to a server running on localhost?
If it is possible, which IP address does the remote computer need to connect?
You need to resolve some basic questions first:
What is the IP of the computer where PG is running? e.g. 192.168.100.10
Which port is PG exposed on? e.g. 9999
After you collected the two above information you can go on the second computer where you have pgAmin and execute
telnet <host> <port>
substituting <host> and <port> with the info collected above. If telnet replies with
Trying ::1...
Connected to <host>.
Escape character is '^]'.
this should mean that the port is open and PG should be listening on that host:port. You found your connection string to PG!
I am just sharing my understanding here. Corrections are welcome.
pgAdmin can connect to one/more postgres servers via TCP over using JDBC like protocol. pgAdmin is just a stand-alone web-interface ( web adapter ).
So some web-server configuration/tuning should be needed in pgAdmin configuration to enable access from remote machines.

Troubles connecting PostgreSQL installed in WSL2 Ubuntu from the Windows 10 host

I'm having big troubles connecting to PostgreSQL, installed in WSL2 Ubuntu, from the Windows 10 host.
Here is what I have done so far.
Set password for postgres user.
Set the following in pg_hpa.conf
local all postgres md5
host all all 0.0.0.0/0 md5
Set the following in postgresql.conf
listen_addresses = '*'
Tested successfully that I can connect with psql -U postgres - so password should be set correctly.
When I try to connect using either pgAdmin or psql from the Windows 10 host, I get the following error.
error: could not connect to server: FATAL: password authentication failed for user "postgres"
Anything else I can change in pg_hpa.conf or other PostgreSQL configurations which might help?
I'm thinking that I could have something to do with that WSL2 has its own IP, even tough that connections from the hosts are made appear coming from localhost. The connection seems to be made, but authentication failed for some reason when it is not made from within Ubuntu.
I later tested with nc -l 5432 and for some reason, port 5432 didn't reach WSL2 on local host, but did on WSL-2 IP. If I use any other free port e.g. 5434 (free both on Windows and WSL-2) it works fine and I can connect to the PostgreSQL service on WSl-2 through localhost on windows.
I didn't change any options since the original posted question - only the port.
Update: It turns out that there indeed was a process from an old install of postgres on Windows which was listening on port 5432. This of cause explains it all. ..:/
As was pointed out by the original poster, ensure that you do not have a Windows service already running and listening on that port. In my case it was a PostgreSQL instance installed as a Windows service. Whatever the underlying networking support, it seems you can have a process/service listening on port 5432 in Windows as well as a separate Linux process listening on port 5432 from WSL2.
It was not enough to stop the Windows PostgreSQL service. Connecting from the Windows pgAdmin4 installation program failed. I also disabled the service from Microsoft Services console.
I needed to also stop and start the WSL2 postgresql. Only then was I successfully able to connect from my Windows pgAdmin4 installation program to the WSL2 postgreSQL

PostgreSQL SSH port forwarding via Windows/PuTTY

I have PostgreSQL 9.4 running on a Linux VPS, and I need to be able to connect to it over SSH from both Linux and Windows clients. (I will later need to connect to multiple servers, and so that all clients use the same port numbers, I'm forwarding to port 5551 for the first server, then I will use 5552, 5553, etc.)
From a Linux client I just run ssh -fNg -L 5551:localhost:5432 user#remote1.com and connect to localhost:5551 with PGAdmin3 or any other client app. Works great.
On Windows, I'm using PuTTY and Pageant. I got the connection to user#remote1.com via terminal working, then I went to the SSH Tunnels and added L5432 localhost:5551. Terminal connection still works, but when I try to connect with PGAdmin3 to localhost:5551 I get an error:
could not connect to server: Connection refused (0x0000274AD/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5551?
I resolved it. Like many things, this is obvious in hindsight. I had things backward in the SSH Tunnels setup in PuTTY. It needs to be L5551 remote1.com:5432