Set up connection between two linodes (Web/database node) PostgreSQL/Net Core

Hi all,

I'm completely new to Linux but I've finally managed to get a PostgreSQL database running on my database box and my net core application running on my web box. My issue is that I can't connect the two and honestly I'm about to give up!

I've set up private IP addresses on both. I've then tried to set up an ssh tunnel from my web box to my DB box using ssh -D 5542 username@ip which successfully launched an ssh session but I still don't seem to able to connect to the DB using 127.0.0.1:5432. I've got everything working on my windows machine using PGAdmin so I can confirm that the database connection definitely works, I just can't connect my 2 nodes together.

Not sure if I'm going about this the wrong way?

Thanks!

4 Replies

Managed to get it working by using

ssh -f -L 5433:127.0.0.1:5432 username@remote-host -N

Does anyone have any pointers on how to run this at startup so my connection is always active between the 2?

If your Linodes both have a private IP, you could also connect directly, then you wouldn’t need to worry about starting up a tunnel, or it dropping out.

Ensure PostgreSQL is listening on the private IP, then from your web Linode, connect to 192.168.2.96:5432 (replace 192.168.2.96 with your actual private IP.)

Check out the Linode guides to configuring a firewall on your DB Linode and ensure only your web Linode is allowed to talk to that IP.

If you want traffic encrypted between the 2 servers, PostgreSQL can do that with SSL connections.

Hi Andy,

Thanks for this, I tried to do a direct connection but kept getting errors, I even at one point had Postgres set to listen on 0.0.0.0 but still couldn't get a connection.

Might give it another go now I'm not as frustrated with it. I didn't look at my firewalls so maybe that was the reason why.

Thanks again for pointing me in some direction.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct