HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Connect to PostgreSQL from different host

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlconnectdifferenthostfrom

Problem

I am facing error while connecting to the PostgreSQL server from different host, I configured both postgresql.conf and pg_hba.conf but unfortunately with no result.

So I have installed PostgreSQL on Debian from package, added user with createuser and useradd, then created db via createdb as my custom user as an owner. Afterwards I have set postgresql.conf with these values

listen_addresses = '*'
ssl = false


And added this line in pg_hba.conf

host    all      all     192.168.0.0/24  md5


Then I have restarted service and tried to connect from my machine via psql -U admin -d admin -h 10.10.30.88and I am getting this error

psql: FATAL:  no pg_hba.conf entry for host "192.168.10.195", user "admin", database "admin", SSL off


So have I forgotten about something?

Whole pg_hba.conf

local   all             postgres                                peer

local   all             all                                     peer
host    all             all             127.0.0.1/32            md5

# IPv6 local connections:
host    all             all             ::1/128                 md5

host    all     all     192.168.0.0/24  md5
host    all     all     10.10.0.0/24    md5


ipconfig PostgreSQL server

eth0      Link encap:Ethernet  HWaddr 52:54:00:00:00:03  
      inet addr:10.10.30.88  Bcast:10.10.30.255  Mask:255.255.255.0
      inet6 addr: fe80::5054:ff:fe00:3/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:4001 errors:0 dropped:0 overruns:0 frame:0
      TX packets:2297 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:365126 (356.5 KiB)  TX bytes:306782 (299.5 KiB)


ipconfig from other VM in same network

```
eth0 Link encap:Ethernet HWaddr 52:54:00:00:00:15
inet addr:10.10.30.83 Bcast:10.10.30.255 Mask:255.255.255.0
inet6 addr: fe80::5054:ff:fe00:15/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU

Solution

The issue is probably due to this line:

host    all     all   192.168.0.0/24  md5


This (the 24) basically tells Postgres to allow connections from any machine that has IP of the form: 192.168.0.x. So, your 192.168.10.195 does not match the criteria. You can replace it with:

host    all     all   192.168.0.0/16  md5     -- any 192.168.x.x


or

host    all     all   192.168.10.0/24  md5    -- any 192.168.10.x


or

host    all     all   192.168.10.195/32  md5  -- only 192.168.10.195


depending on what range of IPs you want to allow.

Code Snippets

host    all     all   192.168.0.0/24  md5
host    all     all   192.168.0.0/16  md5     -- any 192.168.x.x
host    all     all   192.168.10.0/24  md5    -- any 192.168.10.x
host    all     all   192.168.10.195/32  md5  -- only 192.168.10.195

Context

StackExchange Database Administrators Q#128708, answer score: 6

Revisions (0)

No revisions yet.